From 03bcebbc609cc02ae7f27937cd7ac2da4d6d6c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 27 Jun 2018 17:41:15 -0700 Subject: [PATCH] Also point to free named region on lifetime errors --- src/librustc/infer/error_reporting/mod.rs | 13 ++++++++ ...rrowck-escaping-closure-error-2.nll.stderr | 6 ++-- .../regions-bound-missing-bound-in-impl.rs | 1 - ...regions-bound-missing-bound-in-impl.stderr | 31 ++++--------------- .../expect-region-supply-region.stderr | 12 +++---- .../in-band-lifetimes/impl/dyn-trait.stderr | 6 ++-- .../mismatched_trait_impl.stderr | 6 ++-- src/test/ui/issue-4335.nll.stderr | 6 ++-- .../ui/nll/borrowed-universal-error-2.stderr | 6 ++-- .../ui/nll/borrowed-universal-error.stderr | 6 ++-- src/test/ui/nll/issue-31567.stderr | 6 ++-- 11 files changed, 46 insertions(+), 53 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c71d4e90ed3..51422f8f38b 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -232,6 +232,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } (format!("the lifetime {} as defined on", br.name), sp) } + ty::ReFree(ty::FreeRegion { + bound_region: ty::BoundRegion::BrNamed(_, ref name), .. + }) => { + 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() == name.as_str() { + sp = param.span; + } + } + } + (format!("the lifetime {} as defined on", name), sp) + } ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), diff --git a/src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr b/src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr index 2b5070977a3..5448049a801 100644 --- a/src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr +++ b/src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr @@ -7,11 +7,11 @@ LL | //~^ ERROR E0373 LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:1... - --> $DIR/borrowck-escaping-closure-error-2.rs:19:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:8... + --> $DIR/borrowck-escaping-closure-error-2.rs:19:8 | LL | fn foo<'a>(x: &'a i32) -> Box { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error 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 9ed07d1c8e9..04f90ea9ad3 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,7 +36,6 @@ 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 86dad34586d..b139369014e 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 @@ -24,38 +24,19 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d | = 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:5... - --> $DIR/regions-bound-missing-bound-in-impl.rs:37:5 +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: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 - | -LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration - --> $DIR/regions-bound-missing-bound-in-impl.rs:52:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:51:5 | LL | fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); | ---------------- lifetimes in impl do not match this method in trait @@ -64,7 +45,7 @@ LL | fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait error[E0276]: impl has stricter requirements than trait - --> $DIR/regions-bound-missing-bound-in-impl.rs:59:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:58:5 | LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>); | ------------------------------------------------------- definition of `another_bound` from trait @@ -72,7 +53,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 6 previous errors +error: aborting due to 5 previous errors Some errors occurred: E0195, E0276, E0308. For more information about an error, try `rustc --explain E0195`. diff --git a/src/test/ui/closure-expected-type/expect-region-supply-region.stderr b/src/test/ui/closure-expected-type/expect-region-supply-region.stderr index 8184616c97f..56b43bbd7d3 100644 --- a/src/test/ui/closure-expected-type/expect-region-supply-region.stderr +++ b/src/test/ui/closure-expected-type/expect-region-supply-region.stderr @@ -38,11 +38,11 @@ LL | | LL | | //~^ ERROR borrowed data cannot be stored outside of its closure LL | | }); | |_____^ -note: ...does not necessarily outlive the lifetime 'x as defined on the function body at 42:1 - --> $DIR/expect-region-supply-region.rs:42:1 +note: ...does not necessarily outlive the lifetime 'x as defined on the function body at 42:30 + --> $DIR/expect-region-supply-region.rs:42:30 | LL | fn expect_bound_supply_named<'x>() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0308]: mismatched types --> $DIR/expect-region-supply-region.rs:47:33 @@ -52,11 +52,11 @@ LL | closure_expecting_bound(|x: &'x u32| { | = note: expected type `&u32` found type `&'x u32` -note: the lifetime 'x as defined on the function body at 42:1... - --> $DIR/expect-region-supply-region.rs:42:1 +note: the lifetime 'x as defined on the function body at 42:30... + --> $DIR/expect-region-supply-region.rs:42:30 | LL | fn expect_bound_supply_named<'x>() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 47:29 --> $DIR/expect-region-supply-region.rs:47:29 | diff --git a/src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr b/src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr index 07b86228f61..3e54ebeb398 100644 --- a/src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr +++ b/src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | static_val(x); //~ ERROR cannot infer | ^ | -note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:1... - --> $DIR/dyn-trait.rs:31:1 +note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:26... + --> $DIR/dyn-trait.rs:31:26 | LL | fn with_dyn_debug_static<'a>(x: Box) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ = note: ...so that the expression is assignable: expected std::boxed::Box found std::boxed::Box<(dyn std::fmt::Debug + 'a)> diff --git a/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr index 675ae1695b5..f2c6155fd98 100644 --- a/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr +++ b/src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr @@ -11,11 +11,11 @@ LL | / fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR cannot infe LL | | x LL | | } | |_____^ -note: ...but the lifetime must also be valid for the lifetime 'a as defined on the method body at 19:5... - --> $DIR/mismatched_trait_impl.rs:19:5 +note: ...but the lifetime must also be valid for the lifetime 'a as defined on the method body at 19:32... + --> $DIR/mismatched_trait_impl.rs:19:32 | LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR cannot infer - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ = note: ...so that the method type is compatible with trait: expected fn(&i32, &'a u32, &u32) -> &'a u32 found fn(&i32, &u32, &u32) -> &u32 diff --git a/src/test/ui/issue-4335.nll.stderr b/src/test/ui/issue-4335.nll.stderr index 7f4273bc8c7..8eede347478 100644 --- a/src/test/ui/issue-4335.nll.stderr +++ b/src/test/ui/issue-4335.nll.stderr @@ -13,11 +13,11 @@ LL | id(Box::new(|| *v)) LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:1... - --> $DIR/issue-4335.rs:15:1 +note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:6... + --> $DIR/issue-4335.rs:15:6 | LL | fn f<'r, T>(v: &'r T) -> Box T + 'r> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/borrowed-universal-error-2.stderr b/src/test/ui/nll/borrowed-universal-error-2.stderr index 467b02d207d..ea7d8199384 100644 --- a/src/test/ui/nll/borrowed-universal-error-2.stderr +++ b/src/test/ui/nll/borrowed-universal-error-2.stderr @@ -7,11 +7,11 @@ LL | //~^ ERROR `v` does not live long enough [E0597] LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:1... - --> $DIR/borrowed-universal-error-2.rs:14:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8... + --> $DIR/borrowed-universal-error-2.rs:14:8 | LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error diff --git a/src/test/ui/nll/borrowed-universal-error.stderr b/src/test/ui/nll/borrowed-universal-error.stderr index 94d9bb36fa4..da287980e8c 100644 --- a/src/test/ui/nll/borrowed-universal-error.stderr +++ b/src/test/ui/nll/borrowed-universal-error.stderr @@ -7,11 +7,11 @@ LL | //~^ ERROR borrowed value does not live long enough [E0597] LL | } | - temporary value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:1... - --> $DIR/borrowed-universal-error.rs:18:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:8... + --> $DIR/borrowed-universal-error.rs:18:8 | LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-31567.stderr b/src/test/ui/nll/issue-31567.stderr index 579dc7eba8c..065de6ea600 100644 --- a/src/test/ui/nll/issue-31567.stderr +++ b/src/test/ui/nll/issue-31567.stderr @@ -7,11 +7,11 @@ LL | &s_inner.0 LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:1... - --> $DIR/issue-31567.rs:21:1 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:17... + --> $DIR/issue-31567.rs:21:17 | LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error