diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 5fd9ecf451366..fd78b483b75f2 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -4,6 +4,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed use rustc_infer::infer::{ error_reporting::nice_region_error::NiceRegionError, error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin, + RelateParamBound, }; use rustc_middle::hir::place::PlaceBase; use rustc_middle::mir::{ConstraintCategory, ReturnConstraint}; @@ -166,11 +167,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let type_test_span = type_test.locations.span(&self.body); if let Some(lower_bound_region) = lower_bound_region { + let generic_ty = type_test.generic_kind.to_ty(self.infcx.tcx); + let origin = RelateParamBound(type_test_span, generic_ty, None); self.buffer_error(self.infcx.construct_generic_bound_failure( type_test_span, - None, + Some(origin), type_test.generic_kind, lower_bound_region, + self.body.source.def_id().as_local(), )); } else { // FIXME. We should handle this case better. It diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index f2dd4f5d5cbca..f9273cc50b70a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -61,7 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan}; use rustc_hir as hir; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::{Item, ItemKind, Node}; use rustc_middle::dep_graph::DepContext; @@ -2285,7 +2285,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, ) { - self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit(); + let owner = + self.in_progress_typeck_results.map(|typeck_results| typeck_results.borrow().hir_owner); + self.construct_generic_bound_failure(span, origin, bound_kind, sub, owner).emit(); } pub fn construct_generic_bound_failure( @@ -2294,31 +2296,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { origin: Option>, bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, + owner: Option, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let hir = self.tcx.hir(); // Attempt to obtain the span of the parameter so we can // suggest adding an explicit lifetime bound to it. - let generics = self - .in_progress_typeck_results - .map(|typeck_results| typeck_results.borrow().hir_owner) - .map(|owner| { - let hir_id = hir.local_def_id_to_hir_id(owner); - let parent_id = hir.get_parent_item(hir_id); - ( - // Parent item could be a `mod`, so we check the HIR before calling: - if let Some(Node::Item(Item { - kind: ItemKind::Trait(..) | ItemKind::Impl { .. }, - .. - })) = hir.find_by_def_id(parent_id) - { - Some(self.tcx.generics_of(parent_id)) - } else { - None - }, - self.tcx.generics_of(owner.to_def_id()), - hir.span(hir_id), - ) - }); + let generics = owner.map(|owner| { + let hir_id = hir.local_def_id_to_hir_id(owner); + let parent_id = hir.get_parent_item(hir_id); + ( + // Parent item could be a `mod`, so we check the HIR before calling: + if let Some(Node::Item(Item { + kind: ItemKind::Trait(..) | ItemKind::Impl { .. }, + .. + })) = hir.find_by_def_id(parent_id) + { + Some(self.tcx.generics_of(parent_id)) + } else { + None + }, + self.tcx.generics_of(owner.to_def_id()), + hir.span(hir_id), + ) + }); let span = match generics { // This is to get around the trait identity obligation, that has a `DUMMY_SP` as signal @@ -2606,11 +2606,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { None, ); if let Some(infer::RelateParamBound(_, t, _)) = origin { - let return_impl_trait = self - .in_progress_typeck_results - .map(|typeck_results| typeck_results.borrow().hir_owner) - .and_then(|owner| self.tcx.return_type_impl_trait(owner)) - .is_some(); + let return_impl_trait = + owner.and_then(|owner| self.tcx.return_type_impl_trait(owner)).is_some(); let t = self.resolve_vars_if_possible(t); match t.kind() { // We've got: diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index 9589b69491e25..0059f729bae2f 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -82,10 +82,11 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32 error[E0310]: the parameter type `T` may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:41:5 | +LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { + | -- help: consider adding an explicit lifetime bound...: `T: 'static +` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 9 previous errors diff --git a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr index b1175a5952e59..5328b077993c5 100644 --- a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr +++ b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr @@ -1,10 +1,11 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/type_parameters_captured.rs:10:5 | +LL | fn foo(x: T) -> impl Any + 'static { + | - help: consider adding an explicit lifetime bound...: `T: 'static` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/lifetimes/lifetime-errors/issue_74400.nll.stderr b/src/test/ui/lifetimes/lifetime-errors/issue_74400.nll.stderr index 5509226cb1cdd..422673b361a95 100644 --- a/src/test/ui/lifetimes/lifetime-errors/issue_74400.nll.stderr +++ b/src/test/ui/lifetimes/lifetime-errors/issue_74400.nll.stderr @@ -1,10 +1,10 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/issue_74400.rs:12:5 | +LL | fn g(data: &[T]) { + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | f(data, identity) - | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0308]: mismatched types --> $DIR/issue_74400.rs:12:5 diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index 4b860a55057b6..b6856089a84f9 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -36,6 +36,9 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/propagate-from-trait-match.rs:32:36 | +LL | fn supply<'a, T>(value: T) + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | establish_relationships(value, |value| { | ____________________________________^ LL | | @@ -44,9 +47,7 @@ LL | | // This function call requires that ... | LL | | require(value); LL | | }); - | |_____^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | |_____^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr index 31ee540cce9f7..3d4cfc1610a66 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr @@ -1,18 +1,20 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:11:5 | +LL | fn no_region<'a, T>(x: Box) -> impl Debug + 'a + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:26:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> impl Debug + 'a + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr index 9f0c60c1e1705..cc5aa1eb11ec0 100644 --- a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr +++ b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr @@ -1,10 +1,10 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/projection-implied-bounds.rs:30:18 | +LL | fn generic2(value: T) { + | -- help: consider adding an explicit lifetime bound...: `T: 'static +` LL | twice(value, |value_ref, item| invoke2(value_ref, item)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr index 983d6a06afada..8fe25181da1a0 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr @@ -33,6 +33,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds note: external requirements --> $DIR/projection-no-regions-closure.rs:34:23 @@ -96,6 +97,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds note: external requirements --> $DIR/projection-no-regions-closure.rs:52:23 diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr index c4df04b99b525..e0ff544fe4713 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr @@ -5,6 +5,7 @@ LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error[E0309]: the associated type `::Item` may not live long enough --> $DIR/projection-no-regions-fn.rs:28:5 @@ -13,6 +14,7 @@ LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index 2513b0bfccbf1..62db6dd845a28 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -31,10 +31,11 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:45:29 | +LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T) + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | with_signature(cell, t, |cell, t| require(cell, t)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: lifetime may not live long enough --> $DIR/projection-one-region-closure.rs:45:39 @@ -81,10 +82,11 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:56:29 | +LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T) + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | with_signature(cell, t, |cell, t| require(cell, t)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: lifetime may not live long enough --> $DIR/projection-one-region-closure.rs:56:39 diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index 4e0155bdf2cd0..1ee788b40ab9e 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -34,6 +34,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `>::AssocType: 'a`... + = note: ...so that the type `>::AssocType` will meet its required lifetime bounds note: external requirements --> $DIR/projection-two-region-trait-bound-closure.rs:48:29 @@ -70,6 +71,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `>::AssocType: 'a`... + = note: ...so that the type `>::AssocType` will meet its required lifetime bounds note: external requirements --> $DIR/projection-two-region-trait-bound-closure.rs:61:29 diff --git a/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-bound.nll.stderr b/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-bound.nll.stderr index 3a84cbfbedc09..b4435fe06bccc 100644 --- a/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-bound.nll.stderr +++ b/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-bound.nll.stderr @@ -5,6 +5,7 @@ LL | bar::() | ^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `>::Output: 'a`... + = note: ...so that the type `>::Output` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.nll.stderr b/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.nll.stderr index 58bfb600452e0..ddeaf3c1f9e8c 100644 --- a/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.nll.stderr +++ b/src/test/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.nll.stderr @@ -5,6 +5,7 @@ LL | bar::<>::Output>() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `>::Output: 'a`... + = note: ...so that the type `>::Output` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-where-clause-none.stderr b/src/test/ui/nll/ty-outlives/projection-where-clause-none.stderr index 8175c302155a5..c51edb7868d7a 100644 --- a/src/test/ui/nll/ty-outlives/projection-where-clause-none.stderr +++ b/src/test/ui/nll/ty-outlives/projection-where-clause-none.stderr @@ -1,10 +1,11 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-where-clause-none.rs:16:5 | +LL | fn foo<'a, T>() -> &'a () + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | bar::() - | ^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index baf223b786b08..3e5e4868341ed 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -52,10 +52,10 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-approximate-lower-bound.rs:29:24 | +LL | fn generic_fail<'a, T>(cell: Cell<&'a ()>, value: T) { + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | twice(cell, value, |a, b| invoke(a, b)); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index 88d73e7a729a9..dc2f23b4fc8a3 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -29,18 +29,20 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:26:23 | +LL | fn no_region<'a, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | with_signature(x, |y| y) - | ^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:41:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 5b175aac1e1cb..e9f728c77b34b 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -37,6 +37,8 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-where-clause.rs:27:26 | +LL | fn no_region<'a, T>(a: Cell<&'a ()>, b: T) { + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | with_signature(a, b, |x, y| { | __________________________^ LL | | @@ -45,9 +47,7 @@ LL | | // See `correct_region`, which explains the point of this ... | LL | | require(&x, &y) LL | | }) - | |_____^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | |_____^ ...so that the type `T` will meet its required lifetime bounds note: external requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26 @@ -121,15 +121,16 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-where-clause.rs:64:26 | +LL | fn wrong_region<'a, 'b, T>(a: Cell<&'a ()>, b: T) + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | with_signature(a, b, |x, y| { | __________________________^ LL | | LL | | // See `correct_region` LL | | require(&x, &y) LL | | }) - | |_____^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | |_____^ ...so that the type `T` will meet its required lifetime bounds note: external requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:77:26 diff --git a/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr b/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr index 9a023a0e58e5f..a2e6a5d57cd62 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr @@ -1,10 +1,10 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn-body.rs:19:5 | +LL | fn region_static<'a, T>(cell: Cell<&'a usize>, t: T) { + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | outlives(cell, t) - | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-fn.stderr b/src/test/ui/nll/ty-outlives/ty-param-fn.stderr index 8c8529620d57f..fce360dd54bfb 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-fn.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-fn.stderr @@ -1,18 +1,20 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn.rs:11:5 | +LL | fn no_region<'a, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn.rs:26:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | x - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/regions-close-associated-type-into-object.nll.stderr b/src/test/ui/regions/regions-close-associated-type-into-object.nll.stderr index 92c4956da02d2..f7dcaa9d97e7c 100644 --- a/src/test/ui/regions/regions-close-associated-type-into-object.nll.stderr +++ b/src/test/ui/regions/regions-close-associated-type-into-object.nll.stderr @@ -5,6 +5,7 @@ LL | Box::new(item) | ^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'static`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error[E0310]: the associated type `::Item` may not live long enough --> $DIR/regions-close-associated-type-into-object.rs:22:5 @@ -13,6 +14,7 @@ LL | Box::new(item) | ^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'static`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error[E0309]: the associated type `::Item` may not live long enough --> $DIR/regions-close-associated-type-into-object.rs:28:5 @@ -21,6 +23,7 @@ LL | Box::new(item) | ^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error[E0309]: the associated type `::Item` may not live long enough --> $DIR/regions-close-associated-type-into-object.rs:35:5 @@ -29,6 +32,7 @@ LL | Box::new(item) | ^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `::Item: 'a`... + = note: ...so that the type `::Item` will meet its required lifetime bounds error: aborting due to 4 previous errors diff --git a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr index b30626830ad6b..6a2429e51ecda 100644 --- a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr @@ -1,26 +1,26 @@ error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:9:5 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | Box::new(B(&*v)) as Box - | ^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... + | ^^^^^^^^ ...so that the type `U` will meet its required lifetime bounds error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:9:5 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | Box::new(B(&*v)) as Box - | ^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... + | ^^^^^^^^^^^^^^^^ ...so that the type `U` will meet its required lifetime bounds error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:9:5 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | Box::new(B(&*v)) as Box - | ^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... + | ^^^^^^^^^^^^^^^^ ...so that the type `U` will meet its required lifetime bounds error: lifetime may not live long enough --> $DIR/regions-close-object-into-object-4.rs:9:5 @@ -42,10 +42,10 @@ LL | Box::new(B(&*v)) as Box error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:9:14 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | Box::new(B(&*v)) as Box - | ^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... + | ^^^^^^ ...so that the type `U` will meet its required lifetime bounds error: aborting due to 6 previous errors diff --git a/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr index 7486e73e66ab3..54302cc6dca22 100644 --- a/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr @@ -1,26 +1,29 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:5 | +LL | fn f<'a, T, U>(v: Box + 'static>) -> Box { + | - help: consider adding an explicit lifetime bound...: `T: 'static` +LL | // oh dear! LL | Box::new(B(&*v)) as Box - | ^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:5 | +LL | fn f<'a, T, U>(v: Box + 'static>) -> Box { + | - help: consider adding an explicit lifetime bound...: `T: 'static` +LL | // oh dear! LL | Box::new(B(&*v)) as Box - | ^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:5 | +LL | fn f<'a, T, U>(v: Box + 'static>) -> Box { + | - help: consider adding an explicit lifetime bound...: `T: 'static` +LL | // oh dear! LL | Box::new(B(&*v)) as Box - | ^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0515]: cannot return value referencing local data `*v` --> $DIR/regions-close-object-into-object-5.rs:17:5 @@ -34,10 +37,11 @@ LL | Box::new(B(&*v)) as Box error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:14 | +LL | fn f<'a, T, U>(v: Box + 'static>) -> Box { + | - help: consider adding an explicit lifetime bound...: `T: 'static` +LL | // oh dear! LL | Box::new(B(&*v)) as Box - | ^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 5 previous errors diff --git a/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr b/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr index b576ae8701137..063c3b19a19cc 100644 --- a/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr +++ b/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr @@ -1,18 +1,18 @@ error[E0310]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:12:5 | +LL | fn make_object1(v: A) -> Box { + | -- help: consider adding an explicit lifetime bound...: `A: 'static +` LL | Box::new(v) as Box - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'static`... + | ^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:21:5 | +LL | fn make_object3<'a, 'b, A: SomeTrait + 'a>(v: A) -> Box { + | -- help: consider adding an explicit lifetime bound...: `A: 'b +` LL | Box::new(v) as Box - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'b`... + | ^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/regions-close-param-into-object.nll.stderr b/src/test/ui/regions/regions-close-param-into-object.nll.stderr index 7bd7824f00a46..f0464e299bbec 100644 --- a/src/test/ui/regions/regions-close-param-into-object.nll.stderr +++ b/src/test/ui/regions/regions-close-param-into-object.nll.stderr @@ -1,34 +1,38 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:6:5 | +LL | fn p1(v: T) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'static` +... LL | Box::new(v) - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:12:5 | +LL | fn p2(v: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'static` +... LL | Box::new(v) - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:18:5 | +LL | fn p3<'a,T>(v: T) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | Box::new(v) - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:24:5 | +LL | fn p4<'a,T>(v: Box) -> Box + | - help: consider adding an explicit lifetime bound...: `T: 'a` +... LL | Box::new(v) - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... + | ^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 4 previous errors diff --git a/src/test/ui/regions/regions-implied-bounds-projection-gap-1.nll.stderr b/src/test/ui/regions/regions-implied-bounds-projection-gap-1.nll.stderr index 0f0f86dfcdd69..0e1db8acf1fae 100644 --- a/src/test/ui/regions/regions-implied-bounds-projection-gap-1.nll.stderr +++ b/src/test/ui/regions/regions-implied-bounds-projection-gap-1.nll.stderr @@ -1,10 +1,11 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-implied-bounds-projection-gap-1.rs:16:5 | +LL | fn func<'x, T:Trait1<'x>>(t: &'x T::Foo) + | -- help: consider adding an explicit lifetime bound...: `T: 'x +` +LL | { LL | wf::<&'x T>(); - | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'x`... + | ^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-bound-from-trait-self.nll.stderr b/src/test/ui/regions/regions-infer-bound-from-trait-self.nll.stderr index 0651e305cde35..e88f79a3a8c54 100644 --- a/src/test/ui/regions/regions-infer-bound-from-trait-self.nll.stderr +++ b/src/test/ui/regions/regions-infer-bound-from-trait-self.nll.stderr @@ -5,6 +5,7 @@ LL | check_bound(x, self) | ^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `Self: 'a`... + = note: ...so that the type `Self` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr b/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr index 1f7b34fc69962..fe07749954404 100644 --- a/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr +++ b/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr @@ -1,18 +1,18 @@ error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:33:5 | +LL | fn bar1<'a,A>(x: Inv<'a>, a: A) { + | - help: consider adding an explicit lifetime bound...: `A: 'a` LL | check_bound(x, a) - | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'a`... + | ^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:37:5 | +LL | fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) { + | -- help: consider adding an explicit lifetime bound...: `A: 'a +` LL | check_bound(x, a) - | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'a`... + | ^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr index 536494c73445c..d38d66c08853c 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr @@ -1,6 +1,8 @@ error[E0311]: the parameter type `T` may not live long enough --> $DIR/missing-lifetimes-in-signature-2.rs:20:5 | +LL | fn func(foo: &Foo, t: T) { + | -- help: consider adding an explicit lifetime bound...: `T: 'a +` LL | / foo.bar(move |_| { LL | | LL | | t.test(); @@ -12,6 +14,14 @@ note: the parameter type `T` must be valid for the anonymous lifetime defined he | LL | fn func(foo: &Foo, t: T) { | ^^^ +note: ...so that the type `T` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature-2.rs:20:5 + | +LL | / foo.bar(move |_| { +LL | | +LL | | t.test(); +LL | | }); + | |______^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr index 0ae629676fec7..4a18e0a4f8bbd 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr @@ -26,6 +26,9 @@ LL | fn foo(g: G, dest: &mut T) -> impl FnOnce() + '_ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:32:5 | +LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ + | - help: consider adding an explicit lifetime bound...: `G: 'a` +... LL | / move || { LL | | *dest = g.get(); LL | | } @@ -36,10 +39,20 @@ note: the parameter type `G` must be valid for the anonymous lifetime defined he | LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^ +note: ...so that the type `G` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:32:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:55:5 | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | -- help: consider adding an explicit lifetime bound...: `G: 'b +` +... LL | / move || { LL | | *dest = g.get(); LL | | } @@ -50,10 +63,20 @@ note: the parameter type `G` must be valid for the anonymous lifetime defined he | LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^ +note: ...so that the type `G` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:55:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:65:9 | +LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | -- help: consider adding an explicit lifetime bound...: `G: 'c +` +... LL | / move || { LL | | *dest = g.get(); LL | | } @@ -64,10 +87,20 @@ note: the parameter type `G` must be valid for the anonymous lifetime defined he | LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { | ^^^^^^ +note: ...so that the type `G` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:65:9 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_________^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:77:5 | +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | -- help: consider adding an explicit lifetime bound...: `G: 'b +` +... LL | / move || { LL | | *dest = g.get(); LL | | } @@ -78,6 +111,13 @@ note: the parameter type `G` must be valid for the anonymous lifetime defined he | LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a | ^^^^^^ +note: ...so that the type `G` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:77:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ error[E0621]: explicit lifetime required in the type of `dest` --> $DIR/missing-lifetimes-in-signature.rs:77:5 @@ -93,12 +133,13 @@ LL | | } error[E0309]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:89:5 | +LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a + | - help: consider adding an explicit lifetime bound...: `G: 'a` +... LL | / move || { LL | | *dest = g.get(); LL | | } - | |_____^ - | - = help: consider adding an explicit lifetime bound `G: 'a`... + | |_____^ ...so that the type `G` will meet its required lifetime bounds error: aborting due to 8 previous errors diff --git a/src/test/ui/suggestions/suggest-impl-trait-lifetime.nll.stderr b/src/test/ui/suggestions/suggest-impl-trait-lifetime.nll.stderr index f4eb9813c1ac7..72354eaaee147 100644 --- a/src/test/ui/suggestions/suggest-impl-trait-lifetime.nll.stderr +++ b/src/test/ui/suggestions/suggest-impl-trait-lifetime.nll.stderr @@ -1,10 +1,11 @@ error[E0310]: the parameter type `impl Debug` may not live long enough --> $DIR/suggest-impl-trait-lifetime.rs:7:5 | +LL | fn foo(d: impl Debug) { + | ---------- help: consider adding an explicit lifetime bound...: `impl Debug + 'static` +LL | LL | bar(d); - | ^^^^^^ - | - = help: consider adding an explicit lifetime bound `impl Debug: 'static`... + | ^^^^^^ ...so that the type `impl Debug` will meet its required lifetime bounds error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr index db771d211322c..a3b410c2cfb8c 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr @@ -19,10 +19,10 @@ LL | type WrongGeneric = impl 'static; error[E0310]: the parameter type `T` may not live long enough --> $DIR/generic_type_does_not_live_long_enough.rs:18:5 | +LL | fn wrong_generic(t: T) -> WrongGeneric { + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | t - | ^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... + | ^ ...so that the type `T` will meet its required lifetime bounds error: aborting due to 3 previous errors