-
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.
Rollup merge of #118799 - GKFX:stabilize-simple-offsetof, r=wesleywiser
Stabilize single-field offset_of This PR stabilizes offset_of for a single field. There has been some further discussion at #106655 about whether this is advisable; I'm opening the PR anyway so that the code is available.
- Loading branch information
Showing
35 changed files
with
145 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// pp-exact | ||
#![feature(offset_of)] | ||
|
||
fn main() { std::mem::offset_of!(std :: ops :: Range < usize >, end); } |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![feature(offset_of)] | ||
#![feature(offset_of_nested)] | ||
|
||
use std::mem::offset_of; | ||
|
||
|
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,28 @@ | ||
#![feature(offset_of_enum)] | ||
|
||
use std::mem::offset_of; | ||
|
||
struct S { | ||
a: u8, | ||
b: (u8, u8), | ||
c: T, | ||
} | ||
|
||
struct T { | ||
t: &'static str, | ||
} | ||
|
||
enum Alpha { | ||
One(u8), | ||
Two(u8), | ||
} | ||
|
||
fn main() { | ||
offset_of!(Alpha, Two.0); //~ ERROR only a single ident or integer is stable as the field in offset_of | ||
offset_of!(S, a); | ||
offset_of!((u8, S), 1); | ||
offset_of!((u32, (S, T)), 1.1); //~ ERROR only a single ident or integer is stable as the field in offset_of | ||
offset_of!(S, b.0); //~ ERROR only a single ident or integer is stable as the field in offset_of | ||
offset_of!((S, ()), 0.c); //~ ERROR only a single ident or integer is stable as the field in offset_of | ||
offset_of!(S, c.t); //~ ERROR only a single ident or integer is stable as the field in offset_of | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/ui/feature-gates/feature-gate-offset-of-nested.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,60 @@ | ||
error[E0658]: only a single ident or integer is stable as the field in offset_of | ||
--> $DIR/feature-gate-offset-of-nested.rs:21:27 | ||
| | ||
LL | offset_of!(Alpha, Two.0); | ||
| ^ | ||
| | ||
= note: see issue #120140 <https://github.com/rust-lang/rust/issues/120140> for more information | ||
= help: add `#![feature(offset_of_nested)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: only a single ident or integer is stable as the field in offset_of | ||
--> $DIR/feature-gate-offset-of-nested.rs:24:33 | ||
| | ||
LL | offset_of!((u32, (S, T)), 1.1); | ||
| _____----------------------------^- | ||
| | | | ||
| | in this macro invocation | ||
LL | | offset_of!(S, b.0); | ||
LL | | offset_of!((S, ()), 0.c); | ||
LL | | offset_of!(S, c.t); | ||
... | | ||
| | ||
= note: see issue #120140 <https://github.com/rust-lang/rust/issues/120140> for more information | ||
= help: add `#![feature(offset_of_nested)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0658]: only a single ident or integer is stable as the field in offset_of | ||
--> $DIR/feature-gate-offset-of-nested.rs:25:21 | ||
| | ||
LL | offset_of!(S, b.0); | ||
| ^ | ||
| | ||
= note: see issue #120140 <https://github.com/rust-lang/rust/issues/120140> for more information | ||
= help: add `#![feature(offset_of_nested)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: only a single ident or integer is stable as the field in offset_of | ||
--> $DIR/feature-gate-offset-of-nested.rs:26:27 | ||
| | ||
LL | offset_of!((S, ()), 0.c); | ||
| ^ | ||
| | ||
= note: see issue #120140 <https://github.com/rust-lang/rust/issues/120140> for more information | ||
= help: add `#![feature(offset_of_nested)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: only a single ident or integer is stable as the field in offset_of | ||
--> $DIR/feature-gate-offset-of-nested.rs:27:21 | ||
| | ||
LL | offset_of!(S, c.t); | ||
| ^ | ||
| | ||
= note: see issue #120140 <https://github.com/rust-lang/rust/issues/120140> for more information | ||
= help: add `#![feature(offset_of_nested)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![feature(offset_of)] | ||
#![feature(offset_of_nested)] | ||
#![deny(dead_code)] | ||
|
||
use std::mem::offset_of; | ||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![feature(offset_of)] | ||
|
||
use std::mem::offset_of; | ||
|
||
fn main() { | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![feature(offset_of, extern_types)] | ||
#![feature(extern_types)] | ||
|
||
use std::mem::offset_of; | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![feature(offset_of, offset_of_enum)] | ||
#![feature(offset_of_enum, offset_of_nested)] | ||
|
||
use std::mem::offset_of; | ||
|
||
|
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
// Test that inference types in `offset_of!` don't ICE. | ||
|
||
#![feature(offset_of)] | ||
|
||
struct Foo<T> { | ||
x: T, | ||
} | ||
|
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
Oops, something went wrong.