Skip to content

Commit 2abce06

Browse files
authored
Rollup merge of rust-lang#65307 - Phosphorus15:master, r=varkor
Try fix incorrect "explicit lifetime name needed" This pr is trying to fixes rust-lang#65285 .
2 parents fd1cf87 + 53187c5 commit 2abce06

3 files changed

+43
-4
lines changed

src/librustc/hir/lowering.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3291,10 +3291,14 @@ impl<'a> LoweringContext<'a> {
32913291
let id = self.sess.next_node_id();
32923292
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
32933293
}
3294-
// This is the normal case.
3295-
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),
3296-
3297-
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
3294+
// `PassThrough` is the normal case.
3295+
// `new_error_lifetime`, which would usually be used in the case of `ReportError`,
3296+
// is unsuitable here, as these can occur from missing lifetime parameters in a
3297+
// `PathSegment`, for which there is no associated `'_` or `&T` with no explicit
3298+
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
3299+
// later, at which point a suitable error will be emitted.
3300+
| AnonymousLifetimeMode::PassThrough
3301+
| AnonymousLifetimeMode::ReportError => self.new_implicit_lifetime(span),
32983302
}
32993303
}
33003304

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_type="lib"]
2+
3+
struct Nested<K>(K);
4+
5+
fn should_error<T>() where T : Into<&u32> {}
6+
//~^ ERROR `&` without an explicit lifetime name cannot be used here [E0637]
7+
8+
trait X<'a, K: 'a> {
9+
fn foo<'b, L: X<&'b Nested<K>>>();
10+
//~^ ERROR missing lifetime specifier [E0106]
11+
}
12+
13+
fn bar<'b, L: X<&'b Nested<i32>>>(){}
14+
//~^ ERROR missing lifetime specifier [E0106]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0637]: `&` without an explicit lifetime name cannot be used here
2+
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:5:37
3+
|
4+
LL | fn should_error<T>() where T : Into<&u32> {}
5+
| ^ explicit lifetime name needed here
6+
7+
error[E0106]: missing lifetime specifier
8+
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:19
9+
|
10+
LL | fn foo<'b, L: X<&'b Nested<K>>>();
11+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
12+
13+
error[E0106]: missing lifetime specifier
14+
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:13:15
15+
|
16+
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
17+
| ^^^^^^^^^^^^^^^^^^ expected lifetime parameter
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)