diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 76c73f12f4e..9ccca9e6a08 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -697,9 +697,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn unresolved_lifetime_ref(&self, lifetime_ref: &hir::Lifetime) { - span_err!(self.sess, lifetime_ref.span, E0261, - "use of undeclared lifetime name `{}`", - lifetime_ref.name); + struct_span_err!(self.sess, lifetime_ref.span, E0261, + "use of undeclared lifetime name `{}`", lifetime_ref.name) + .span_label(lifetime_ref.span, &format!("undeclared lifetime")) + .emit(); } fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDef]) { @@ -708,8 +709,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { for lifetime in lifetimes { if lifetime.lifetime.name == keywords::StaticLifetime.name() { - span_err!(self.sess, lifetime.lifetime.span, E0262, - "invalid lifetime parameter name: `{}`", lifetime.lifetime.name); + let lifetime = lifetime.lifetime; + let mut err = struct_span_err!(self.sess, lifetime.span, E0262, + "invalid lifetime parameter name: `{}`", lifetime.name); + err.span_label(lifetime.span, + &format!("{} is a reserved lifetime name", lifetime.name)); + err.emit(); } } diff --git a/src/test/compile-fail/E0261.rs b/src/test/compile-fail/E0261.rs index 4196ad370b8..558c1c38144 100644 --- a/src/test/compile-fail/E0261.rs +++ b/src/test/compile-fail/E0261.rs @@ -9,9 +9,11 @@ // except according to those terms. fn foo(x: &'a str) { } //~ ERROR E0261 + //~| undeclared lifetime struct Foo { x: &'a str, //~ ERROR E0261 + //~| undeclared lifetime } fn main() {} diff --git a/src/test/compile-fail/E0262.rs b/src/test/compile-fail/E0262.rs index e09e4766d51..41b6acaee4a 100644 --- a/src/test/compile-fail/E0262.rs +++ b/src/test/compile-fail/E0262.rs @@ -9,5 +9,6 @@ // except according to those terms. fn foo<'static>(x: &'static str) { } //~ ERROR E0262 + //~| 'static is a reserved lifetime name fn main() {}