-
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.
Auto merge of #111684 - ChayimFriedman2:unused-offset-of, r=WaffleLapkin
Warn on unused `offset_of!()` result The usage of `core::hint::must_use()` means that we don't get a specialized message. I figured out that since there are plenty of other methods that just have `#[must_use]` with no message it'll be fine, but it is a bit unfortunate that the error mentions `must_use` and not `offset_of!`. Fixes #111669.
- Loading branch information
Showing
13 changed files
with
333 additions
and
135 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
44 changes: 0 additions & 44 deletions
44
tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff
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,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; | ||
} | ||
} | ||
|
72 changes: 72 additions & 0 deletions
72
tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff
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,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; | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff
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,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; | ||
} | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff
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,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; | ||
} | ||
} | ||
|
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,5 @@ | ||
// unit-test: ConstProp | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
|
||
#![feature(offset_of)] | ||
|
||
|
Oops, something went wrong.