-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
elided lifetime #46254
elided lifetime #46254
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Unassigning myself since this isn't really my area. Please make sure to make the appropriate folks from @rust-lang/compiler aware of your PR, @Dylan-DPC. |
☔ The latest upstream changes (presumably #46430) made this pull request unmergeable. Please resolve the merge conflicts. |
BTW you should rebase instead of merging. |
Yeah thanks. But i resolved the conflicts on the Github UI (since it were minor conflicts) which i assume merges by default. |
You can still rebase, and it will remove the merge commit. |
Yeah sure |
☔ The latest upstream changes (presumably #46305) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry, somehow this didn't wind up assigned to me. |
@Dylan-DPC so it seems like you're not actually issuing the lint anywhere -- is that right? Do you need help with just how to do this? |
Ah, actually, you're probably going to hit the same issue that @gaurikholkar hit in #46441. In particular, we can't issue lints from |
That said, #46441 is a good PR to look at for how to issue lints in general. =) |
Yeah i will rebase ontop of it. |
Hi @Dylan-DPC, how are you doing with this? #46657 is merged so I think you can rebase on top of that now. |
09343db
to
ee254cb
Compare
src/librustc/lint/builtin.rs
Outdated
@@ -292,6 +298,7 @@ impl LintPass for HardwiredLints { | |||
COERCE_NEVER, | |||
SINGLE_USE_LIFETIME, | |||
TYVAR_BEHIND_RAW_POINTER | |||
ELIDED_LIFETIME_IN_PATH |
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.
Missing a comma on the line above
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.
Thanks fixed
yeah trying to figure out how to issue. Should i just issue it when deprecated is true? |
@@ -0,0 +1,16 @@ | |||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
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.
Add the .stderr file for the ui test
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.
You can run ./x.py test --stage 1 src/test/ui to get the stderr file
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.
Ya thanks. Just have to work on some stuff before that
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.
Obviously you have to add the code that actually issues the lint =) let me know if you need any tips on that
declare_lint! { | ||
pub ELIDED_LIFETIME_IN_PATH, | ||
Allow, | ||
"hidden lifetime parameters are deprecated, try `Foo<'_>`" |
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.
Let's change the message to:
elided lifetime parameters from structs, enums, or such types are deprecated; use '_
instead
#![deny(elided_lifetime_in_path)] | ||
struct Foo<'a> { x: &'a u32 } | ||
fn foo(x: &Foo) { | ||
// ^^^ warning: hidden lifetime parameters are deprecated, try `Foo<'_>` |
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 should be //~^ ERROR: ...
That is an annotation that indicates that we expect an error on the line above. The .stderr
file will give more precise information.
Oh, I missed this comment:
Yep, I think so. |
To issue the lint (i.e., when deprecated is true), you would want something like this: rust/src/librustc/middle/resolve_lifetime.rs Lines 1228 to 1234 in 78493ed
|
Thanks. My question was do i need to do perform any other check? |
@Dylan-DPC |
@eddyb nice. Thanks |
@bors r+ |
@Dylan-DPC: 🔑 Insufficient privileges: Not in reviewers |
@bors r=nikomatsakis |
📌 Commit accd997 has been approved by |
⌛ Testing commit accd997 with merge 2575f9713fc5cbfffc83cc99ed2430d4cbba2ecd... |
💔 Test failed - status-travis |
@bors retry |
⌛ Testing commit accd997 with merge d1c54614c99d7227d5ed8c15ace39887e1e8a582... |
💔 Test failed - status-travis |
elided lifetime Closes #45992 Hey Having a problem with my config so decided to make a WIP PR nevertheless. Will add some more tests.
☀️ Test successful - status-appveyor, status-travis |
The existing elided-lifetimes-in-paths lint (introduced in Nov. 2017's accd997 / rust-lang#46254) lacked stuctured suggestions and—much more alarmingly—produced false positives on associated functions (like `Ref::clone`) and on anonymous '_ lifetimes (!!—yes, the very anonymous lifetimes that we meant to suggest "instead"). That this went apparently unnoticed for so long maybe tells you something about how many people actually bother to flip on allow-by-default lints. After many hours of good old-fashioned American elbow grease—and a little help from expert reviewers—it turns out that getting the right answer is a lot easier if we fire the lint while lowering the Higher Intermediate Representation. The lint is promoted to the idioms-2018 group. Also, in the matter of test filenames, "elided" only has one 'l' (see, e.g., https://en.wiktionary.org/wiki/elide). Resolves rust-lang#52041.
…_re-pub-lic, r=nikomatsakis add structured suggestions and fix false-positive for elided-lifetimes-in-paths lint This adds structured suggestions to the elided-lifetimes-in-paths lint (introduced in Nov. 2017's #46254), prevents it from emitting a false-positive on anonymous (underscore) lifetimes (!), and adds it to the idioms-2018 group (#52041). ~~As an aside, "elided-lifetimes-in-paths" seems like an unfortunate name, because it's not clear exactly what "elided" means. The motivation for this lint (see original issue #45992, and [RFC 2115](https://github.com/rust-lang/rfcs/blob/e978a8d3017a01d632f916140c98802505cd1324/text/2115-argument-lifetimes.md#motivation)) seems to be specifically about not supplying angle-bracketed lifetime arguments to non-`&` types, but (1) the phrase "lifetime elision" has historically also referred to the ability to not supply a lifetime name to `&` references, and (2) an `is_elided` method in the HIR returns true for anoymous/underscore lifetimes, which is _not_ what we're trying to lint here. (That naming confusion is almost certainly what led to the false positive addressed here.) Given that the lint is relatively new and is allow-by-default, is it too late to rename it ... um, _again_ (#50879)?~~ ~~This does _not_ address a couple of other false positives discovered in #52041 (comment) ![elided_states](https://user-images.githubusercontent.com/1076988/42302137-2bf9479c-7fce-11e8-8bd0-f29aefc802b6.png) r? @nikomatsakis cc @nrc @petrochenkov
Closes #45992
Hey
Having a problem with my config so decided to make a WIP PR nevertheless. Will add some more tests.