Skip to content
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

Warn on unused offset_of!() result #111684

Merged
merged 1 commit into from
Jun 21, 2023

Conversation

ChayimFriedman2
Copy link
Contributor

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.

@rustbot
Copy link
Collaborator

rustbot commented May 17, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 17, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 17, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-log-analyzer

This comment has been minimized.

library/core/src/mem/mod.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Jun 8, 2023

@ChayimFriedman2 you should probably rebase on master and then run ./x.py test tests/ui/offset-of to see which tests fail because of those changes and fix them (by adding let _ = s, I suppose).

@rust-log-analyzer

This comment has been minimized.

@@ -2,49 +2,39 @@ error[E0308]: mismatched types
--> $DIR/offset-of-output-type.rs:12:17
|
LL | let _: u8 = offset_of!(S, v);
| -- ^^^^^^^^^^^^^^^^ expected `u8`, found `usize`
| |
| expected due to this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a shame we are missing those, but I'm not sure what to do with that...

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 8, 2023

📌 Commit 460c3a8f3019370ecf20876b24bc0ff4cb7372d6 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2023
@bors
Copy link
Contributor

bors commented Jun 9, 2023

⌛ Testing commit 460c3a8f3019370ecf20876b24bc0ff4cb7372d6 with merge 4c238050a5a58daca1fee25804464e9138506abf...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 9, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 9, 2023
@bors

This comment was marked as resolved.

@bors
Copy link
Contributor

bors commented Jun 19, 2023

📌 Commit d3caa2ab349d9eb234b1f61f57db27cf98ccf117 has been approved by WaffleLapkin

It is now in the queue for this repository.

@est31
Copy link
Member

est31 commented Jun 19, 2023

@ChayimFriedman2 that's interesting. I have tried running the command I suggested above and ran into some issues due to cross compilation toolchains not being available. So I couldn't reproduce your issue, but not because it's working for me but because it's even more broken :).

@bors
Copy link
Contributor

bors commented Jun 19, 2023

⌛ Testing commit d3caa2ab349d9eb234b1f61f57db27cf98ccf117 with merge 2e99d62427028bc9995f9bd056acdb1ccab80ab0...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 20, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 20, 2023
@ChayimFriedman2
Copy link
Contributor Author

I don't understand. This is exactly the opposite of the previous failure. Something strange is happening here.

@ChayimFriedman2
Copy link
Contributor Author

ChayimFriedman2 commented Jun 20, 2023

If I do what bors wants (which BTW is what --bless emits), then it fails locally. What should I do?

@oli-obk
Copy link
Contributor

oli-obk commented Jun 20, 2023

A few things:

  • what's your host?
  • do you have a config.toml? If so, what did you configure?
  • is it only failing for the 32 bit target but works for the 64 bit target?

@ChayimFriedman2
Copy link
Contributor Author

@oli-obk

what's your host?

x86_64-pc-windows-msvc

do you have a config.toml? If so, what did you configure?

It is configured to profile = "compiler".

is it only failing for the 32 bit target but works for the 64 bit target?

No, it fails for the 64 bit target (and doesn't check 32 bit therefore).

@oli-obk
Copy link
Contributor

oli-obk commented Jun 21, 2023

wait I'm confused. If you --bless, then the tests fail locally? Can you gist your entire log of that happening?

@ChayimFriedman2
Copy link
Contributor Author

@oli-obk

Building bootstrap
    Finished dev [unoptimized] target(s) in 0.19s
Building stage0 library artifacts (x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.54s
Building compiler artifacts (stage0 -> stage1, x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 1.66s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 library artifacts (x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 1.01s
Building stage0 tool compiletest (x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.69s
Check compiletest suite=mir-opt mode=mir-opt (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)

running 1 tests
F

failures:

---- [mir-opt] tests\mir-opt\const_prop\offset_of.rs stdout ----
29                StorageLive(_2);
30      -         _2 = OffsetOf(Alpha, [0]);
31      +         _2 = const 4_usize;
-                 _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
+                 _1 = must_use::<usize>(move _2) -> bb1;
33            }
34
35            bb1: {

38                StorageLive(_4);
39      -         _4 = OffsetOf(Alpha, [1]);
40      +         _4 = const 0_usize;
-                 _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
+                 _3 = must_use::<usize>(move _4) -> bb2;
42            }
43
44            bb2: {

47                StorageLive(_6);
48      -         _6 = OffsetOf(Alpha, [2, 0]);
49      +         _6 = const 2_usize;
-                 _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
+                 _5 = must_use::<usize>(move _6) -> bb3;
51            }
52
53            bb3: {

56                StorageLive(_8);
57      -         _8 = OffsetOf(Alpha, [2, 1]);
58      +         _8 = const 3_usize;
-                 _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
+                 _7 = must_use::<usize>(move _8) -> bb4;
60            }
61
62            bb4: {

thread '[mir-opt] tests\mir-opt\const_prop\offset_of.rs' panicked at 'Actual MIR output differs from expected MIR output C:\rust\tests\mir-opt\const_prop\offset_of.concrete.ConstProp.diff', src\tools\compiletest\src\runtest.rs:3652:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    [mir-opt] tests\mir-opt\const_prop\offset_of.rs

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 260 filtered out; finished in 891.43ms

@ChayimFriedman2
Copy link
Contributor Author

That is, --bless adds the possibility of unwinding, but locally it wants it to be non-unwinding call (probably it determines that the function cannot unwind). On borts, #111684 (comment) wants unwinding, but previously #111684 (comment) wanted non-unwinding.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 21, 2023

🤦 your test needs a // EMIT_MIR_FOR_EACH_PANIC_STRATEGY comment at the top of the file so that we end up with two diff files

@oli-obk
Copy link
Contributor

oli-obk commented Jun 21, 2023

@bors r=WaffleLapkin

@bors
Copy link
Contributor

bors commented Jun 21, 2023

📌 Commit 592844c has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 21, 2023
@bors
Copy link
Contributor

bors commented Jun 21, 2023

⌛ Testing commit 592844c with merge 006a26c...

@bors
Copy link
Contributor

bors commented Jun 21, 2023

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing 006a26c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 21, 2023
@bors bors merged commit 006a26c into rust-lang:master Jun 21, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 21, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (006a26c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 660.125s -> 659.628s (-0.08%)

@ChayimFriedman2 ChayimFriedman2 deleted the unused-offset-of branch June 22, 2023 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not using the result of offset_of should lint
9 participants