Skip to content
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

Merged
merged 1 commit into from
Feb 3, 2018
Merged

elided lifetime #46254

merged 1 commit into from
Feb 3, 2018

Conversation

Dylan-DPC-zz
Copy link

Closes #45992

Hey
Having a problem with my config so decided to make a WIP PR nevertheless. Will add some more tests.

@rust-highfive
Copy link
Collaborator

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.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2017
@michaelwoerister
Copy link
Member

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.

@michaelwoerister michaelwoerister removed their assignment Nov 27, 2017
@Dylan-DPC-zz
Copy link
Author

@nikomatsakis

@bors
Copy link
Contributor

bors commented Dec 2, 2017

☔ The latest upstream changes (presumably #46430) made this pull request unmergeable. Please resolve the merge conflicts.

@eddyb
Copy link
Member

eddyb commented Dec 3, 2017

BTW you should rebase instead of merging.

@Dylan-DPC-zz
Copy link
Author

Yeah thanks. But i resolved the conflicts on the Github UI (since it were minor conflicts) which i assume merges by default.

@eddyb
Copy link
Member

eddyb commented Dec 3, 2017

You can still rebase, and it will remove the merge commit.

@Dylan-DPC-zz
Copy link
Author

Yeah sure

@bors
Copy link
Contributor

bors commented Dec 5, 2017

☔ The latest upstream changes (presumably #46305) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

Sorry, somehow this didn't wind up assigned to me.

@nikomatsakis
Copy link
Contributor

@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?

@nikomatsakis
Copy link
Contributor

Ah, actually, you're probably going to hit the same issue that @gaurikholkar hit in #46441. In particular, we can't issue lints from resolve_lifetimes right now because of when it executes. I fixed this as part of this commit in Gauri's PR. You should probably rebase atop that commit, but maybe I should factor it out into a separate PR so you are not blocked on #46441 having landed.

@nikomatsakis
Copy link
Contributor

That said, #46441 is a good PR to look at for how to issue lints in general. =)

@Dylan-DPC-zz
Copy link
Author

Yeah i will rebase ontop of it.

@aidanhs
Copy link
Member

aidanhs commented Dec 14, 2017

Hi @Dylan-DPC, how are you doing with this? #46657 is merged so I think you can rebase on top of that now.

@Dylan-DPC-zz Dylan-DPC-zz force-pushed the ellided-lifetime branch 2 times, most recently from 09343db to ee254cb Compare December 30, 2017 11:02
@@ -292,6 +298,7 @@ impl LintPass for HardwiredLints {
COERCE_NEVER,
SINGLE_USE_LIFETIME,
TYVAR_BEHIND_RAW_POINTER
ELIDED_LIFETIME_IN_PATH

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fixed

@Dylan-DPC-zz
Copy link
Author

hi @nikomatsakis

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?

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

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

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

Copy link
Author

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

Copy link
Contributor

@nikomatsakis nikomatsakis left a 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<'_>`"
Copy link
Contributor

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<'_>`
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor

Oh, I missed this comment:

yeah trying to figure out how to issue. Should i just issue it when deprecated is true?

Yep, I think so.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 3, 2018

To issue the lint (i.e., when deprecated is true), you would want something like this:

this.tcx
.struct_span_lint_node(lint::builtin::SINGLE_USE_LIFETIME,
id,
span,
&format!("lifetime name `{}` only used once",
hir_lifetime.name.name()))
.emit();

@Dylan-DPC-zz
Copy link
Author

Thanks. My question was do i need to do perform any other check?

@eddyb
Copy link
Member

eddyb commented Feb 1, 2018

@Dylan-DPC git reflog means you only lose commits if you don't look at them for a month or so.

@Dylan-DPC-zz
Copy link
Author

@eddyb nice. Thanks

@Dylan-DPC-zz
Copy link
Author

@bors r+

@bors
Copy link
Contributor

bors commented Feb 2, 2018

@Dylan-DPC: 🔑 Insufficient privileges: Not in reviewers

@estebank
Copy link
Contributor

estebank commented Feb 2, 2018

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Feb 2, 2018

📌 Commit accd997 has been approved by nikomatsakis

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2018
@bors
Copy link
Contributor

bors commented Feb 2, 2018

⌛ Testing commit accd997 with merge 2575f9713fc5cbfffc83cc99ed2430d4cbba2ecd...

@bors
Copy link
Contributor

bors commented Feb 3, 2018

💔 Test failed - status-travis

@shepmaster
Copy link
Member

The job exceeded the maximum time limit for jobs, and has been terminated.

@bors retry

@bors
Copy link
Contributor

bors commented Feb 3, 2018

⌛ Testing commit accd997 with merge d1c54614c99d7227d5ed8c15ace39887e1e8a582...

@bors
Copy link
Contributor

bors commented Feb 3, 2018

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Feb 3, 2018

@bors retry #43283

@bors
Copy link
Contributor

bors commented Feb 3, 2018

⌛ Testing commit accd997 with merge aa0a5a8...

bors added a commit that referenced this pull request Feb 3, 2018
elided lifetime

Closes #45992

Hey
Having a problem with my config so decided to make a WIP PR nevertheless. Will add some more tests.
@bors
Copy link
Contributor

bors commented Feb 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing aa0a5a8 to master...

@bors bors merged commit accd997 into rust-lang:master Feb 3, 2018
@Dylan-DPC-zz Dylan-DPC-zz deleted the ellided-lifetime branch February 3, 2018 17:38
zackmdavis added a commit to zackmdavis/rust that referenced this pull request Jul 22, 2018
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.
bors added a commit that referenced this pull request Jul 22, 2018
…_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.