-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
17 changed files
with
215 additions
and
46 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,26 @@ | ||
use std::mem::offset_of; | ||
|
||
struct S { | ||
a: u8, | ||
b: (u8, u8), | ||
c: [i32], | ||
} | ||
|
||
struct T { | ||
x: i32, | ||
y: S, | ||
} | ||
|
||
type Tup = (i32, [i32]); | ||
|
||
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 | ||
} | ||
|
||
fn tuple() { | ||
offset_of!(Tup, 1); //~ ERROR size for values of type `[i32]` cannot be known at compilation time | ||
} |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/feature-gate-offset-of-slice.rs:17: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:21: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[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/feature-gate-offset-of-slice.rs:25:5 | ||
| | ||
LL | offset_of!(Tup, 1); | ||
| ^^^^^^^^^^^^^^^^^^ 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: aborting due to 3 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
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,26 @@ | ||
//@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, | ||
} | ||
|
||
type Tup = (i16, [i32]); | ||
|
||
fn main() { | ||
assert_eq!(offset_of!(S, c), 4); | ||
assert_eq!(offset_of!(T, y), 4); | ||
assert_eq!(offset_of!(T, y.c), 8); | ||
assert_eq!(offset_of!(Tup, 1), 4); | ||
} |