Skip to content

Warn on unused offset_of!() result #111684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,8 @@ impl<T> SizedTypeProperties for T {}
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
/// ```
#[unstable(feature = "offset_of", issue = "106655")]
#[allow_internal_unstable(builtin_syntax)]
#[allow_internal_unstable(builtin_syntax, hint_must_use)]
pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) {
builtin # offset_of($Container, $($fields).+)
// The `{}` is for better error messages
crate::hint::must_use({builtin # offset_of($Container, $($fields).+)})
}
44 changes: 0 additions & 44 deletions tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
- // MIR for `concrete` before ConstProp
+ // MIR for `concrete` after ConstProp

fn concrete() -> () {
let mut _0: ();
let _1: usize;
let mut _2: usize;
let mut _4: usize;
let mut _6: usize;
let mut _8: usize;
scope 1 {
debug x => _1;
let _3: usize;
scope 2 {
debug y => _3;
let _5: usize;
scope 3 {
debug z0 => _5;
let _7: usize;
scope 4 {
debug z1 => _7;
}
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [0]);
+ _2 = const 4_usize;
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
}

bb1: {
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [1]);
+ _4 = const 0_usize;
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
}

bb2: {
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [2, 0]);
+ _6 = const 2_usize;
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
}

bb3: {
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [2, 1]);
+ _8 = const 3_usize;
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
}

bb4: {
StorageDead(_8);
_0 = const ();
StorageDead(_7);
StorageDead(_5);
StorageDead(_3);
StorageDead(_1);
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
- // MIR for `concrete` before ConstProp
+ // MIR for `concrete` after ConstProp

fn concrete() -> () {
let mut _0: ();
let _1: usize;
let mut _2: usize;
let mut _4: usize;
let mut _6: usize;
let mut _8: usize;
scope 1 {
debug x => _1;
let _3: usize;
scope 2 {
debug y => _3;
let _5: usize;
scope 3 {
debug z0 => _5;
let _7: usize;
scope 4 {
debug z1 => _7;
}
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [0]);
+ _2 = const 4_usize;
_1 = must_use::<usize>(move _2) -> bb1;
}

bb1: {
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [1]);
+ _4 = const 0_usize;
_3 = must_use::<usize>(move _4) -> bb2;
}

bb2: {
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [2, 0]);
+ _6 = const 2_usize;
_5 = must_use::<usize>(move _6) -> bb3;
}

bb3: {
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [2, 1]);
+ _8 = const 3_usize;
_7 = must_use::<usize>(move _8) -> bb4;
}

bb4: {
StorageDead(_8);
_0 = const ();
StorageDead(_7);
StorageDead(_5);
StorageDead(_3);
StorageDead(_1);
return;
}
}

40 changes: 0 additions & 40 deletions tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
- // MIR for `generic` before ConstProp
+ // MIR for `generic` after ConstProp

fn generic() -> () {
let mut _0: ();
let _1: usize;
let mut _2: usize;
let mut _4: usize;
let mut _6: usize;
let mut _8: usize;
scope 1 {
debug gx => _1;
let _3: usize;
scope 2 {
debug gy => _3;
let _5: usize;
scope 3 {
debug dx => _5;
let _7: usize;
scope 4 {
debug dy => _7;
}
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [0]);
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
}

bb1: {
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [1]);
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
}

bb2: {
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
_6 = OffsetOf(Delta<T>, [1]);
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
}

bb3: {
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
_8 = OffsetOf(Delta<T>, [2]);
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
}

bb4: {
StorageDead(_8);
_0 = const ();
StorageDead(_7);
StorageDead(_5);
StorageDead(_3);
StorageDead(_1);
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
- // MIR for `generic` before ConstProp
+ // MIR for `generic` after ConstProp

fn generic() -> () {
let mut _0: ();
let _1: usize;
let mut _2: usize;
let mut _4: usize;
let mut _6: usize;
let mut _8: usize;
scope 1 {
debug gx => _1;
let _3: usize;
scope 2 {
debug gy => _3;
let _5: usize;
scope 3 {
debug dx => _5;
let _7: usize;
scope 4 {
debug dy => _7;
}
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [0]);
_1 = must_use::<usize>(move _2) -> bb1;
}

bb1: {
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [1]);
_3 = must_use::<usize>(move _4) -> bb2;
}

bb2: {
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
_6 = OffsetOf(Delta<T>, [1]);
_5 = must_use::<usize>(move _6) -> bb3;
}

bb3: {
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
_8 = OffsetOf(Delta<T>, [2]);
_7 = must_use::<usize>(move _8) -> bb4;
}

bb4: {
StorageDead(_8);
_0 = const ();
StorageDead(_7);
StorageDead(_5);
StorageDead(_3);
StorageDead(_1);
return;
}
}

1 change: 1 addition & 0 deletions tests/mir-opt/const_prop/offset_of.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// unit-test: ConstProp
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![feature(offset_of)]

Expand Down
Loading