diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 482af9c005f32..c71d4e90ed389 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -189,6 +189,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self, region: ty::Region<'tcx>, ) -> (String, Option) { + let cm = self.sess.codemap(); + let scope = region.free_region_binding_scope(self); let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); let unknown; @@ -219,10 +221,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } }; let (prefix, span) = match *region { - ty::ReEarlyBound(ref br) => ( - format!("the lifetime {} as defined on", br.name), - self.sess.codemap().def_span(self.hir.span(node)), - ), + ty::ReEarlyBound(ref br) => { + let mut sp = cm.def_span(self.hir.span(node)); + if let Some(generics) = self.hir.get_generics(scope) { + for param in &generics.params { + if param.name.name().as_str() == br.name.as_str() { + sp = param.span; + } + } + } + (format!("the lifetime {} as defined on", br.name), sp) + } ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), @@ -234,7 +243,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ), _ => ( format!("the lifetime {} as defined on", fr.bound_region), - self.sess.codemap().def_span(self.hir.span(node)), + cm.def_span(self.hir.span(node)), ), }, _ => bug!(), diff --git a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.rs b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.rs index 04f90ea9ad3a2..9ed07d1c8e92f 100644 --- a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.rs +++ b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.rs @@ -36,6 +36,7 @@ impl<'a, 't> Foo<'a, 't> for &'a isize { fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { //~^ ERROR method not compatible with trait + //~| ERROR method not compatible with trait // // Note: This is a terrible error message. It is caused // because, in the trait, 'b is early bound, and in the impl, diff --git a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr index b530fea1e5977..deab39b99246c 100644 --- a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr +++ b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr @@ -29,6 +29,25 @@ note: the lifetime 'c as defined on the method body at 37:5... | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 37:24 + --> $DIR/regions-bound-missing-bound-in-impl.rs:37:24 + | +LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { + | ^^ + +error[E0308]: method not compatible with trait + --> $DIR/regions-bound-missing-bound-in-impl.rs:37:5 + | +LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch + | + = note: expected type `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'d>)` + found type `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'d>)` +note: the lifetime 'c as defined on the method body at 37:24... + --> $DIR/regions-bound-missing-bound-in-impl.rs:37:24 + | +LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { + | ^^ note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 37:5 --> $DIR/regions-bound-missing-bound-in-impl.rs:37:5 | @@ -53,7 +72,7 @@ LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>); LL | fn another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'x: 't` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors Some errors occurred: E0195, E0276, E0308. For more information about an error, try `rustc --explain E0195`. diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr index b673111d21986..92464a2430169 100644 --- a/src/test/ui/impl-trait/region-escape-via-bound.stderr +++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr @@ -4,16 +4,11 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> | ^^^^^^^^^^^^^^ | -note: hidden type `std::cell::Cell<&'x u32>` captures the lifetime 'x as defined on the function body at 26:1 - --> $DIR/region-escape-via-bound.rs:26:1 +note: hidden type `std::cell::Cell<&'x u32>` captures the lifetime 'x as defined on the function body at 28:7 + --> $DIR/region-escape-via-bound.rs:28:7 | -LL | / fn foo(x: Cell<&'x u32>) -> impl Trait<'y> -LL | | //~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds [E0700] -LL | | where 'x: 'y -LL | | { -LL | | x -LL | | } - | |_^ +LL | where 'x: 'y + | ^^ error: aborting due to previous error diff --git a/src/test/ui/issue-46472.stderr b/src/test/ui/issue-46472.stderr index 9b55b78b43d57..9e5acf56d26ca 100644 --- a/src/test/ui/issue-46472.stderr +++ b/src/test/ui/issue-46472.stderr @@ -7,11 +7,11 @@ LL | &mut 4 LL | } | - temporary value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:1... - --> $DIR/issue-46472.rs:13:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:8... + --> $DIR/issue-46472.rs:13:8 | LL | fn bar<'a>() -> &'a mut u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: borrowed value does not live long enough (Mir) --> $DIR/issue-46472.rs:14:10 @@ -22,11 +22,11 @@ LL | &mut 4 LL | } | - temporary value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:1... - --> $DIR/issue-46472.rs:13:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:8... + --> $DIR/issue-46472.rs:13:8 | LL | fn bar<'a>() -> &'a mut u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/normalization-bounds-error.stderr b/src/test/ui/nll/normalization-bounds-error.stderr index 970384f9d56ff..3548219361fc7 100644 --- a/src/test/ui/nll/normalization-bounds-error.stderr +++ b/src/test/ui/nll/normalization-bounds-error.stderr @@ -4,16 +4,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'d` d LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime 'd as defined on the function body at 23:1... - --> $DIR/normalization-bounds-error.rs:23:1 +note: first, the lifetime cannot outlive the lifetime 'd as defined on the function body at 23:14... + --> $DIR/normalization-bounds-error.rs:23:14 | LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...but the lifetime must also be valid for the lifetime 'a as defined on the function body at 23:1... - --> $DIR/normalization-bounds-error.rs:23:1 + | ^^ +note: ...but the lifetime must also be valid for the lifetime 'a as defined on the function body at 23:18... + --> $DIR/normalization-bounds-error.rs:23:18 | LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ = note: ...so that the types are compatible: expected Visitor<'d> found Visitor<'_>