-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 new mismatched-lifetime-syntaxes
lint
#138677
base: master
Are you sure you want to change the base?
Add a new mismatched-lifetime-syntaxes
lint
#138677
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
compiler/rustc_lint/src/lints.rs
Outdated
// TODO: how avoid calling it lifetime_name2? | ||
diag.arg("lifetime_name2", self.lifetime_name); |
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.
This is called lifetime_name2
because the nested MismatchedElidedLifetimeStylesSuggestion::Named
also declares a fluent variable called lifetime_name
and they clobber each other. I'm pretty sure this is me doing it wrong, but I have not yet found the right way.
Thanks to:
|
478a98e
to
e15c083
Compare
This comment has been minimized.
This comment has been minimized.
e15c083
to
ca86221
Compare
mismatched_elided_lifetime_styles
lintmismatched-lifetime-syntaxes
lint
This comment has been minimized.
This comment has been minimized.
ca86221
to
6b4ba02
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #138719) made this pull request unmergeable. Please resolve the merge conflicts. |
6b4ba02
to
7ff70d4
Compare
Some changes occurred to the CTFE machinery
cc @davidtwco, @compiler-errors, @TaKO8Ki Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
7ff70d4
to
3a95f66
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
3a95f66
to
1625496
Compare
This comment has been minimized.
This comment has been minimized.
This will allow us to eagerly translate messages on a top-level diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the awkward closure passed into Subdiagnostic and make better use of `Into`.
An upcoming lint will want to be able to know if a reference has a hidden lifetime (`&u8`) or an anonymous lifetime (`&'_ u8`). The code previously treated hidden lifetimes as anonymous. To preserve diagnostic quality, lifetime suggestions now need to know if they are in the context of a reference or a path, as there is different syntax for each. For example, a reference changes from `&u8` to `&'a u8` (add a space with no comma), while a path changes from `T` to `T<'a>` (add angle brackets) or `T<X>` to `T<'a, X>` (add a comma and a space). There's a minor ugliness introduced to -Zunpretty=hir output, as there's a non-idiomatic space character introduced after the ampersand, but it's called unpretty for a reason!
1625496
to
1cd8999
Compare
The lang-team discussed this and I attempted to summarize their decision. The summary-of-the-summary is:
Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even lead to unsound code! Some examples:
Matching up a references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:
Having a lint for consistent syntax of elided lifetimes will make the future goal of warning-by-default for paths participating in elision much simpler.
This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing
elided-named-lifetimes
lint, which means it starts out life as warn-by-default.