Skip to content

Commit

Permalink
Rollup merge of rust-lang#65307 - Phosphorus15:master, r=varkor
Browse files Browse the repository at this point in the history
Try fix incorrect "explicit lifetime name needed"

This pr is trying to fixes rust-lang#65285 .
  • Loading branch information
tmandry authored Oct 15, 2019
2 parents a6ae7ae + 53187c5 commit ff9b99d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3291,10 +3291,14 @@ impl<'a> LoweringContext<'a> {
let id = self.sess.next_node_id();
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
}
// This is the normal case.
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),

AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
// `PassThrough` is the normal case.
// `new_error_lifetime`, which would usually be used in the case of `ReportError`,
// is unsuitable here, as these can occur from missing lifetime parameters in a
// `PathSegment`, for which there is no associated `'_` or `&T` with no explicit
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
// later, at which point a suitable error will be emitted.
| AnonymousLifetimeMode::PassThrough
| AnonymousLifetimeMode::ReportError => self.new_implicit_lifetime(span),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![crate_type="lib"]

struct Nested<K>(K);

fn should_error<T>() where T : Into<&u32> {}
//~^ ERROR `&` without an explicit lifetime name cannot be used here [E0637]

trait X<'a, K: 'a> {
fn foo<'b, L: X<&'b Nested<K>>>();
//~^ ERROR missing lifetime specifier [E0106]
}

fn bar<'b, L: X<&'b Nested<i32>>>(){}
//~^ ERROR missing lifetime specifier [E0106]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:5:37
|
LL | fn should_error<T>() where T : Into<&u32> {}
| ^ explicit lifetime name needed here

error[E0106]: missing lifetime specifier
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:19
|
LL | fn foo<'b, L: X<&'b Nested<K>>>();
| ^^^^^^^^^^^^^^^^ expected lifetime parameter

error[E0106]: missing lifetime specifier
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:13:15
|
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
| ^^^^^^^^^^^^^^^^^^ expected lifetime parameter

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0106`.

0 comments on commit ff9b99d

Please sign in to comment.