Skip to content

Commit 53187c5

Browse files
committed
Slides path lifetime to the lifetime resolver
add test to for the fix add descriptive text for the fix simplified code logics update descriptive comments update to cope with the tidyness requirement merged commit suggestions Co-Authored-By: varkor <[email protected]> truncated redundant comments update to cope with tidy-check
1 parent 000d90b commit 53187c5

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/librustc/hir/lowering.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,10 +3281,14 @@ impl<'a> LoweringContext<'a> {
32813281
let id = self.sess.next_node_id();
32823282
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
32833283
}
3284-
// This is the normal case.
3285-
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),
3286-
3287-
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
3284+
// `PassThrough` is the normal case.
3285+
// `new_error_lifetime`, which would usually be used in the case of `ReportError`,
3286+
// is unsuitable here, as these can occur from missing lifetime parameters in a
3287+
// `PathSegment`, for which there is no associated `'_` or `&T` with no explicit
3288+
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
3289+
// later, at which point a suitable error will be emitted.
3290+
| AnonymousLifetimeMode::PassThrough
3291+
| AnonymousLifetimeMode::ReportError => self.new_implicit_lifetime(span),
32883292
}
32893293
}
32903294

Lines changed: 14 additions & 0 deletions
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]
Lines changed: 21 additions & 0 deletions
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)