-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add a lint against never type fallback affecting unsafe code #123939
Add a lint against never type fallback affecting unsafe code #123939
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in coverage instrumentation. cc @Zalathar |
This comment has been minimized.
This comment has been minimized.
7dad013
to
ea60ab1
Compare
@@ -4179,6 +4180,49 @@ declare_lint! { | |||
"named arguments in format used positionally" | |||
} | |||
|
|||
declare_lint! { | |||
/// The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback |
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 lint description should mention what never type fallback actually is, I think most people are not aware of it at all
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.
That's one of the annoying problems of all the never type stuff, fallback can't be explained without going somewhat indepth :(
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 added an explanation, does it look good?
Thinking about
Where The algorithm to actually check this is
But This PR (and a future one for the third lint) are struggling/will struggle from a similar problem: we need to be able to go backwards (because this lint does not care about coercion direction -- since rust infers both ways). I will try to use just |
Okay. I'll try adding opt-in backreferences to |
ea60ab1
to
14f1124
Compare
☔ The latest upstream changes (presumably #124026) made this pull request unmergeable. Please resolve the merge conflicts. |
…r, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? `@fmease` needed for rust-lang#123939
…r, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? ``@fmease`` needed for rust-lang#123939
…r, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? `@fmease` needed for rust-lang#123939
…r, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? ``@fmease`` needed for rust-lang#123939
…r, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? ```@fmease``` needed for rust-lang#123939
Rollup merge of rust-lang#123980 - WaffleLapkin:graph-average-refactor, r=wesleywiser Add an opt-in to store incoming edges in `VecGraph` + misc r? ```@fmease``` needed for rust-lang#123939
14f1124
to
447a08c
Compare
This comment has been minimized.
This comment has been minimized.
447a08c
to
f56a71b
Compare
This comment has been minimized.
This comment has been minimized.
cee445b
to
2a14501
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
2a14501
to
d36b7f0
Compare
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.
Some style nits, and then requesting that you implement the method case too.
@compiler-errors I've added support for unsafe methods, alongside other unsafe things which may have a type infered from the environment (like pointer dereference, union access, etc). The change is annoyingly big, but yeah... |
hir_typeck_never_type_fallback_flowing_into_unsafe = | ||
never type fallback affects this call to an `unsafe` function | ||
never type fallback affects this {$reason -> | ||
[call] call to an `unsafe` function | ||
[union_field] union access | ||
[deref] raw pointer dereference | ||
[path] `unsafe` function | ||
[method] call to an `unsafe` method |
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.
Split this into 5 slugs and do:
#[derive(Diagnostic)]
enum NeverTypeFallbackFlowingIntoUnsafe {
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
Call,
...
}
And then
hir_typeck_never_type_fallback_flowing_into_unsafe_call = never type fallback affects this call to an `unsafe` function
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've kept the reason enum and then convert to the diagnostic, cause I find using errors::*
until the literal "emit" somewhat weird. But LMK if I should just return the diagnostic from the "find unsafe infer vars" function.
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.
r=me after splitting the fluent slugs
☔ The latest upstream changes (presumably #124558) made this pull request unmergeable. Please resolve the merge conflicts. |
(never_type_fallback_flowing_into_unsafe)
ea4473d
to
b562617
Compare
that's fine @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (fcc06c8): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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: 674.637s -> 671.059s (-0.53%) |
…s, r=workingjubilee Document never type fallback in `!`'s docs Pulled the documentation I've written for rust-lang#123939. I want a single place where never type fallback is explained, which can be referred in all the lints and migration materials.
I'm not very happy with the code quality...(ended up updatingVecGraph
not allowing you to get predecessors is very annoying. This should work though, so there is that.VecGraph
to support getting predecessors)First few commits are from #123934 #123980