-
Notifications
You must be signed in to change notification settings - Fork 14k
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
base: main
Are you sure you want to change the base?
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
|
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 |
Closes #149042
Attempts to be smarter about identifying 'real'/user-written unreachable code to raise the lint