-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Reduce confusing unreachable_code lints
#149044
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
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
|
Iirc some parts of mir building uses |
|
You'll probably need to bless the coverage tests with: Coverage instrumentation unfortunately relies on a bunch of fragile heuristics that get disturbed by changes like this one, but luckily the new output seems reasonable. |
Some examples of diagnostic changes with this error: unreachable expression
--> $DIR/void-branch.rs:10:9
|
LL | std::mem::uninitialized::<Void>();
| --------------------------------- any code following this expression is unreachable
LL | }
| ^ unreachable expressionLL | #[define_opaque(WithoutLt)]
LL | fn without_lt() -> impl for<'a> Trait<'a, Assoc = WithoutLt> {}
| -- ^
| |
| hidden type `&'a str` captures the lifetime `'a` as defined hereI'm not sure if there's any performance implications with using sourcemap parsing on a pretty hot path, I'll perf it |
|
Some changes occurred in coverage tests. cc @Zalathar |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Use a more accurate span for the implicit block return assignment
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first commit seems like a small improvement. The second commit touches a lot of test and coverage output for seemingly little gain, and doesn't seem worthwhile.
Supposedly this fixes #149042 but no test is added to cover that case. Seems like a test should be added?
This comment has been minimized.
This comment has been minimized.
Agree, I think I'll back it out (though the coverage changes were originally just not blessed with the first commit, so there's still going to be some sweeping changes there).
Imo, |
d1bc16c to
aed6c5d
Compare
#149042's description said a lint was issued in a case where it shouldn't be issued. |
|
Ah, this change is about turning |
7 | fn check() -> () {
| __________________^
8 | | make_never();
| | ------------ any code following this expression is unreachable
9 | | }
| |_^ unreachable expressioninto 8 | make_never();
| ------------^ unreachable expression
| |
| any code following this expression is unreachableI think there's a good argument to be made that the implicit void return should not be counted as 'code' that's unreachable. I'll see if that's feasible to reliably detect |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
aed6c5d to
d793f62
Compare
unreachable_code lints
|
@rustbot ready |
| std::mem::uninitialized::<Void>(); | ||
| println!(); | ||
| //~^ ERROR unreachable expression | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the error point on the unchanged test? Do you mind adding another if false block with the println an keep the original one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No error is raised within the block without the additional println (similarly to fn block in the other test I added).
Do you mind adding another if false block with the println an keep the original one?
Sorry, can you add an example? I'm not quite sure what this should look like
|
|
||
| let term = bb.terminator(); | ||
| match term.kind { | ||
| TerminatorKind::Goto { .. } | TerminatorKind::Return => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind adding a comment explaining why we return None here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// No user code in this bb, and our goto target may be reachable via other paths
There may be other cases where we shouldn't lint and/or should label with something other than "expression" but this was sufficient for the motivating examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skeptical about the goto. What about some kind of if a { panic!() } else { unreachable!() }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current (nightly) error
Two errors, each highlighting the if and else blocks respectivelywarning: unreachable expression
--> poc.rs:6:14
|
6 | if false {
| ______________^
7 | | //~^ ERROR unreachable expression
8 | | infallible();
| | ------------ any code following this expression is unreachable
9 | | } else {
| |_____^ unreachable expression
|
warning: unreachable expression
--> poc.rs:9:12
|
9 | } else {
| ____________^
10 | | //~^ ERROR unreachable expression
11 | | infallible();
| | ------------ any code following this expression is unreachable
12 | | }
| |_____^ unreachable expressionWith the current PR no error is emitted at all.
With the `Goto` arm removed
Two errors, both highlighting the entire if/else
warning: unreachable expression
--> poc.rs:6:5
|
6 | / if false {
7 | | //~^ ERROR unreachable expression
8 | | infallible();
| | ------------ any code following this expression is unreachable
9 | | } else {
10 | | //~^ ERROR unreachable expression
11 | | infallible();
12 | | }
| |_____^ unreachable expression
|
warning: unreachable expression
--> poc.rs:6:5
|
6 | / if false {
7 | | //~^ ERROR unreachable expression
8 | | infallible();
9 | | } else {
10 | | //~^ ERROR unreachable expression
11 | | infallible();
| | ------------ any code following this expression is unreachable
12 | | }
| |_____^ unreachable expressionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with a test illustrating this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for the current behaviour.
|
This seems ok to me once @cjgillot's questions are addressed. |
d793f62 to
2d9cd22
Compare
|
At this point I think we should just r? @cjgillot |
2d9cd22 to
98141e0
Compare
|
@bors r=cjgillot |
|
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing ea98522 (parent) -> af17d59 (this PR) Test differencesShow 4 test diffsStage 1
Stage 2
Additionally, 2 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard af17d59d71cd344fb34caab3e96c88b7c137f872 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (af17d59): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 472.807s -> 469.465s (-0.71%) |
Closes #149042
Attempts to be smarter about identifying 'real'/user-written unreachable code to raise the lint