-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
offset_of: allow (unstably) taking the offset of slice tail fields
- Loading branch information
Showing
15 changed files
with
167 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::mem::offset_of; | ||
|
||
struct S { | ||
a: u8, | ||
b: (u8, u8), | ||
c: [i32], | ||
} | ||
|
||
struct T { | ||
x: i32, | ||
y: S, | ||
} | ||
|
||
fn main() { | ||
offset_of!(S, c); //~ ERROR size for values of type `[i32]` cannot be known at compilation time | ||
} | ||
|
||
fn other() { | ||
offset_of!(T, y); //~ ERROR size for values of type `[i32]` cannot be known at compilation time | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/ui/feature-gates/feature-gate-offset-of-slice.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/feature-gate-offset-of-slice.rs:15:5 | ||
| | ||
LL | offset_of!(S, c); | ||
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[i32]` | ||
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/feature-gate-offset-of-slice.rs:19:5 | ||
| | ||
LL | offset_of!(T, y); | ||
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: within `S`, the trait `Sized` is not implemented for `[i32]`, which is required by `S: Sized` | ||
note: required because it appears within the type `S` | ||
--> $DIR/feature-gate-offset-of-slice.rs:3:8 | ||
| | ||
LL | struct S { | ||
| ^ | ||
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@run-pass | ||
#![feature(offset_of_slice, offset_of_nested)] | ||
|
||
use std::mem::offset_of; | ||
|
||
#[repr(C)] | ||
struct S { | ||
a: u8, | ||
b: (u8, u8), | ||
c: [i32], | ||
} | ||
|
||
#[repr(C)] | ||
struct T { | ||
x: i8, | ||
y: S, | ||
} | ||
|
||
fn main() { | ||
assert_eq!(offset_of!(S, c), 4); | ||
assert_eq!(offset_of!(T, y), 4); | ||
assert_eq!(offset_of!(T, y.c), 8); | ||
} |