Skip to content

Commit f841067

Browse files
committed
in which the elided-lifetimes-in-paths lint stops firing on '_
`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.
1 parent 1a59677 commit f841067

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

src/librustc/hir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl LifetimeName {
272272
}
273273
}
274274

275+
pub fn is_implicit(&self) -> bool {
276+
self == &LifetimeName::Implicit
277+
}
278+
275279
fn is_static(&self) -> bool {
276280
self == &LifetimeName::Static
277281
}

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ declare_lint! {
252252
declare_lint! {
253253
pub ELIDED_LIFETIMES_IN_PATHS,
254254
Allow,
255-
"hidden lifetime parameters are deprecated, try `Foo<'_>`"
255+
"implicit lifetime parameters are deprecated"
256256
}
257257

258258
declare_lint! {

src/librustc/middle/resolve_lifetime.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -2068,24 +2068,24 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20682068

20692069
fn resolve_elided_lifetimes(&mut self,
20702070
lifetime_refs: Vec<&'tcx hir::Lifetime>,
2071-
deprecated: bool) {
2071+
deprecate_implicit: bool) {
20722072
if lifetime_refs.is_empty() {
20732073
return;
20742074
}
20752075

20762076
let span = lifetime_refs[0].span;
2077-
let id = lifetime_refs[0].id;
20782077
let mut late_depth = 0;
20792078
let mut scope = self.scope;
2080-
if deprecated {
2081-
self.tcx
2082-
.struct_span_lint_node(
2083-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
2084-
id,
2085-
span,
2086-
&format!("hidden lifetime parameters are deprecated, try `Foo<'_>`"),
2087-
)
2088-
.emit();
2079+
if deprecate_implicit && lifetime_refs[0].name.is_implicit() {
2080+
let mut err = self.tcx.struct_span_lint_node(
2081+
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
2082+
lifetime_refs[0].id, // FIXME: HirIdify #50928
2083+
span,
2084+
&format!("implicit lifetime parameters in types are deprecated"),
2085+
);
2086+
// FIXME: suggest `'_` (need to take into account whether angle-bracketed
2087+
// params already exist)
2088+
err.emit();
20892089
}
20902090
let error = loop {
20912091
match *scope {

src/test/ui/in-band-lifetimes/elided-lifetimes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
struct Foo<'a> { x: &'a u32 }
1515

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

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

2422
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: hidden lifetime parameters are deprecated, try `Foo<'_>`
1+
error: implicit lifetime parameters in types are deprecated
22
--> $DIR/elided-lifetimes.rs:16:12
33
|
44
LL | fn foo(x: &Foo) {
@@ -10,11 +10,5 @@ note: lint level defined here
1010
LL | #![deny(elided_lifetimes_in_paths)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: hidden lifetime parameters are deprecated, try `Foo<'_>`
14-
--> $DIR/elided-lifetimes.rs:20:16
15-
|
16-
LL | fn bar(x: &Foo<'_>) {
17-
| ^^
18-
19-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2014

0 commit comments

Comments
 (0)