Skip to content

Commit

Permalink
in which the elided-lifetimes-in-paths lint stops firing on '_
Browse files Browse the repository at this point in the history
`is_elided` is true for both underscore (`'_`) and implicit (no
representation in source code) lifetimes, but we don't want to fire the
lint on the former, because the entire point of the lint is to suggest
changing the latter to the former (see the initial issue rust-lang#45992).

It seems unfortunate for there to be ambiguity on whether the word
"elided" includes underscore lifetimes or not—the mandate of the
elided-lifetimes-in-paths lint seems to suggest it doesn't, whereas
the `is_elided` method seems to suggest it does—but it's beyond us to
resolve that in this commit. For now, let the message say "implicit"
for definiteness.

This relates to rust-lang#52041.
  • Loading branch information
zackmdavis committed Jul 4, 2018
1 parent 9573841 commit 3d4c2ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl LifetimeName {
}
}

pub fn is_implicit(&self) -> bool {
self == &LifetimeName::Implicit
}

fn is_static(&self) -> bool {
self == &LifetimeName::Static
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,24 +2068,24 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {

fn resolve_elided_lifetimes(&mut self,
lifetime_refs: Vec<&'tcx hir::Lifetime>,
deprecated: bool) {
deprecate_implicit: bool) {
if lifetime_refs.is_empty() {
return;
}

let span = lifetime_refs[0].span;
let id = lifetime_refs[0].id;
let mut late_depth = 0;
let mut scope = self.scope;
if deprecated {
self.tcx
.struct_span_lint_node(
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
id,
span,
&format!("hidden lifetime parameters are deprecated, try `Foo<'_>`"),
)
.emit();
if deprecate_implicit && lifetime_refs[0].name.is_implicit() {
let mut err = self.tcx.struct_span_lint_node(
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
lifetime_refs[0].id, // FIXME: HirIdify #50928
span,
&format!("implicit lifetime parameters in types are deprecated"),
);
// FIXME: suggest `'_` (need to take into account whether angle-bracketed
// params already exist)
err.emit();
}
let error = loop {
match *scope {
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/in-band-lifetimes/elided-lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
struct Foo<'a> { x: &'a u32 }

fn foo(x: &Foo) {
//~^ ERROR: hidden lifetime parameters are deprecated, try `Foo<'_>`
//~^ ERROR: implicit lifetime parameters in types are deprecated
}

fn bar(x: &Foo<'_>) {
//~^ ERROR: hidden lifetime parameters are deprecated, try `Foo<'_>`
}
fn bar(x: &Foo<'_>) {}

fn main() {}
10 changes: 2 additions & 8 deletions src/test/ui/in-band-lifetimes/elided-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: hidden lifetime parameters are deprecated, try `Foo<'_>`
error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:16:12
|
LL | fn foo(x: &Foo) {
Expand All @@ -10,11 +10,5 @@ note: lint level defined here
LL | #![deny(elided_lifetimes_in_paths)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: hidden lifetime parameters are deprecated, try `Foo<'_>`
--> $DIR/elided-lifetimes.rs:20:16
|
LL | fn bar(x: &Foo<'_>) {
| ^^

error: aborting due to 2 previous errors
error: aborting due to previous error

0 comments on commit 3d4c2ed

Please sign in to comment.