From cd8ca262570d856d354d4ea28632197ca8be15b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 27 Jun 2018 15:25:18 -0700 Subject: [PATCH 1/6] Point at lifetimes instead of def span for E0195 --- src/librustc/hir/map/mod.rs | 22 +++++++++++- src/librustc_typeck/check/compare_method.rs | 21 ++++++----- .../regions-bound-missing-bound-in-impl.rs | 5 +++ ...regions-bound-missing-bound-in-impl.stderr | 35 ++++++++++++------- src/test/ui/error-codes/E0195.stderr | 6 ++-- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index b7071970a04b9..33cae96dd07a2 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -25,7 +25,7 @@ use rustc_target::spec::abi::Abi; use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID}; use syntax::codemap::Spanned; use syntax::ext::base::MacroKind; -use syntax_pos::Span; +use syntax_pos::{Span, DUMMY_SP}; use hir::*; use hir::print::Nested; @@ -664,6 +664,26 @@ impl<'hir> Map<'hir> { self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` } + pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> { + self.get_if_local(id).and_then(|node| { + match node { + NodeImplItem(ref impl_item) => Some(&impl_item.generics), + NodeTraitItem(ref trait_item) => Some(&trait_item.generics), + NodeItem(ref item) => { + match item.node { + ItemFn(_, _, ref generics, _) => Some(generics), + _ => None, + } + } + _ => None, + } + }) + } + + pub fn get_generics_span(&self, id: DefId) -> Option { + self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP) + } + /// Retrieve the Node corresponding to `id`, returning None if /// cannot be found. pub fn find(&self, id: NodeId) -> Option> { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 04c11d30d2679..4c903b6fe5851 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -356,7 +356,6 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_generics: &ty::Generics, trait_to_skol_substs: &Substs<'tcx>) -> Result<(), ErrorReported> { - let span = tcx.sess.codemap().def_span(span); let trait_params = trait_generics.own_counts().lifetimes; let impl_params = impl_generics.own_counts().lifetimes; @@ -378,16 +377,20 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // are zero. Since I don't quite know how to phrase things at // the moment, give a kind of vague error message. if trait_params != impl_params { - let mut err = struct_span_err!(tcx.sess, - span, - E0195, - "lifetime parameters or bounds on method `{}` do not match \ - the trait declaration", - impl_m.ident); + let def_span = tcx.sess.codemap().def_span(span); + let span = tcx.hir.get_generics_span(impl_m.def_id).unwrap_or(def_span); + let mut err = struct_span_err!( + tcx.sess, + span, + E0195, + "lifetime parameters or bounds on method `{}` do not match the trait declaration", + impl_m.ident, + ); err.span_label(span, "lifetimes do not match method in trait"); if let Some(sp) = tcx.hir.span_if_local(trait_m.def_id) { - err.span_label(tcx.sess.codemap().def_span(sp), - "lifetimes in impl do not match this method in trait"); + let def_sp = tcx.sess.codemap().def_span(sp); + let sp = tcx.hir.get_generics_span(trait_m.def_id).unwrap_or(def_sp); + err.span_label(sp, "lifetimes in impl do not match this method in trait"); } err.emit(); return Err(ErrorReported); 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 617de2c5dfe84..04f90ea9ad3a2 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 @@ -20,6 +20,7 @@ pub trait Foo<'a, 't> { fn no_bound<'b>(self, b: Inv<'b>); fn has_bound<'b:'a>(self, b: Inv<'b>); fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); + fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); fn okay_bound<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>); } @@ -47,6 +48,10 @@ impl<'a, 't> Foo<'a, 't> for &'a isize { // cases. } + fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) { + //~^ ERROR lifetime parameters or bounds on method `wrong_bound2` do not match the trait + } + fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) { } 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 b58dbd1e4d1c9..b530fea1e5977 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 @@ -1,42 +1,51 @@ error[E0195]: lifetime parameters or bounds on method `no_bound` do not match the trait declaration - --> $DIR/regions-bound-missing-bound-in-impl.rs:28:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:29:16 | LL | fn no_bound<'b>(self, b: Inv<'b>); - | ---------------------------------- lifetimes in impl do not match this method in trait + | ---- lifetimes in impl do not match this method in trait ... LL | fn no_bound<'b:'a>(self, b: Inv<'b>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait + | ^^^^^^^ lifetimes do not match method in trait error[E0195]: lifetime parameters or bounds on method `has_bound` do not match the trait declaration - --> $DIR/regions-bound-missing-bound-in-impl.rs:32:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:33:17 | LL | fn has_bound<'b:'a>(self, b: Inv<'b>); - | -------------------------------------- lifetimes in impl do not match this method in trait + | ------- lifetimes in impl do not match this method in trait ... LL | fn has_bound<'b>(self, b: Inv<'b>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait + | ^^^^ lifetimes do not match method in trait error[E0308]: method not compatible with trait - --> $DIR/regions-bound-missing-bound-in-impl.rs:36: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>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 36:5... - --> $DIR/regions-bound-missing-bound-in-impl.rs:36:5 +note: 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>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 36:5 - --> $DIR/regions-bound-missing-bound-in-impl.rs:36:5 +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: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 +... +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:53: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 @@ -44,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 4 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/error-codes/E0195.stderr b/src/test/ui/error-codes/E0195.stderr index f2cf661830d8a..3860c93a45f49 100644 --- a/src/test/ui/error-codes/E0195.stderr +++ b/src/test/ui/error-codes/E0195.stderr @@ -1,11 +1,11 @@ error[E0195]: lifetime parameters or bounds on method `bar` do not match the trait declaration - --> $DIR/E0195.rs:19:5 + --> $DIR/E0195.rs:19:11 | LL | fn bar<'a,'b:'a>(x: &'a str, y: &'b str); - | ----------------------------------------- lifetimes in impl do not match this method in trait + | ---------- lifetimes in impl do not match this method in trait ... LL | fn bar<'a,'b>(x: &'a str, y: &'b str) { //~ ERROR E0195 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait + | ^^^^^^^ lifetimes do not match method in trait error: aborting due to previous error From 5436a5c55ac6b08bd0bb729b7da55915e6e78fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 27 Jun 2018 16:27:47 -0700 Subject: [PATCH 2/6] Point to lifetime in fn definition on lifetime error note --- src/librustc/infer/error_reporting/mod.rs | 19 ++++++++++++----- .../regions-bound-missing-bound-in-impl.rs | 1 + ...regions-bound-missing-bound-in-impl.stderr | 21 ++++++++++++++++++- .../impl-trait/region-escape-via-bound.stderr | 13 ++++-------- src/test/ui/issue-46472.stderr | 12 +++++------ .../ui/nll/normalization-bounds-error.stderr | 12 +++++------ 6 files changed, 51 insertions(+), 27 deletions(-) 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<'_> From 3005162f98c1b9a4d57f6a7b3d5c3fe55de01c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 27 Jun 2018 16:44:39 -0700 Subject: [PATCH 3/6] Extend support to `get_generics` for all `NodeItem`s --- src/librustc/hir/map/mod.rs | 9 +- ...ssociated-const-impl-wrong-lifetime.stderr | 6 +- ...regions-bound-missing-bound-in-impl.stderr | 4 +- src/test/ui/error-codes/E0478.stderr | 12 +-- src/test/ui/issue-27942.stderr | 12 +-- src/test/ui/issue-37884.stderr | 6 +- src/test/ui/nll/issue-47470.stderr | 6 +- .../ui/nll/trait-associated-constant.stderr | 24 ++--- ...borrow-params-issue-29793-small.nll.stderr | 96 +++++++++---------- src/test/ui/static-lifetime.stderr | 6 +- 10 files changed, 94 insertions(+), 87 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 33cae96dd07a2..dbf99cf30e56b 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -671,7 +671,14 @@ impl<'hir> Map<'hir> { NodeTraitItem(ref trait_item) => Some(&trait_item.generics), NodeItem(ref item) => { match item.node { - ItemFn(_, _, ref generics, _) => Some(generics), + ItemFn(_, _, ref generics, _) | + ItemTy(_, ref generics) | + ItemEnum(_, ref generics) | + ItemStruct(_, ref generics) | + ItemUnion(_, ref generics) | + ItemTrait(_, _, ref generics, ..) | + ItemTraitAlias(ref generics, _) | + ItemImpl(_, _, _, ref generics, ..) => Some(generics), _ => None, } } diff --git a/src/test/ui/associated-const-impl-wrong-lifetime.stderr b/src/test/ui/associated-const-impl-wrong-lifetime.stderr index d800f4c727d70..f8375899e3e01 100644 --- a/src/test/ui/associated-const-impl-wrong-lifetime.stderr +++ b/src/test/ui/associated-const-impl-wrong-lifetime.stderr @@ -6,11 +6,11 @@ LL | const NAME: &'a str = "unit"; | = note: expected type `&'static str` found type `&'a str` -note: the lifetime 'a as defined on the impl at 17:1... - --> $DIR/associated-const-impl-wrong-lifetime.rs:17:1 +note: the lifetime 'a as defined on the impl at 17:6... + --> $DIR/associated-const-impl-wrong-lifetime.rs:17:6 | LL | impl<'a> Foo for &'a () { - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ = note: ...does not necessarily outlive the static lifetime error: aborting due to previous error 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 deab39b99246c..86dad34586d68 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 @@ -55,7 +55,7 @@ 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:51:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:52: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 +64,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:58:5 + --> $DIR/regions-bound-missing-bound-in-impl.rs:59:5 | LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>); | ------------------------------------------------------- definition of `another_bound` from trait diff --git a/src/test/ui/error-codes/E0478.stderr b/src/test/ui/error-codes/E0478.stderr index 44d8151303f72..0e778908058e0 100644 --- a/src/test/ui/error-codes/E0478.stderr +++ b/src/test/ui/error-codes/E0478.stderr @@ -4,16 +4,16 @@ error[E0478]: lifetime bound not satisfied LL | child: Box + 'SnowWhite>, //~ ERROR E0478 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:1 - --> $DIR/E0478.rs:13:1 +note: lifetime parameter instantiated with the lifetime 'SnowWhite as defined on the struct at 13:22 + --> $DIR/E0478.rs:13:22 | LL | struct Prince<'kiss, 'SnowWhite> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:1 - --> $DIR/E0478.rs:13:1 + | ^^^^^^^^^^ +note: but lifetime parameter must outlive the lifetime 'kiss as defined on the struct at 13:15 + --> $DIR/E0478.rs:13:15 | LL | struct Prince<'kiss, 'SnowWhite> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issue-27942.stderr b/src/test/ui/issue-27942.stderr index 879eda0f85640..5e2ecbb05aebc 100644 --- a/src/test/ui/issue-27942.stderr +++ b/src/test/ui/issue-27942.stderr @@ -11,11 +11,11 @@ note: the anonymous lifetime #1 defined on the method body at 15:5... | LL | fn select(&self) -> BufferViewHandle; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:1 - --> $DIR/issue-27942.rs:13:1 +note: ...does not necessarily outlive the lifetime 'a as defined on the trait at 13:18 + --> $DIR/issue-27942.rs:13:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0308]: mismatched types --> $DIR/issue-27942.rs:15:5 @@ -25,11 +25,11 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected type `Resources<'_>` found type `Resources<'a>` -note: the lifetime 'a as defined on the trait at 13:1... - --> $DIR/issue-27942.rs:13:1 +note: the lifetime 'a as defined on the trait at 13:18... + --> $DIR/issue-27942.rs:13:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 15:5 --> $DIR/issue-27942.rs:15:5 | diff --git a/src/test/ui/issue-37884.stderr b/src/test/ui/issue-37884.stderr index 73fbb2d320388..f01b623aced42 100644 --- a/src/test/ui/issue-37884.stderr +++ b/src/test/ui/issue-37884.stderr @@ -21,11 +21,11 @@ LL | | { LL | | Some(&mut self.0) LL | | } | |_____^ -note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:1 - --> $DIR/issue-37884.rs:13:1 +note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:6 + --> $DIR/issue-37884.rs:13:6 | LL | impl<'a, T: 'a> Iterator for RepeatMut<'a, T> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-47470.stderr b/src/test/ui/nll/issue-47470.stderr index f84a68d85b95f..a89e186540a47 100644 --- a/src/test/ui/nll/issue-47470.stderr +++ b/src/test/ui/nll/issue-47470.stderr @@ -6,11 +6,11 @@ LL | &local //~ ERROR `local` does not live long enough LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:1... - --> $DIR/issue-47470.rs:23:1 +note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:6... + --> $DIR/issue-47470.rs:23:6 | LL | impl<'a> Bar for Foo<'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to previous error diff --git a/src/test/ui/nll/trait-associated-constant.stderr b/src/test/ui/nll/trait-associated-constant.stderr index 2c3fd091f9a0d..07972ecced313 100644 --- a/src/test/ui/nll/trait-associated-constant.stderr +++ b/src/test/ui/nll/trait-associated-constant.stderr @@ -6,16 +6,16 @@ LL | const AC: Option<&'c str> = None; | = note: expected type `std::option::Option<&'b str>` found type `std::option::Option<&'c str>` -note: the lifetime 'c as defined on the impl at 30:1... - --> $DIR/trait-associated-constant.rs:30:1 +note: the lifetime 'c as defined on the impl at 30:18... + --> $DIR/trait-associated-constant.rs:30:18 | LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:1 - --> $DIR/trait-associated-constant.rs:30:1 + | ^^ +note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:14 + --> $DIR/trait-associated-constant.rs:30:14 | LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0308]: mismatched types --> $DIR/trait-associated-constant.rs:38:5 @@ -25,16 +25,16 @@ LL | const AC: Option<&'a str> = None; | = note: expected type `std::option::Option<&'b str>` found type `std::option::Option<&'a str>` -note: the lifetime 'a as defined on the impl at 37:1... - --> $DIR/trait-associated-constant.rs:37:1 +note: the lifetime 'a as defined on the impl at 37:6... + --> $DIR/trait-associated-constant.rs:37:6 | LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:1 - --> $DIR/trait-associated-constant.rs:37:1 + | ^^ +note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:14 + --> $DIR/trait-associated-constant.rs:37:14 | LL | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/region-borrow-params-issue-29793-small.nll.stderr b/src/test/ui/region-borrow-params-issue-29793-small.nll.stderr index 1a53c033baa53..443af08e1cc7c 100644 --- a/src/test/ui/region-borrow-params-issue-29793-small.nll.stderr +++ b/src/test/ui/region-borrow-params-issue-29793-small.nll.stderr @@ -43,11 +43,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x LL | }; | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:5... - --> $DIR/region-borrow-params-issue-29793-small.rs:64:5 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:10... + --> $DIR/region-borrow-params-issue-29793-small.rs:64:10 | LL | fn g<'a>(x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:65:17 @@ -58,11 +58,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x LL | }; | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:5... - --> $DIR/region-borrow-params-issue-29793-small.rs:64:5 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:10... + --> $DIR/region-borrow-params-issue-29793-small.rs:64:10 | LL | fn g<'a>(x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:76:17 @@ -73,11 +73,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x LL | }; | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:5... - --> $DIR/region-borrow-params-issue-29793-small.rs:75:5 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:10... + --> $DIR/region-borrow-params-issue-29793-small.rs:75:10 | LL | fn g<'a>(x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:76:17 @@ -88,11 +88,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x LL | }; | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:5... - --> $DIR/region-borrow-params-issue-29793-small.rs:75:5 +note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:10... + --> $DIR/region-borrow-params-issue-29793-small.rs:75:10 | LL | fn g<'a>(x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:100:21 @@ -103,11 +103,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:99:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:99:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:100:21 @@ -118,11 +118,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:99:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:99:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:114:21 @@ -133,11 +133,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:113:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:113:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:114:21 @@ -148,11 +148,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:113:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:113:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:142:21 @@ -163,11 +163,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:141:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:141:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:142:21 @@ -178,11 +178,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:141:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:141:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:157:21 @@ -193,11 +193,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:156:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:156:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:157:21 @@ -208,11 +208,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:156:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:156:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:185:21 @@ -223,11 +223,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:184:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:184:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:185:21 @@ -238,11 +238,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:184:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:184:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `x` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:199:21 @@ -253,11 +253,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:198:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:198:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0597]: `y` does not live long enough --> $DIR/region-borrow-params-issue-29793-small.rs:199:21 @@ -268,11 +268,11 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors fo LL | } | - borrowed value only lives until here | -note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:9... - --> $DIR/region-borrow-params-issue-29793-small.rs:198:9 +note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:14... + --> $DIR/region-borrow-params-issue-29793-small.rs:198:14 | LL | fn g<'a>(&self, x: usize, y:usize) -> Box usize + 'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error: aborting due to 20 previous errors diff --git a/src/test/ui/static-lifetime.stderr b/src/test/ui/static-lifetime.stderr index 4fe4e569df954..c38b8a96f9fc2 100644 --- a/src/test/ui/static-lifetime.stderr +++ b/src/test/ui/static-lifetime.stderr @@ -4,11 +4,11 @@ error[E0478]: lifetime bound not satisfied LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} //~ ERROR lifetime bound | ^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime 'a as defined on the impl at 13:1 - --> $DIR/static-lifetime.rs:13:1 +note: lifetime parameter instantiated with the lifetime 'a as defined on the impl at 13:6 + --> $DIR/static-lifetime.rs:13:6 | LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} //~ ERROR lifetime bound - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ = note: but lifetime parameter must outlive the static lifetime error: aborting due to previous error 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 4/6] 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 | 29 ++++--------------- .../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, 45 insertions(+), 52 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c71d4e90ed389..51422f8f38b9c 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 2b5070977a39b..5448049a8017d 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 9ed07d1c8e92f..04f90ea9ad3a2 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 86dad34586d68..b139369014e44 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 - | -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 +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>) { | ^^ - -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... +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>) { | ^^ -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 8184616c97ff3..56b43bbd7d34c 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 07b86228f6118..3e54ebeb398d6 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 675ae1695b55f..f2c6155fd98f8 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 7f4273bc8c770..8eede34747827 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 467b02d207dd2..ea7d819938443 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 94d9bb36fa428..da287980e8c5f 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 579dc7eba8c85..065de6ea600b4 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 From 9a9b74737173945dfb616a9d9aa834f61a37f1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 28 Jun 2018 11:06:30 -0700 Subject: [PATCH 5/6] review comments: unify duplicated code --- src/librustc/hir/mod.rs | 11 ++++++++++- src/librustc/infer/error_reporting/mod.rs | 20 ++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 5416474721045..e16b6bd2b10ee 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -31,7 +31,7 @@ use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; use util::nodemap::{NodeMap, FxHashSet}; use mir::mono::Linkage; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::{Span, DUMMY_SP, symbol::InternedString}; use syntax::codemap::{self, Spanned}; use rustc_target::spec::abi::Abi; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect}; @@ -547,6 +547,15 @@ impl Generics { own_counts } + + pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> { + for param in &self.params { + if *name == param.name.name().as_interned_str() { + return Some(param); + } + } + None + } } /// Synthetic Type Parameters are converted to an other form during lowering, this allows diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 51422f8f38b9c..afc83771fe1c7 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -223,12 +223,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let (prefix, span) = match *region { 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; - } - } + if let Some(param) = self.hir.get_generics(scope).and_then(|generics| { + generics.get_named(&br.name) + }) { + sp = param.span; } (format!("the lifetime {} as defined on", br.name), sp) } @@ -236,12 +234,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { 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; - } - } + if let Some(param) = self.hir.get_generics(scope).and_then(|generics| { + generics.get_named(&name) + }) { + sp = param.span; } (format!("the lifetime {} as defined on", name), sp) } From 8449c5ab8a83cfa1f89c8f7810a42a54130c844d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 28 Jun 2018 11:14:31 -0700 Subject: [PATCH 6/6] Fix rebase --- src/librustc/hir/mod.rs | 2 +- .../ui/impl-trait/static-return-lifetime-infered.stderr | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e16b6bd2b10ee..d8bf5fe9b6ddf 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -550,7 +550,7 @@ impl Generics { pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> { for param in &self.params { - if *name == param.name.name().as_interned_str() { + if *name == param.name.ident().as_interned_str() { return Some(param); } } diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 2795bb92ed56f..083ad03ff8503 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -30,12 +30,12 @@ LL | self.x.iter().map(|a| a.0) | | | ...but this borrow... | -note: ...can't outlive the lifetime 'a as defined on the method body at 20:5 - --> $DIR/static-return-lifetime-infered.rs:20:5 +note: ...can't outlive the lifetime 'a as defined on the method body at 20:20 + --> $DIR/static-return-lifetime-infered.rs:20:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime 'a as defined on the method body at 20:5 + | ^^ +help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime 'a as defined on the method body at 20:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^