diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 1ef2b0ae98843..aca12707833ad 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -56,6 +56,8 @@ impl<'tcx> UniverseInfo<'tcx> { ) { match self.0 { UniverseInfoInner::RelateTys { expected, found } => { + let (expected, found) = + mbcx.regioncx.name_regions(mbcx.infcx.tcx, (expected, found)); let err = mbcx.infcx.report_mismatched_types( &cause, expected, diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 72aee0267ac1e..44cd594b964ab 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -21,7 +21,7 @@ use crate::{ WriteKind, }; -use super::{find_use, RegionName, UseSpans}; +use super::{find_use, region_errors, RegionName, UseSpans}; #[derive(Debug)] pub(crate) enum BorrowExplanation<'tcx> { @@ -268,6 +268,10 @@ impl<'tcx> BorrowExplanation<'tcx> { ); }; + if let ConstraintCategory::TypeAnnotation = category { + err.span_help(span, "you can remove unnecessary lifetime annotations here"); + region_errors::suggest_relax_self(tcx, err, body.source.def_id(), span); + } self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name); } _ => {} diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index bd3a2a3d69496..3f45e23efba37 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan}; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, Item, ItemKind, Node}; @@ -18,7 +19,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint}; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::Region; use rustc_middle::ty::TypeVisitor; -use rustc_middle::ty::{self, RegionVid, Ty}; +use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty, TyCtxt}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; @@ -208,9 +209,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, key, member_region } => { - let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty); - let named_key = self.regioncx.name_regions(self.infcx.tcx, key); - let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region); + let named_ty = self.regioncx.name_regions_opaque(self.infcx.tcx, hidden_ty); + let named_key = self.regioncx.name_regions_opaque(self.infcx.tcx, key); + let named_region = + self.regioncx.name_regions_opaque(self.infcx.tcx, member_region); self.buffer_error(unexpected_hidden_region_diagnostic( self.infcx.tcx, span, @@ -714,12 +716,53 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } + if let ConstraintCategory::TypeAnnotation = category { + self.handle_annotation_error(errci, &mut diag); + } self.add_static_impl_trait_suggestion(&mut diag, *fr, fr_name, *outlived_fr); self.suggest_adding_lifetime_params(&mut diag, *fr, *outlived_fr); diag } + /// Adds a secondary label to lifetime annotation errors: + /// ``` + /// fn test<'a, 'b>(s: &'a str) { + /// let closure = |_: &'b str| {}; // Primary label: type annotation requires 'a: 'b. + /// closure(s); // Secondary label: because of this call. + /// } + /// ``` + /// + /// Also Suggests replacing `Self`. See `suggest_relax_self`. + fn handle_annotation_error(&self, errci: &ErrorConstraintInfo<'tcx>, err: &mut Diagnostic) { + let ErrorConstraintInfo { fr, outlived_fr, span, category: _, .. } = errci.clone(); + + // Try to report the second most relevant constraint to provide more context. + let constraint2 = self.regioncx.best_blame_constraint_filtered( + &self.body, + fr, + NllRegionVariableOrigin::FreeRegion, + |r| self.regioncx.provides_universal_region(r, fr, outlived_fr), + |constraint| match constraint.category { + ConstraintCategory::TypeAnnotation => false, + _ => true, + }, + ); + debug!("suggest_relax_annotation: constraint2={:?}", constraint2); + let map = self.infcx.tcx.sess.source_map(); + let same_line = map + .lookup_line(constraint2.cause.span.hi()) + .and_then(|line1| map.lookup_line(span.hi()).map(|line2| line1.line == line2.line)) + .unwrap_or(false); + let desc = constraint2.category.description(); + if !desc.is_empty() && !same_line { + err.span_label(constraint2.cause.span, format!("because of {desc}here")); + } + + let body_did = self.body.source.def_id(); + suggest_relax_self(self.infcx.tcx, err, body_did, span); + } + /// Adds a suggestion to errors where an `impl Trait` is returned. /// /// ```text @@ -902,3 +945,46 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag); } } + +/// Use of `Self` can impose unnecessary region constraints: +/// ``` +/// struct MyStruct<'a>(&'a str); +/// impl<'a> MyStruct<'a> { +/// fn test<'x>(s: &'x str) { +/// let _ = Self(s); // requires 'x: 'a. +/// } +/// } +/// ``` +/// Here we suggest replacing `Self` with `MyStruct<'_>`. +/// Assumes that `span` points to hir::Path that may name `Self`. +pub(crate) fn suggest_relax_self<'tcx>( + tcx: TyCtxt<'tcx>, + err: &mut Diagnostic, + body_did: DefId, + span: Span, +) { + use rustc_lexer as lex; + fn tokenize(mut input: &str) -> impl Iterator { + std::iter::from_fn(move || { + if input.is_empty() { + return None; + } + let token = lex::first_token(input); + let token_str = &input[..(token.len as usize)]; + input = &input[(token.len as usize)..]; + Some((token.kind, token_str)) + }) + } + + let snippet = tcx.sess.source_map().span_to_snippet(span).unwrap_or_default(); + let has_self = tokenize(&snippet) + .find(|(tok, s)| *tok == lex::TokenKind::Ident && *s == "Self") + .and_then(|_| tcx.opt_parent(tcx.typeck_root_def_id(body_did))) + .filter(|parent_did| tcx.def_kind(parent_did) == DefKind::Impl); + + if let Some(impl_did) = has_self { + let suggested_ty = + tcx.fold_regions(tcx.type_of(impl_did), |_, _| tcx.mk_region(ty::ReErased)); + err.help(format!("consider replacing `Self` with `{suggested_ty}`")); + } +} diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index a87e8bd5ba16f..80f7560f87cb5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -867,7 +867,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { }; let tcx = self.infcx.tcx; - let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?; + let typeck_root_did = tcx.typeck_root_def_id(self.mir_def_id().to_def_id()); + let body_parent_did = tcx.opt_parent(typeck_root_did)?; if tcx.parent(region.def_id) != body_parent_did || tcx.def_kind(body_parent_did) != DefKind::Impl { diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 2894c6d29ec43..d62581f525851 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1875,6 +1875,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// `results`. The paths are stored as a series of /// `ConstraintIndex` values -- in other words, a list of *edges*. /// + /// We have a special handling for `TypeAnnotation` constraints in that we don't report a path + /// with such constraint unless we're sure that no other path exists. + /// This enables us to say that a lifetime annotation is unnecessarily restrictive if it + /// appears in the constraint path, and thus we can safely suggest removing it. + /// /// Returns: a series of constraints as well as the region `R` /// that passed the target test. pub(crate) fn find_constraint_paths_between_regions( @@ -1888,10 +1893,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Use a deque so that we do a breadth-first search. We will // stop at the first match, which ought to be the shortest // path (fewest constraints). - let mut deque = VecDeque::new(); - deque.push_back(from_region); + let mut deque_p0 = VecDeque::new(); // Higher priority queue. + let mut deque_p1 = VecDeque::new(); // Lower priority queue. See method docs. + deque_p0.push_back(from_region); - while let Some(r) = deque.pop_front() { + while let Some(r) = deque_p0.pop_front().or_else(|| deque_p1.pop_front()) { debug!( "find_constraint_paths_between_regions: from_region={:?} r={:?} value={}", from_region, @@ -1939,8 +1945,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug_assert_eq!(constraint.sup, r); let sub_region = constraint.sub; if let Trace::NotVisited = context[sub_region] { + let constraint_category = constraint.category; context[sub_region] = Trace::FromOutlivesConstraint(constraint); - deque.push_back(sub_region); + match constraint_category { + ConstraintCategory::TypeAnnotation => deque_p1.push_back(sub_region), + // FIXME A `ClosureBounds` constraint can be mapped to `TypeAnnotation` + // later. It should be treated as such here but we're ingoring that. + _ => deque_p0.push_back(sub_region), + } } }; @@ -2054,6 +2066,25 @@ impl<'tcx> RegionInferenceContext<'tcx> { from_region: RegionVid, from_region_origin: NllRegionVariableOrigin, target_test: impl Fn(RegionVid) -> bool, + ) -> BlameConstraint<'tcx> { + self.best_blame_constraint_filtered( + body, + from_region, + from_region_origin, + target_test, + |_| true, + ) + } + + /// Same as `best_blame_constraint` but this can exclude some constraints from being reported + /// as the "best" according to `filter`. + pub(crate) fn best_blame_constraint_filtered( + &self, + body: &Body<'tcx>, + from_region: RegionVid, + from_region_origin: NllRegionVariableOrigin, + target_test: impl Fn(RegionVid) -> bool, + filter: impl Fn(&BlameConstraint<'tcx>) -> bool, ) -> BlameConstraint<'tcx> { debug!( "best_blame_constraint(from_region={:?}, from_region_origin={:?})", @@ -2115,6 +2146,13 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } }) + // Downgrade the category of filtered constraints to be ignored later. + .map(|mut blame| { + if !filter(&blame) { + blame.category = ConstraintCategory::Internal; + } + blame + }) .collect(); debug!("best_blame_constraint: categorized_path={:#?}", categorized_path); @@ -2259,6 +2297,24 @@ impl<'tcx> RegionInferenceContext<'tcx> { categorized_path.remove(0) } + /// Replaces region variables with equal universal regions where possible. + pub(crate) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T + where + T: TypeFoldable<'tcx>, + { + tcx.fold_regions(ty, |region, _| match *region { + ty::ReVar(vid) => { + let scc = self.constraint_sccs.scc(vid); + let normalized = self.scc_representatives[scc]; + match &self.definitions[normalized].external_name { + Some(universal_r) => *universal_r, + None => region, + } + } + _ => region, + }) + } + pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { self.universe_causes[&universe].clone() } diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index d6712b6a4799c..746ad17bc353f 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -153,7 +153,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// that the regions produced are in fact equal to the named region they are /// replaced with. This is fine because this function is only to improve the /// region names in error messages. - pub(crate) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T + pub(crate) fn name_regions_opaque(&self, tcx: TyCtxt<'tcx>, ty: T) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 4431a2e8ec60d..31dbf5c4f53cf 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -101,9 +101,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // argument N is stored in local N+2. let local = Local::new(argument_index + 2); let mir_input_ty = body.local_decls[local].ty; + // FIXME span should point to the type annotation, not the argument. let mir_input_span = body.local_decls[local].source_info.span; // If the user explicitly annotated the input types, enforce those. + let user_provided_input_ty = + self.extract_annotations(user_provided_input_ty, mir_input_span); let user_provided_input_ty = self.normalize(user_provided_input_ty, Locations::All(mir_input_span)); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 7bf7f7357bf4f..a6be14c8542d9 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -494,7 +494,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { ty::Variance::Invariant, user_ty, Locations::All(*span), - ConstraintCategory::TypeAnnotation, + ConstraintCategory::Boring, ) { span_mirbug!( self, @@ -1076,6 +1076,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation; let inferred_ty = self.normalize(inferred_ty, Locations::All(span)); let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty); + let annotation = self.extract_annotations(annotation, span); match annotation { UserType::Ty(mut ty) => { ty = self.normalize(ty, Locations::All(span)); diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index c97a6a1a6587a..03b67e6f8c3e1 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -4,7 +4,7 @@ use rustc_infer::traits::ObligationCause; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::relate::TypeRelation; -use rustc_middle::ty::{self, Const, Ty}; +use rustc_middle::ty::{self, Const, Ty, TypeFoldable}; use rustc_span::Span; use rustc_trait_selection::traits::query::Fallible; @@ -55,6 +55,29 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { .relate(a, b)?; Ok(()) } + + /// Given a user annotation, `val`, this registers the minimum necessary region constraints + /// under the category `ConstraintCategory::TypeAnnotation` and replaces annotated lifetimes + /// with fresh inference vars. + pub(super) fn extract_annotations>(&mut self, val: T, span: Span) -> T { + let tcx = self.infcx.tcx; + let mut relate = NllTypeRelatingDelegate::new( + self, + Locations::All(span), + ConstraintCategory::TypeAnnotation, + UniverseInfo::other(), + ); + tcx.fold_regions(val, |region, _| match region.kind() { + ty::ReVar(_) => region, + ty::ReFree(_) | ty::ReEarlyBound(_) | ty::ReStatic => { + let var = relate.next_existential_region_var(false); + relate.push_outlives(region, var, ty::VarianceDiagInfo::default()); + relate.push_outlives(var, region, ty::VarianceDiagInfo::default()); + var + } + _ => bug!("unexpected region in type annotation {:?}", region), + }) + } } struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 7a87a3e488260..35e0730a506e0 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -242,6 +242,13 @@ impl<'hir> PathSegment<'hir> { DUMMY } } + + pub fn span(&self) -> Span { + match self.args { + Some(ref args) => self.ident.span.to(args.span_ext), + None => self.ident.span, + } + } } #[derive(Encodable, Debug, HashStable_Generic)] diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 5e26a52900eaf..6247edf83bd34 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -132,6 +132,8 @@ pub struct Adt<'tcx> { /// Optional user-given substs: for something like `let x = /// Bar:: { ... }`. pub user_ty: Option>>, + /// Constructor span, e.g. `Foo::` in `Foo::(1)`. + pub ctor_span: Span, pub fields: Box<[FieldExpr]>, /// The base, e.g. `Foo {x: 1, .. base}`. diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 97249fdd17563..ec8fd698f0efd 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -115,6 +115,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp variant_index: _, substs: _, user_ty: _, + ctor_span: _, }) => { for field in &**fields { visitor.visit_expr(&visitor.thir()[field.expr]); diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 017d43d10a9a9..014948cfa00e4 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -319,6 +319,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { variant_index, substs, user_ty, + ctor_span, ref fields, ref base, }) => { @@ -380,7 +381,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let inferred_ty = expr.ty; let user_ty = user_ty.map(|ty| { this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { - span: source_info.span, + span: ctor_span, user_ty: ty, inferred_ty, }) diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 864caf0ba3197..bac109334e7c2 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -395,6 +395,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { variant_index: _, substs: _, user_ty: _, + ctor_span: _, fields: _, base: _, }) => match self.tcx.layout_scalar_valid_range(adt_def.did()) { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 985601712c4f0..50e5793d4317c 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -263,7 +263,7 @@ impl<'tcx> Cx<'tcx> { // Here comes the interesting stuff: hir::ExprKind::MethodCall(segment, ref args, fn_span) => { // Rewrite a.b(c) into UFCS form like Trait::b(a, c) - let expr = self.method_callee(expr, segment.ident.span, None); + let expr = self.method_callee(expr, segment.span(), None); // When we apply adjustments to the receiver, use the span of // the overall method call for better diagnostics. args[0] // is guaranteed to exist, since a method call always has a receiver. @@ -347,6 +347,7 @@ impl<'tcx> Cx<'tcx> { variant_index: index, fields: field_refs, user_ty, + ctor_span: fun.span, base: None, })) } else { @@ -471,6 +472,7 @@ impl<'tcx> Cx<'tcx> { variant_index: VariantIdx::new(0), substs, user_ty, + ctor_span: qpath.span(), fields: self.field_refs(fields), base: base.as_ref().map(|base| FruInfo { base: self.mirror_expr(base), @@ -497,6 +499,7 @@ impl<'tcx> Cx<'tcx> { variant_index: index, substs, user_ty, + ctor_span: qpath.span(), fields: self.field_refs(fields), base: None, })) @@ -862,6 +865,7 @@ impl<'tcx> Cx<'tcx> { variant_index: adt_def.variant_index_with_ctor_id(def_id), substs, user_ty: user_provided_type, + ctor_span: expr.span, fields: Box::new([]), base: None, })), diff --git a/src/test/ui/associated-types/associated-types-subtyping-1.stderr b/src/test/ui/associated-types/associated-types-subtyping-1.stderr index 414bc048ab51c..e8f6d1b92eedc 100644 --- a/src/test/ui/associated-types/associated-types-subtyping-1.stderr +++ b/src/test/ui/associated-types/associated-types-subtyping-1.stderr @@ -8,6 +8,9 @@ LL | fn method2<'a,'b,T>(x: &'a T, y: &'b T) ... LL | let a: >::Type = make_any(); | ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` +... +LL | let _c: >::Type = a; + | - because of assignment here | = help: consider adding the following bound: `'b: 'a` diff --git a/src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.stderr b/src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.stderr index 6994c837dfcbe..6f16850002ed6 100644 --- a/src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.stderr +++ b/src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.stderr @@ -2,12 +2,13 @@ error[E0506]: cannot assign to `*s` because it is borrowed --> $DIR/borrowck-loan-of-static-data-issue-27616.rs:16:5 | LL | let alias: &'static mut String = s; - | ------------------- - borrow of `*s` occurs here - | | - | type annotation requires that `*s` is borrowed for `'static` + | - borrow of `*s` occurs here ... LL | *s = String::new(); | ^^ assignment to borrowed `*s` occurs here +... +LL | println!("{}", inner); + | ----- borrow later used here error: aborting due to previous error diff --git a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr index 26f47eb684dfc..e6e6f6155a16c 100644 --- a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr +++ b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr @@ -8,7 +8,7 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); | ^ | | | has type `fn(&'1 u32)` - | requires that `'1` must outlive `'x` + | type annotation requires that `'1` must outlive `'x` error: lifetime may not live long enough --> $DIR/expect-fn-supply-fn.rs:16:49 @@ -17,7 +17,7 @@ LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) { | -- lifetime `'x` defined here ... LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); - | ^ requires that `'x` must outlive `'static` + | ^ type annotation requires that `'x` must outlive `'static` error[E0308]: mismatched types --> $DIR/expect-fn-supply-fn.rs:32:49 diff --git a/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr b/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr index 9aab51c986cac..c7e0cc0642f04 100644 --- a/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr +++ b/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr @@ -7,7 +7,7 @@ LL | fn expect_bound_supply_named<'x>() { LL | closure_expecting_bound(|x: &'x u32| { | ^ - let's call the lifetime of this reference `'1` | | - | requires that `'1` must outlive `'x` + | type annotation requires that `'1` must outlive `'x` error: lifetime may not live long enough --> $DIR/expect-region-supply-region-2.rs:14:30 @@ -16,7 +16,7 @@ LL | fn expect_bound_supply_named<'x>() { | -- lifetime `'x` defined here ... LL | closure_expecting_bound(|x: &'x u32| { - | ^ requires that `'x` must outlive `'static` + | ^ type annotation requires that `'x` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/invariant.stderr b/src/test/ui/const-generics/invariant.stderr index ce0fad104713b..318c885e6a6bb 100644 --- a/src/test/ui/const-generics/invariant.stderr +++ b/src/test/ui/const-generics/invariant.stderr @@ -18,8 +18,8 @@ error[E0308]: mismatched types LL | v | ^ one type is more general than the other | - = note: expected reference `&Foo` - found reference `&Foo fn(&'a ())>` + = note: expected reference `&'static Foo` + found reference `&'static Foo fn(&'a ())>` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.stderr b/src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.stderr index 78143042ece7b..decec43ada4d2 100644 --- a/src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.stderr +++ b/src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.stderr @@ -7,6 +7,12 @@ LL | &std::intrinsics::size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-eval-intrinsic-promotion.rs:4:12 + | +LL | let x: &'static usize = + | ^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr index 69e3ca716a909..08c4c00f83090 100644 --- a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr +++ b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr @@ -15,6 +15,12 @@ LL | let _: &'static u32 = &foo(); | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dont_promote_unstable_const_fn.rs:17:12 + | +LL | let _: &'static u32 = &foo(); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/dont_promote_unstable_const_fn.rs:21:28 @@ -26,6 +32,12 @@ LL | let _: &'static u32 = &meh(); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dont_promote_unstable_const_fn.rs:21:12 + | +LL | let _: &'static u32 = &meh(); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/dont_promote_unstable_const_fn.rs:22:26 @@ -37,6 +49,12 @@ LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dont_promote_unstable_const_fn.rs:22:12 + | +LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis(); + | ^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn_cross_crate.stderr b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn_cross_crate.stderr index 129f06151074f..e616f73b31562 100644 --- a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn_cross_crate.stderr +++ b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn_cross_crate.stderr @@ -8,6 +8,12 @@ LL | let _: &'static u32 = &foo(); LL | let _x: &'static u32 = &foo(); LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:8:12 + | +LL | let _: &'static u32 = &foo(); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:9:29 @@ -18,6 +24,12 @@ LL | let _x: &'static u32 = &foo(); | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:9:13 + | +LL | let _x: &'static u32 = &foo(); + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr index c6ca30e09bd3f..ca643f6d008d0 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr @@ -8,6 +8,12 @@ LL | let x: &'static u8 = &(bar() + 1); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_const_fn_fail.rs:19:12 + | +LL | let x: &'static u8 = &(bar() + 1); + | ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr index c6275a835e544..6932e300a4726 100644 --- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr +++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr @@ -8,6 +8,12 @@ LL | let x: &'static u8 = &(bar() + 1); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_const_fn_fail_deny_const_err.rs:20:12 + | +LL | let x: &'static u8 = &(bar() + 1); + | ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/promoted_raw_ptr_ops.stderr b/src/test/ui/consts/const-eval/promoted_raw_ptr_ops.stderr index 8ac60da38634b..21b618164ac82 100644 --- a/src/test/ui/consts/const-eval/promoted_raw_ptr_ops.stderr +++ b/src/test/ui/consts/const-eval/promoted_raw_ptr_ops.stderr @@ -8,6 +8,12 @@ LL | let x: &'static bool = &(42 as *const i32 == 43 as *const i32); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_raw_ptr_ops.rs:2:12 + | +LL | let x: &'static bool = &(42 as *const i32 == 43 as *const i32); + | ^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_raw_ptr_ops.rs:4:30 @@ -19,6 +25,12 @@ LL | let y: &'static usize = &(&1 as *const i32 as usize + 1); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_raw_ptr_ops.rs:4:12 + | +LL | let y: &'static usize = &(&1 as *const i32 as usize + 1); + | ^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_raw_ptr_ops.rs:6:28 @@ -30,6 +42,12 @@ LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_raw_ptr_ops.rs:6:12 + | +LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_raw_ptr_ops.rs:8:29 @@ -41,6 +59,12 @@ LL | let a: &'static bool = &(main as fn() == main as fn()); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted_raw_ptr_ops.rs:8:12 + | +LL | let a: &'static bool = &(main as fn() == main as fn()); + | ^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/const-eval/transmute-const-promotion.stderr b/src/test/ui/consts/const-eval/transmute-const-promotion.stderr index 15b9b56ea6606..cc0500e06d02f 100644 --- a/src/test/ui/consts/const-eval/transmute-const-promotion.stderr +++ b/src/test/ui/consts/const-eval/transmute-const-promotion.stderr @@ -8,6 +8,12 @@ LL | let x: &'static u32 = unsafe { &mem::transmute(3.0f32) }; LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/transmute-const-promotion.rs:4:12 + | +LL | let x: &'static u32 = unsafe { &mem::transmute(3.0f32) }; + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/union_promotion.stderr b/src/test/ui/consts/const-eval/union_promotion.stderr index ed186e3ebd2f5..f7dcfcb79da76 100644 --- a/src/test/ui/consts/const-eval/union_promotion.stderr +++ b/src/test/ui/consts/const-eval/union_promotion.stderr @@ -10,6 +10,12 @@ LL | | }; | |_____^ creates a temporary which is freed while still in use LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/union_promotion.rs:10:12 + | +LL | let x: &'static bool = &unsafe { + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/const-int-conversion.stderr b/src/test/ui/consts/const-int-conversion.stderr index 61162a792262b..94dd7230eff73 100644 --- a/src/test/ui/consts/const-int-conversion.stderr +++ b/src/test/ui/consts/const-int-conversion.stderr @@ -8,6 +8,12 @@ LL | let x: &'static i32 = &(5_i32.reverse_bits()); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:2:12 + | +LL | let x: &'static i32 = &(5_i32.reverse_bits()); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:4:28 @@ -19,6 +25,12 @@ LL | let y: &'static i32 = &(i32::from_be_bytes([0x12, 0x34, 0x56, 0x78])); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:4:12 + | +LL | let y: &'static i32 = &(i32::from_be_bytes([0x12, 0x34, 0x56, 0x78])); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:6:28 @@ -30,6 +42,12 @@ LL | let z: &'static i32 = &(i32::from_le_bytes([0x12, 0x34, 0x56, 0x78])); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:6:12 + | +LL | let z: &'static i32 = &(i32::from_le_bytes([0x12, 0x34, 0x56, 0x78])); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:8:28 @@ -41,6 +59,12 @@ LL | let a: &'static i32 = &(i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0] ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:8:12 + | +LL | let a: &'static i32 = &(i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]))); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:10:29 @@ -52,6 +76,12 @@ LL | let b: &'static [u8] = &(0x12_34_56_78_i32.to_be_bytes()); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:10:12 + | +LL | let b: &'static [u8] = &(0x12_34_56_78_i32.to_be_bytes()); + | ^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:12:29 @@ -63,6 +93,12 @@ LL | let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes()); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:12:12 + | +LL | let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes()); + | ^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:14:29 @@ -74,6 +110,12 @@ LL | let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes()); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-conversion.rs:14:12 + | +LL | let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes()); + | ^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-int-overflowing.stderr b/src/test/ui/consts/const-int-overflowing.stderr index 56c7f7f092d66..31198532aa4e3 100644 --- a/src/test/ui/consts/const-int-overflowing.stderr +++ b/src/test/ui/consts/const-int-overflowing.stderr @@ -8,6 +8,12 @@ LL | let x: &'static (i32, bool) = &(5_i32.overflowing_add(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-overflowing.rs:2:12 + | +LL | let x: &'static (i32, bool) = &(5_i32.overflowing_add(3)); + | ^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-overflowing.rs:4:36 @@ -19,6 +25,12 @@ LL | let y: &'static (i32, bool) = &(5_i32.overflowing_sub(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-overflowing.rs:4:12 + | +LL | let y: &'static (i32, bool) = &(5_i32.overflowing_sub(3)); + | ^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-overflowing.rs:6:36 @@ -30,6 +42,12 @@ LL | let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-overflowing.rs:6:12 + | +LL | let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/consts/const-int-rotate.stderr b/src/test/ui/consts/const-int-rotate.stderr index ed265804bbc6c..ac15094c6cec8 100644 --- a/src/test/ui/consts/const-int-rotate.stderr +++ b/src/test/ui/consts/const-int-rotate.stderr @@ -8,6 +8,12 @@ LL | let x: &'static i32 = &(5_i32.rotate_left(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-rotate.rs:2:12 + | +LL | let x: &'static i32 = &(5_i32.rotate_left(3)); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-rotate.rs:4:28 @@ -19,6 +25,12 @@ LL | let y: &'static i32 = &(5_i32.rotate_right(3)); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-rotate.rs:4:12 + | +LL | let y: &'static i32 = &(5_i32.rotate_right(3)); + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-int-sign.stderr b/src/test/ui/consts/const-int-sign.stderr index 5f8fd4141804c..7ec4660411f3a 100644 --- a/src/test/ui/consts/const-int-sign.stderr +++ b/src/test/ui/consts/const-int-sign.stderr @@ -8,6 +8,12 @@ LL | let x: &'static bool = &(5_i32.is_negative()); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-sign.rs:2:12 + | +LL | let x: &'static bool = &(5_i32.is_negative()); + | ^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-sign.rs:4:29 @@ -19,6 +25,12 @@ LL | let y: &'static bool = &(5_i32.is_positive()); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-sign.rs:4:12 + | +LL | let y: &'static bool = &(5_i32.is_positive()); + | ^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-int-wrapping.stderr b/src/test/ui/consts/const-int-wrapping.stderr index 5174b72659cd7..85f314f547c85 100644 --- a/src/test/ui/consts/const-int-wrapping.stderr +++ b/src/test/ui/consts/const-int-wrapping.stderr @@ -8,6 +8,12 @@ LL | let x: &'static i32 = &(5_i32.wrapping_add(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-wrapping.rs:2:12 + | +LL | let x: &'static i32 = &(5_i32.wrapping_add(3)); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-wrapping.rs:4:28 @@ -19,6 +25,12 @@ LL | let y: &'static i32 = &(5_i32.wrapping_sub(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-wrapping.rs:4:12 + | +LL | let y: &'static i32 = &(5_i32.wrapping_sub(3)); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-wrapping.rs:6:28 @@ -30,6 +42,12 @@ LL | let z: &'static i32 = &(5_i32.wrapping_mul(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-wrapping.rs:6:12 + | +LL | let z: &'static i32 = &(5_i32.wrapping_mul(3)); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-wrapping.rs:8:28 @@ -41,6 +59,12 @@ LL | let a: &'static i32 = &(5_i32.wrapping_shl(3)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-wrapping.rs:8:12 + | +LL | let a: &'static i32 = &(5_i32.wrapping_shl(3)); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-wrapping.rs:10:28 @@ -52,6 +76,12 @@ LL | let b: &'static i32 = &(5_i32.wrapping_shr(3)); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-int-wrapping.rs:10:12 + | +LL | let b: &'static i32 = &(5_i32.wrapping_shr(3)); + | ^^^^^^^^^^^^ error: aborting due to 5 previous errors diff --git a/src/test/ui/consts/const-ptr-nonnull.stderr b/src/test/ui/consts/const-ptr-nonnull.stderr index 26946fb99024c..73b1e5e3357dd 100644 --- a/src/test/ui/consts/const-ptr-nonnull.stderr +++ b/src/test/ui/consts/const-ptr-nonnull.stderr @@ -8,6 +8,12 @@ LL | let x: &'static NonNull = &(NonNull::dangling()); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-ptr-nonnull.rs:4:12 + | +LL | let x: &'static NonNull = &(NonNull::dangling()); + | ^^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/const-ptr-nonnull.rs:9:37 @@ -19,6 +25,12 @@ LL | let x: &'static NonNull = &(non_null.cast()); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-ptr-nonnull.rs:9:12 + | +LL | let x: &'static NonNull = &(non_null.cast()); + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-ptr-unique.stderr b/src/test/ui/consts/const-ptr-unique.stderr index 3644cf4cec7d3..6044bc996feb2 100644 --- a/src/test/ui/consts/const-ptr-unique.stderr +++ b/src/test/ui/consts/const-ptr-unique.stderr @@ -8,6 +8,12 @@ LL | let x: &'static *mut u32 = &(unique.as_ptr()); LL | LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-ptr-unique.rs:8:12 + | +LL | let x: &'static *mut u32 = &(unique.as_ptr()); + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/consts/control-flow/interior-mutability.stderr b/src/test/ui/consts/control-flow/interior-mutability.stderr index 4f9c7d34c35f4..87063df5b1d25 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.stderr +++ b/src/test/ui/consts/control-flow/interior-mutability.stderr @@ -8,6 +8,12 @@ LL | let x: &'static _ = &X; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/interior-mutability.rs:40:12 + | +LL | let x: &'static _ = &X; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/interior-mutability.rs:41:26 @@ -19,6 +25,12 @@ LL | let y: &'static _ = &Y; LL | let z: &'static _ = &Z; LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/interior-mutability.rs:41:12 + | +LL | let y: &'static _ = &Y; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/interior-mutability.rs:42:26 @@ -29,6 +41,12 @@ LL | let z: &'static _ = &Z; | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/interior-mutability.rs:42:12 + | +LL | let z: &'static _ = &Z; + | ^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/consts/min_const_fn/promotion.stderr b/src/test/ui/consts/min_const_fn/promotion.stderr index 550423c2d933c..7c8ca7c639185 100644 --- a/src/test/ui/consts/min_const_fn/promotion.stderr +++ b/src/test/ui/consts/min_const_fn/promotion.stderr @@ -8,6 +8,12 @@ LL | let x: &'static () = &foo1(); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:11:12 + | +LL | let x: &'static () = &foo1(); + | ^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promotion.rs:12:28 @@ -19,6 +25,12 @@ LL | let y: &'static i32 = &foo2(42); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:12:12 + | +LL | let y: &'static i32 = &foo2(42); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promotion.rs:13:28 @@ -30,6 +42,12 @@ LL | let z: &'static i32 = &foo3(); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:13:12 + | +LL | let z: &'static i32 = &foo3(); + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promotion.rs:14:34 @@ -41,6 +59,12 @@ LL | let a: &'static Cell = &foo4(); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:14:12 + | +LL | let a: &'static Cell = &foo4(); + | ^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promotion.rs:15:42 @@ -52,6 +76,12 @@ LL | let a: &'static Option> = &foo5(); LL | let a: &'static Option> = &foo6(); LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:15:12 + | +LL | let a: &'static Option> = &foo5(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promotion.rs:16:42 @@ -62,6 +92,12 @@ LL | let a: &'static Option> = &foo6(); | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promotion.rs:16:12 + | +LL | let a: &'static Option> = &foo6(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/consts/promote-not.stderr b/src/test/ui/consts/promote-not.stderr index 0d0b0f9c689b5..d1cd93ed287d0 100644 --- a/src/test/ui/consts/promote-not.stderr +++ b/src/test/ui/consts/promote-not.stderr @@ -27,6 +27,12 @@ LL | let _x: &'static () = &foo(); | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:20:17 + | +LL | let _x: &'static () = &foo(); + | ^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:28:29 @@ -37,6 +43,12 @@ LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:28:13 + | +LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:33:29 @@ -47,6 +59,12 @@ LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; | type annotation requires that borrow lasts for `'static` LL | }; | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:33:13 + | +LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:39:29 @@ -57,6 +75,12 @@ LL | let _val: &'static _ = &(Cell::new(1), 2).1; | type annotation requires that borrow lasts for `'static` LL | }; | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:39:15 + | +LL | let _val: &'static _ = &(Cell::new(1), 2).1; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:46:29 @@ -68,6 +92,12 @@ LL | let _val: &'static _ = &(Cell::new(1), 2).0; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:46:15 + | +LL | let _val: &'static _ = &(Cell::new(1), 2).0; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:47:29 @@ -79,6 +109,12 @@ LL | let _val: &'static _ = &(Cell::new(1), 2).1; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:47:15 + | +LL | let _val: &'static _ = &(Cell::new(1), 2).1; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:50:29 @@ -90,6 +126,12 @@ LL | let _val: &'static _ = &(1/0); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:50:15 + | +LL | let _val: &'static _ = &(1/0); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:51:29 @@ -101,6 +143,12 @@ LL | let _val: &'static _ = &(1/(1-1)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:51:15 + | +LL | let _val: &'static _ = &(1/(1-1)); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:52:29 @@ -112,6 +160,12 @@ LL | let _val: &'static _ = &(1%0); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:52:15 + | +LL | let _val: &'static _ = &(1%0); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:53:29 @@ -123,6 +177,12 @@ LL | let _val: &'static _ = &(1%(1-1)); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:53:15 + | +LL | let _val: &'static _ = &(1%(1-1)); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:54:29 @@ -134,6 +194,12 @@ LL | let _val: &'static _ = &([1,2,3][4]+1); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:54:15 + | +LL | let _val: &'static _ = &([1,2,3][4]+1); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:57:29 @@ -145,6 +211,12 @@ LL | let _val: &'static _ = &TEST_DROP; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:57:15 + | +LL | let _val: &'static _ = &TEST_DROP; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:59:29 @@ -156,6 +228,12 @@ LL | let _val: &'static _ = &&TEST_DROP; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:59:15 + | +LL | let _val: &'static _ = &&TEST_DROP; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:59:30 @@ -167,6 +245,12 @@ LL | let _val: &'static _ = &&TEST_DROP; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:59:15 + | +LL | let _val: &'static _ = &&TEST_DROP; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:62:29 @@ -178,6 +262,12 @@ LL | let _val: &'static _ = &(&TEST_DROP,); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:62:15 + | +LL | let _val: &'static _ = &(&TEST_DROP,); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:62:31 @@ -189,6 +279,12 @@ LL | let _val: &'static _ = &(&TEST_DROP,); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:62:15 + | +LL | let _val: &'static _ = &(&TEST_DROP,); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:65:29 @@ -200,6 +296,12 @@ LL | let _val: &'static _ = &[&TEST_DROP; 1]; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:65:15 + | +LL | let _val: &'static _ = &[&TEST_DROP; 1]; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:65:31 @@ -209,6 +311,12 @@ LL | let _val: &'static _ = &[&TEST_DROP; 1]; | | | | | creates a temporary which is freed while still in use | type annotation requires that borrow lasts for `'static` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote-not.rs:65:15 + | +LL | let _val: &'static _ = &[&TEST_DROP; 1]; + | ^^^^^^^^^^ error: aborting due to 20 previous errors diff --git a/src/test/ui/consts/promote_const_let.stderr b/src/test/ui/consts/promote_const_let.stderr index c47d297c90409..ce5445ced9d61 100644 --- a/src/test/ui/consts/promote_const_let.stderr +++ b/src/test/ui/consts/promote_const_let.stderr @@ -8,6 +8,12 @@ LL | &y | ^^ borrowed value does not live long enough LL | }; | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote_const_let.rs:2:12 + | +LL | let x: &'static u32 = { + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promote_const_let.rs:6:28 @@ -22,6 +28,12 @@ LL | | }; | |_____^ creates a temporary which is freed while still in use LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promote_const_let.rs:6:12 + | +LL | let x: &'static u32 = &{ + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/promoted-const-drop.stderr b/src/test/ui/consts/promoted-const-drop.stderr index 184ba0ea3b377..edba49b0447db 100644 --- a/src/test/ui/consts/promoted-const-drop.stderr +++ b/src/test/ui/consts/promoted-const-drop.stderr @@ -8,6 +8,12 @@ LL | let _: &'static A = &A(); LL | let _: &'static [A] = &[C]; LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted-const-drop.rs:13:12 + | +LL | let _: &'static A = &A(); + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/promoted-const-drop.rs:14:28 @@ -18,6 +24,12 @@ LL | let _: &'static [A] = &[C]; | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted-const-drop.rs:14:12 + | +LL | let _: &'static [A] = &[C]; + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/qualif-union.stderr b/src/test/ui/consts/qualif-union.stderr index 8ec68ada048a5..d5695ee722802 100644 --- a/src/test/ui/consts/qualif-union.stderr +++ b/src/test/ui/consts/qualif-union.stderr @@ -8,6 +8,12 @@ LL | let _: &'static _ = &C1; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/qualif-union.rs:28:12 + | +LL | let _: &'static _ = &C1; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/qualif-union.rs:29:26 @@ -19,6 +25,12 @@ LL | let _: &'static _ = &C2; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/qualif-union.rs:29:12 + | +LL | let _: &'static _ = &C2; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/qualif-union.rs:30:26 @@ -30,6 +42,12 @@ LL | let _: &'static _ = &C3; ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/qualif-union.rs:30:12 + | +LL | let _: &'static _ = &C3; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/qualif-union.rs:31:26 @@ -41,6 +59,12 @@ LL | let _: &'static _ = &C4; LL | let _: &'static _ = &C5; LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/qualif-union.rs:31:12 + | +LL | let _: &'static _ = &C4; + | ^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/qualif-union.rs:32:26 @@ -51,6 +75,12 @@ LL | let _: &'static _ = &C5; | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/qualif-union.rs:32:12 + | +LL | let _: &'static _ = &C5; + | ^^^^^^^^^^ error: aborting due to 5 previous errors diff --git a/src/test/ui/dst/dst-bad-coerce3.stderr b/src/test/ui/dst/dst-bad-coerce3.stderr index 957e98bbeee96..e65279ab27fe9 100644 --- a/src/test/ui/dst/dst-bad-coerce3.stderr +++ b/src/test/ui/dst/dst-bad-coerce3.stderr @@ -11,6 +11,12 @@ LL | let f3: &'a Fat<[isize]> = f2; ... LL | } | - `f1` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dst-bad-coerce3.rs:17:13 + | +LL | let f3: &'a Fat<[isize]> = f2; + | ^^^^^^^^^^^^^^^^ error[E0597]: `f1` does not live long enough --> $DIR/dst-bad-coerce3.rs:21:25 @@ -25,6 +31,12 @@ LL | let f3: &'a Fat = f2; ... LL | } | - `f1` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dst-bad-coerce3.rs:22:13 + | +LL | let f3: &'a Fat = f2; + | ^^^^^^^^^^^^^^^^ error[E0597]: `f1` does not live long enough --> $DIR/dst-bad-coerce3.rs:26:30 @@ -39,6 +51,12 @@ LL | let f3: &'a ([isize],) = f2; ... LL | } | - `f1` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dst-bad-coerce3.rs:27:13 + | +LL | let f3: &'a ([isize],) = f2; + | ^^^^^^^^^^^^^^ error[E0597]: `f1` does not live long enough --> $DIR/dst-bad-coerce3.rs:31:23 @@ -52,6 +70,12 @@ LL | let f3: &'a (dyn Bar,) = f2; | -------------- type annotation requires that `f1` is borrowed for `'a` LL | } | - `f1` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/dst-bad-coerce3.rs:32:13 + | +LL | let f3: &'a (dyn Bar,) = f2; + | ^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr index 0c3df04eabcd2..cc8116fc967b2 100644 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr @@ -6,12 +6,9 @@ LL | fn g<'a, 'b>() { | | | lifetime `'a` defined here LL | f::<'a, 'b>(()); - | ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a function pointer to `f` - = note: the function `f` is invariant over the parameter `'a` - = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/higher-rank-trait-bounds/hrtb-cache-issue-54302.stderr b/src/test/ui/higher-rank-trait-bounds/hrtb-cache-issue-54302.stderr index f014eab8601fa..d3f33e564ba03 100644 --- a/src/test/ui/higher-rank-trait-bounds/hrtb-cache-issue-54302.stderr +++ b/src/test/ui/higher-rank-trait-bounds/hrtb-cache-issue-54302.stderr @@ -4,7 +4,7 @@ error: implementation of `Deserialize` is not general enough LL | assert_deserialize_owned::<&'static str>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Deserialize` is not general enough | - = note: `&'static str` must implement `Deserialize<'0>`, for any lifetime `'0`... + = note: `&str` must implement `Deserialize<'0>`, for any lifetime `'0`... = note: ...but `&str` actually implements `Deserialize<'1>`, for some specific lifetime `'1` error: aborting due to previous error diff --git a/src/test/ui/higher-rank-trait-bounds/hrtb-just-for-static.stderr b/src/test/ui/higher-rank-trait-bounds/hrtb-just-for-static.stderr index b4312091edb27..4d8a552a5e894 100644 --- a/src/test/ui/higher-rank-trait-bounds/hrtb-just-for-static.stderr +++ b/src/test/ui/higher-rank-trait-bounds/hrtb-just-for-static.stderr @@ -13,7 +13,7 @@ error: lifetime may not live long enough LL | fn give_some<'a>() { | -- lifetime `'a` defined here LL | want_hrtb::<&'a u32>() - | ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: implementation of `Foo` is not general enough --> $DIR/hrtb-just-for-static.rs:30:5 diff --git a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr index 31d36d7168b61..732ddc79e42ef 100644 --- a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr +++ b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr @@ -6,36 +6,30 @@ LL | fn subtype<'x, 'y: 'x, 'z: 'y>() { | | | lifetime `'x` defined here LL | gimme::<$t2>(None::<$t1>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'x` must outlive `'y` + | ^^^^^^^^^^^^ type annotation requires that `'x` must outlive `'y` ... LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>), LL | | fn(Inv<'y>)) } | |______________- in this macro invocation | = help: consider adding the following bound: `'x: 'y` - = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant - = note: the struct `Inv<'a>` is invariant over the parameter `'a` - = help: see for more information about variance = note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info) error: lifetime may not live long enough - --> $DIR/hr-subtype.rs:54:13 + --> $DIR/hr-subtype.rs:54:26 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { | -- -- lifetime `'y` defined here | | | lifetime `'x` defined here LL | gimme::<$t1>(None::<$t2>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'x` must outlive `'y` + | ^^^^^^^^^^^ type annotation requires that `'x` must outlive `'y` ... LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>), LL | | fn(Inv<'y>)) } | |______________- in this macro invocation | = help: consider adding the following bound: `'x: 'y` - = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant - = note: the struct `Inv<'a>` is invariant over the parameter `'a` - = help: see for more information about variance = note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr b/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr index 269cde54c7e3d..b9f099d20f197 100644 --- a/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr +++ b/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr @@ -1,12 +1,12 @@ error: lifetime may not live long enough - --> $DIR/hr-subtype.rs:54:13 + --> $DIR/hr-subtype.rs:54:26 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { | -- -- lifetime `'y` defined here | | | lifetime `'x` defined here LL | gimme::<$t1>(None::<$t2>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'x` must outlive `'y` + | ^^^^^^^^^^^ type annotation requires that `'x` must outlive `'y` ... LL | / check! { free_x_vs_free_y: (fn(&'x u32), LL | | fn(&'y u32)) } diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 01d9f506a0c58..50d875a120431 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -6,6 +6,9 @@ LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | | | lifetime `'a` defined here ... +LL | let u = v; + | - because of assignment here +... LL | let _: &'b i32 = *u.0; | ^^^^^^^ type annotation requires that `'a` must outlive `'b` | diff --git a/src/test/ui/inline-const/const-expr-lifetime-err.stderr b/src/test/ui/inline-const/const-expr-lifetime-err.stderr index a23f7c9a796c5..f2f8a080086ce 100644 --- a/src/test/ui/inline-const/const-expr-lifetime-err.stderr +++ b/src/test/ui/inline-const/const-expr-lifetime-err.stderr @@ -5,13 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let y = (); LL | equate(InvariantRef::new(&y), const { InvariantRef::<'a>::NEW }); - | ------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `y` is borrowed for `'a` + | ^^ ----------------------- type annotation requires that `y` is borrowed for `'a` + | | + | borrowed value does not live long enough LL | LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/const-expr-lifetime-err.rs:23:43 + | +LL | equate(InvariantRef::new(&y), const { InvariantRef::<'a>::NEW }); + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-26217.stderr b/src/test/ui/issues/issue-26217.stderr index c7601caacdca3..aa32871f302bf 100644 --- a/src/test/ui/issues/issue-26217.stderr +++ b/src/test/ui/issues/issue-26217.stderr @@ -4,7 +4,7 @@ error: lifetime may not live long enough LL | fn bar<'a>() { | -- lifetime `'a` defined here LL | foo::<&'a i32>(); - | ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-47184.stderr b/src/test/ui/issues/issue-47184.stderr index f97713b4ac438..f34d94b13221d 100644 --- a/src/test/ui/issues/issue-47184.stderr +++ b/src/test/ui/issues/issue-47184.stderr @@ -6,6 +6,12 @@ LL | let _vec: Vec<&'static String> = vec![&String::new()]; | | | | | creates a temporary which is freed while still in use | type annotation requires that borrow lasts for `'static` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-47184.rs:2:15 + | +LL | let _vec: Vec<&'static String> = vec![&String::new()]; + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-54302.stderr b/src/test/ui/issues/issue-54302.stderr index 26c46571f9cb2..058599f5789be 100644 --- a/src/test/ui/issues/issue-54302.stderr +++ b/src/test/ui/issues/issue-54302.stderr @@ -4,7 +4,7 @@ error: implementation of `Deserialize` is not general enough LL | assert_deserialize_owned::<&'static str>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Deserialize` is not general enough | - = note: `&'static str` must implement `Deserialize<'0>`, for any lifetime `'0`... + = note: `&str` must implement `Deserialize<'0>`, for any lifetime `'0`... = note: ...but `&str` actually implements `Deserialize<'1>`, for some specific lifetime `'1` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-54943.stderr b/src/test/ui/issues/issue-54943.stderr index 59be0f983b907..6e900afb97656 100644 --- a/src/test/ui/issues/issue-54943.stderr +++ b/src/test/ui/issues/issue-54943.stderr @@ -5,7 +5,7 @@ LL | fn boo<'a>() { | -- lifetime `'a` defined here ... LL | let x = foo::<&'a u32>(); - | ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/lub-glb/empty-binders-err.rs b/src/test/ui/lub-glb/empty-binders-err.rs index 557480173ee62..8373f25b9a4bb 100644 --- a/src/test/ui/lub-glb/empty-binders-err.rs +++ b/src/test/ui/lub-glb/empty-binders-err.rs @@ -33,8 +33,8 @@ where { let _: fn(&'lower ()) = match v { - //~^ ERROR lifetime may not live long enough true => lt_in_fn::<'a>(), + //~^ ERROR lifetime may not live long enough false => lt_in_fn::<'b>(), }; } @@ -46,8 +46,8 @@ where { let _: Contra<'lower> = match v { - //~^ ERROR lifetime may not live long enough true => lt_in_contra::<'a>(), + //~^ ERROR lifetime may not live long enough false => lt_in_contra::<'b>(), }; } diff --git a/src/test/ui/lub-glb/empty-binders-err.stderr b/src/test/ui/lub-glb/empty-binders-err.stderr index f86f22d5e40bf..26658bcd35b63 100644 --- a/src/test/ui/lub-glb/empty-binders-err.stderr +++ b/src/test/ui/lub-glb/empty-binders-err.stderr @@ -30,28 +30,28 @@ help: the following changes may resolve your lifetime errors = help: add bound `'b: 'upper` error: lifetime may not live long enough - --> $DIR/empty-binders-err.rs:35:12 + --> $DIR/empty-binders-err.rs:36:17 | LL | fn contra_fn<'a, 'b, 'lower>(v: bool) | -- ------ lifetime `'lower` defined here | | | lifetime `'a` defined here ... -LL | let _: fn(&'lower ()) = match v { - | ^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a` +LL | true => lt_in_fn::<'a>(), + | ^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a` | = help: consider adding the following bound: `'lower: 'a` error: lifetime may not live long enough - --> $DIR/empty-binders-err.rs:48:12 + --> $DIR/empty-binders-err.rs:49:17 | LL | fn contra_struct<'a, 'b, 'lower>(v: bool) | -- ------ lifetime `'lower` defined here | | | lifetime `'a` defined here ... -LL | let _: Contra<'lower> = match v { - | ^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a` +LL | true => lt_in_contra::<'a>(), + | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a` | = help: consider adding the following bound: `'lower: 'a` diff --git a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs index a9d2a07715d49..69de3ce6e2447 100644 --- a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs +++ b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs @@ -9,10 +9,10 @@ pub fn dangle() -> &'static [i32] { let other_local_arr = [0, 2, 4]; let local_arr = other_local_arr; let mut out: &mut &'static [i32] = &mut (&[1] as _); - once(|mut z: &[i32], mut out_val: &mut &[i32]| { + once(|mut z: &[i32], mut out_val: &mut &[i32]| { //~ ERROR // We unfortunately point to the first use in the closure in the error // message - z = &local_arr; //~ ERROR + z = &local_arr; *out_val = &local_arr; }, &[] as &[_], &mut *out); *out diff --git a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr index 2fec9bc62d1c7..16940a484d1a0 100644 --- a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr @@ -1,17 +1,22 @@ -error[E0597]: `local_arr` does not live long enough - --> $DIR/propagate-multiple-requirements.rs:15:14 +error[E0373]: closure may outlive the current function, but it borrows `local_arr`, which is owned by the current function + --> $DIR/propagate-multiple-requirements.rs:12:10 | -LL | let mut out: &mut &'static [i32] = &mut (&[1] as _); - | ------------------- type annotation requires that `local_arr` is borrowed for `'static` LL | once(|mut z: &[i32], mut out_val: &mut &[i32]| { - | ----------------------------------------- value captured here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ may outlive borrowed value `local_arr` ... LL | z = &local_arr; - | ^^^^^^^^^ borrowed value does not live long enough -... -LL | } - | - `local_arr` dropped here while still borrowed + | --------- `local_arr` is borrowed here + | +note: closure is returned here + --> $DIR/propagate-multiple-requirements.rs:18:5 + | +LL | *out + | ^^^^ +help: to force the closure to take ownership of `local_arr` (and any other referenced variables), use the `move` keyword + | +LL | once(move |mut z: &[i32], mut out_val: &mut &[i32]| { + | ++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0597`. +For more information about this error, try `rustc --explain E0373`. diff --git a/src/test/ui/nll/issue-31567.stderr b/src/test/ui/nll/issue-31567.stderr index 7d43383e89fd7..49a116b003952 100644 --- a/src/test/ui/nll/issue-31567.stderr +++ b/src/test/ui/nll/issue-31567.stderr @@ -10,6 +10,12 @@ LL | let s_inner: &'a S = &*v.0; LL | &s_inner.0 LL | } | - here, drop of `v` needs exclusive access to `*v.0`, because the type `VecWrapper<'_>` implements the `Drop` trait + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-31567.rs:10:18 + | +LL | let s_inner: &'a S = &*v.0; + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-55511.stderr b/src/test/ui/nll/issue-55511.stderr index bf3e58e8cdb19..741c33810a85e 100644 --- a/src/test/ui/nll/issue-55511.stderr +++ b/src/test/ui/nll/issue-55511.stderr @@ -9,6 +9,12 @@ LL | <() as Foo<'static>>::C => { } ... LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-55511.rs:16:9 + | +LL | <() as Foo<'static>>::C => { } + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-58299.stderr b/src/test/ui/nll/issue-58299.stderr index 509ba67bd108d..ef40074fd994d 100644 --- a/src/test/ui/nll/issue-58299.stderr +++ b/src/test/ui/nll/issue-58299.stderr @@ -5,7 +5,7 @@ LL | fn foo<'a>(x: i32) { | -- lifetime `'a` defined here ... LL | A::<'a>::X..=A::<'static>::X => (), - | ^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/issue-58299.rs:22:27 @@ -14,7 +14,7 @@ LL | fn bar<'a>(x: i32) { | -- lifetime `'a` defined here ... LL | A::<'static>::X..=A::<'a>::X => (), - | ^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/issue-68550.stderr b/src/test/ui/nll/issue-68550.stderr index e234ebb04e16a..3cb715227fc0c 100644 --- a/src/test/ui/nll/issue-68550.stderr +++ b/src/test/ui/nll/issue-68550.stderr @@ -10,6 +10,12 @@ LL | let _: &'a A = &x; | type annotation requires that `x` is borrowed for `'a` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-68550.rs:12:12 + | +LL | let _: &'a A = &x; + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-98170.stderr b/src/test/ui/nll/issue-98170.stderr index 0d17365e71b4a..fdf950075098b 100644 --- a/src/test/ui/nll/issue-98170.stderr +++ b/src/test/ui/nll/issue-98170.stderr @@ -6,17 +6,19 @@ LL | impl MyStruct<'_> { LL | pub fn new<'a>(field: &'a [u32]) -> MyStruct<'a> { | -- lifetime `'a` defined here LL | Self { field } - | ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` + | ^^^^ type annotation requires that `'a` must outlive `'1` + | + = help: consider replacing `Self` with `MyStruct` error: lifetime may not live long enough - --> $DIR/issue-98170.rs:7:16 + --> $DIR/issue-98170.rs:7:9 | LL | impl MyStruct<'_> { | -- lifetime `'1` appears in the `impl`'s self type LL | pub fn new<'a>(field: &'a [u32]) -> MyStruct<'a> { | -- lifetime `'a` defined here LL | Self { field } - | ^^^^^ this usage requires that `'a` must outlive `'1` + | ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` error: lifetime may not live long enough --> $DIR/issue-98170.rs:19:9 @@ -27,10 +29,12 @@ LL | impl<'a> Trait<'a> for MyStruct<'_> { | lifetime `'a` defined here LL | fn new(field: &'a [u32]) -> MyStruct<'a> { LL | Self { field } - | ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` + | ^^^^ type annotation requires that `'a` must outlive `'1` + | + = help: consider replacing `Self` with `MyStruct` error: lifetime may not live long enough - --> $DIR/issue-98170.rs:19:16 + --> $DIR/issue-98170.rs:19:9 | LL | impl<'a> Trait<'a> for MyStruct<'_> { | -- -- lifetime `'1` appears in the `impl`'s self type @@ -38,7 +42,7 @@ LL | impl<'a> Trait<'a> for MyStruct<'_> { | lifetime `'a` defined here LL | fn new(field: &'a [u32]) -> MyStruct<'a> { LL | Self { field } - | ^^^^^ this usage requires that `'a` must outlive `'1` + | ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` error: aborting due to 4 previous errors diff --git a/src/test/ui/nll/issue-98589-closures-relate-named-regions.stderr b/src/test/ui/nll/issue-98589-closures-relate-named-regions.stderr index 6def5602e70b3..983e0dd817fdc 100644 --- a/src/test/ui/nll/issue-98589-closures-relate-named-regions.stderr +++ b/src/test/ui/nll/issue-98589-closures-relate-named-regions.stderr @@ -1,12 +1,12 @@ error: lifetime may not live long enough - --> $DIR/issue-98589-closures-relate-named-regions.rs:10:5 + --> $DIR/issue-98589-closures-relate-named-regions.rs:10:10 | LL | fn test_early_early<'a: 'a, 'b: 'b>() { | -- -- lifetime `'b` defined here | | | lifetime `'a` defined here LL | || { None::<&'a &'b ()>; }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` @@ -18,7 +18,7 @@ LL | fn test_early_late<'a: 'a, 'b>() { | | | lifetime `'a` defined here LL | || { None::<&'a &'b ()>; }; - | ^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` @@ -30,7 +30,7 @@ LL | fn test_late_late<'a, 'b>() { | | | lifetime `'a` defined here LL | || { None::<&'a &'b ()>; }; - | ^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` diff --git a/src/test/ui/nll/relate_tys/fn-subtype.stderr b/src/test/ui/nll/relate_tys/fn-subtype.stderr index 21073647ea77b..58e1f5fb2c739 100644 --- a/src/test/ui/nll/relate_tys/fn-subtype.stderr +++ b/src/test/ui/nll/relate_tys/fn-subtype.stderr @@ -5,7 +5,7 @@ LL | let y: for<'a> fn(&'a ()) = x; | ^ one type is more general than the other | = note: expected fn pointer `for<'a> fn(&'a ())` - found fn pointer `fn(&())` + found fn pointer `fn(&'static ())` error: aborting due to previous error diff --git a/src/test/ui/nll/relate_tys/universe-violation.stderr b/src/test/ui/nll/relate_tys/universe-violation.stderr index 6f38154e37927..06b033fbc918b 100644 --- a/src/test/ui/nll/relate_tys/universe-violation.stderr +++ b/src/test/ui/nll/relate_tys/universe-violation.stderr @@ -5,7 +5,7 @@ LL | let b: fn(&u32) -> &u32 = a; | ^ one type is more general than the other | = note: expected fn pointer `for<'r> fn(&'r u32) -> &'r u32` - found fn pointer `fn(&u32) -> &u32` + found fn pointer `fn(&'static u32) -> &'static u32` error: aborting due to previous error diff --git a/src/test/ui/nll/relate_tys/var-appears-twice.stderr b/src/test/ui/nll/relate_tys/var-appears-twice.stderr index d032ce6f2132c..ca34d5fea9c1c 100644 --- a/src/test/ui/nll/relate_tys/var-appears-twice.stderr +++ b/src/test/ui/nll/relate_tys/var-appears-twice.stderr @@ -2,9 +2,10 @@ error[E0597]: `b` does not live long enough --> $DIR/var-appears-twice.rs:20:38 | LL | let x: DoubleCell<_> = make_cell(&b); - | ------------- ^^ borrowed value does not live long enough - | | - | type annotation requires that `b` is borrowed for `'static` + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `b` is borrowed for `'static` ... LL | } | - `b` dropped here while still borrowed diff --git a/src/test/ui/nll/type-test-universe.stderr b/src/test/ui/nll/type-test-universe.stderr index 242486c360a80..0a9f1384a9c32 100644 --- a/src/test/ui/nll/type-test-universe.stderr +++ b/src/test/ui/nll/type-test-universe.stderr @@ -10,7 +10,7 @@ error: lifetime may not live long enough LL | fn test2<'a>() { | -- lifetime `'a` defined here LL | outlives_forall::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-brace-enums.stderr b/src/test/ui/nll/user-annotations/adt-brace-enums.stderr index 253e382511045..8a143ed9579d5 100644 --- a/src/test/ui/nll/user-annotations/adt-brace-enums.stderr +++ b/src/test/ui/nll/user-annotations/adt-brace-enums.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-enums.rs:25:48 | LL | SomeEnum::SomeVariant::<&'static u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'static` + | ------------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-enums.rs:25:5 + | +LL | SomeEnum::SomeVariant::<&'static u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-enums.rs:30:43 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here LL | let c = 66; LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | -------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-enums.rs:30:5 + | +LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-enums.rs:40:47 @@ -30,12 +40,17 @@ LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | -------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | }; | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-enums.rs:40:9 + | +LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-brace-structs.stderr b/src/test/ui/nll/user-annotations/adt-brace-structs.stderr index 8b9d1705df6ad..52a703037b612 100644 --- a/src/test/ui/nll/user-annotations/adt-brace-structs.stderr +++ b/src/test/ui/nll/user-annotations/adt-brace-structs.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-structs.rs:23:37 | LL | SomeStruct::<&'static u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'static` + | -------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-structs.rs:23:5 + | +LL | SomeStruct::<&'static u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-structs.rs:28:32 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here LL | let c = 66; LL | SomeStruct::<&'a u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | --------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-structs.rs:28:5 + | +LL | SomeStruct::<&'a u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-brace-structs.rs:38:36 @@ -30,12 +40,17 @@ LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... LL | SomeStruct::<&'a u32> { t: &c }; - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | --------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | }; | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-brace-structs.rs:38:9 + | +LL | SomeStruct::<&'a u32> { t: &c }; + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr index ee332278c30f5..3ab7ce6263473 100644 --- a/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr +++ b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -1,14 +1,19 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:33:41 | -LL | / combine( -LL | | SomeEnum::SomeVariant(Cell::new(&c)), - | | ^^ borrowed value does not live long enough -LL | | SomeEnum::SomeOtherVariant::>, -LL | | ); - | |_____- argument requires that `c` is borrowed for `'static` -LL | } - | - `c` dropped here while still borrowed +LL | SomeEnum::SomeVariant(Cell::new(&c)), + | ^^ borrowed value does not live long enough +LL | SomeEnum::SomeOtherVariant::>, + | ------------------------------------------------ type annotation requires that `c` is borrowed for `'static` +LL | ); +LL | } + | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-nullary-enums.rs:34:9 + | +LL | SomeEnum::SomeOtherVariant::>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:41:41 @@ -17,13 +22,18 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here ... LL | SomeEnum::SomeVariant(Cell::new(&c)), - | ----------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` -... + | ^^ borrowed value does not live long enough +LL | SomeEnum::SomeOtherVariant::>, + | ------------------------------------------- type annotation requires that `c` is borrowed for `'a` +LL | ); LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-nullary-enums.rs:42:9 + | +LL | SomeEnum::SomeOtherVariant::>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:54:45 @@ -34,10 +44,15 @@ LL | let _closure = || { | - `c` dropped here while still borrowed ... LL | SomeEnum::SomeVariant(Cell::new(&c)), - | ----------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ^^ borrowed value does not live long enough +LL | SomeEnum::SomeOtherVariant::>, + | ------------------------------------------- type annotation requires that `c` is borrowed for `'a` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-nullary-enums.rs:55:13 + | +LL | SomeEnum::SomeOtherVariant::>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr b/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr index 2fa7042631d21..7d478f42c6f0c 100644 --- a/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr +++ b/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-enums.rs:28:43 | LL | SomeEnum::SomeVariant::<&'static u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'static` + | ------------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-enums.rs:28:5 + | +LL | SomeEnum::SomeVariant::<&'static u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-enums.rs:33:38 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here LL | let c = 66; LL | SomeEnum::SomeVariant::<&'a u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | -------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-enums.rs:33:5 + | +LL | SomeEnum::SomeVariant::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-enums.rs:43:42 @@ -30,12 +40,17 @@ LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... LL | SomeEnum::SomeVariant::<&'a u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | -------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | }; | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-enums.rs:43:9 + | +LL | SomeEnum::SomeVariant::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr index 95bbd62c4fb0d..228867767d30a 100644 --- a/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr @@ -1,27 +1,37 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct-calls.rs:27:7 | +LL | let f = SomeStruct::<&'static u32>; + | -------------------------- type annotation requires that `c` is borrowed for `'static` LL | f(&c); - | --^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'static` + | ^^ borrowed value does not live long enough LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct-calls.rs:26:13 + | +LL | let f = SomeStruct::<&'static u32>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct-calls.rs:33:7 | LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here -... +LL | let c = 66; +LL | let f = SomeStruct::<&'a u32>; + | --------------------- type annotation requires that `c` is borrowed for `'a` LL | f(&c); - | --^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ^^ borrowed value does not live long enough LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct-calls.rs:32:13 + | +LL | let f = SomeStruct::<&'a u32>; + | ^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct-calls.rs:45:11 @@ -30,12 +40,17 @@ LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here LL | let _closure = || { | - `c` dropped here while still borrowed -... +LL | let c = 66; +LL | let f = SomeStruct::<&'a u32>; + | --------------------- type annotation requires that `c` is borrowed for `'a` LL | f(&c); - | --^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ^^ borrowed value does not live long enough + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct-calls.rs:44:17 + | +LL | let f = SomeStruct::<&'a u32>; + | ^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct-calls.rs:53:11 diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr b/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr index 76b5252258c7b..fd334b682f6ed 100644 --- a/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct.rs:23:32 | LL | SomeStruct::<&'static u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'static` + | -------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct.rs:23:5 + | +LL | SomeStruct::<&'static u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct.rs:28:27 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here LL | let c = 66; LL | SomeStruct::<&'a u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | --------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct.rs:28:5 + | +LL | SomeStruct::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/adt-tuple-struct.rs:38:31 @@ -30,12 +40,17 @@ LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... LL | SomeStruct::<&'a u32>(&c); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `c` is borrowed for `'a` + | --------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | }; | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/adt-tuple-struct.rs:38:9 + | +LL | SomeStruct::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr b/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr index 4599d04e7e230..eb1ac676d4f9c 100644 --- a/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr +++ b/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr @@ -8,6 +8,12 @@ LL | let y: &u32 = (&x) as &'static u32; | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/cast_static_lifetime.rs:5:19 + | +LL | let y: &u32 = (&x) as &'static u32; + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/closure-substs.rs b/src/test/ui/nll/user-annotations/closure-substs.rs index f7af54e8df44a..e0fcf0f56a378 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.rs +++ b/src/test/ui/nll/user-annotations/closure-substs.rs @@ -17,14 +17,16 @@ fn foo1() { fn bar<'a>() { // Here `x` is free in the closure sig: |x: &'a i32, b: fn(&'static i32)| { - b(x); //~ ERROR lifetime may not live long enough + //~^ ERROR lifetime may not live long enough + b(x); }; } fn bar1() { // Here `x` is bound in the closure sig: |x: &i32, b: fn(&'static i32)| { - b(x); //~ ERROR borrowed data escapes outside of closure + //~^ ERROR lifetime may not live long enough + b(x); }; } diff --git a/src/test/ui/nll/user-annotations/closure-substs.stderr b/src/test/ui/nll/user-annotations/closure-substs.stderr index 1e8de4ba90541..39b29ac518f67 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.stderr +++ b/src/test/ui/nll/user-annotations/closure-substs.stderr @@ -16,27 +16,24 @@ LL | return x; | ^ returning this value requires that `'1` must outlive `'static` error: lifetime may not live long enough - --> $DIR/closure-substs.rs:20:9 + --> $DIR/closure-substs.rs:19:18 | LL | fn bar<'a>() { | -- lifetime `'a` defined here -... -LL | b(x); - | ^^^^ argument requires that `'a` must outlive `'static` +LL | // Here `x` is free in the closure sig: +LL | |x: &'a i32, b: fn(&'static i32)| { + | ^ type annotation requires that `'a` must outlive `'static` -error[E0521]: borrowed data escapes outside of closure - --> $DIR/closure-substs.rs:27:9 +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:27:15 | LL | |x: &i32, b: fn(&'static i32)| { - | - - let's call the lifetime of this reference `'1` - | | - | `x` is a reference that is only valid in the closure body -LL | b(x); - | ^^^^ + | - ^ type annotation requires that `'1` must outlive `'static` | | - | `x` escapes the closure body here - | argument requires that `'1` must outlive `'static` + | let's call the lifetime of this reference `'1` +LL | +LL | b(x); + | ---- because of argument here error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/user-annotations/fns.stderr b/src/test/ui/nll/user-annotations/fns.stderr index bd4d121d56914..4fb6ed34ef06b 100644 --- a/src/test/ui/nll/user-annotations/fns.stderr +++ b/src/test/ui/nll/user-annotations/fns.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/fns.rs:23:29 | LL | some_fn::<&'static u32>(&c); - | ------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'static` + | ----------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/fns.rs:23:5 + | +LL | some_fn::<&'static u32>(&c); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/fns.rs:28:24 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here LL | let c = 66; LL | some_fn::<&'a u32>(&c); - | -------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ------------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/fns.rs:28:5 + | +LL | some_fn::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/fns.rs:38:28 @@ -32,10 +42,15 @@ LL | let _closure = || { | - `c` dropped here while still borrowed LL | let c = 66; LL | some_fn::<&'a u32>(&c); - | -------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ------------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/fns.rs:38:9 + | +LL | some_fn::<&'a u32>(&c); + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr b/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr index ffbfc40f5372e..a4d26a5642d01 100644 --- a/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr +++ b/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr @@ -4,7 +4,7 @@ error: lifetime may not live long enough LL | fn non_wf_associated_const<'a>(x: i32) { | -- lifetime `'a` defined here LL | A::<'a>::IC; - | ^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/issue-54124.stderr b/src/test/ui/nll/user-annotations/issue-54124.stderr index 2556af2dd7de2..486a6a986b035 100644 --- a/src/test/ui/nll/user-annotations/issue-54124.stderr +++ b/src/test/ui/nll/user-annotations/issue-54124.stderr @@ -6,7 +6,7 @@ LL | fn test<'a>() { LL | let _:fn(&()) = |_:&'a ()| {}; | ^ - let's call the lifetime of this reference `'1` | | - | requires that `'1` must outlive `'a` + | type annotation requires that `'1` must outlive `'a` error: lifetime may not live long enough --> $DIR/issue-54124.rs:2:22 @@ -14,7 +14,7 @@ error: lifetime may not live long enough LL | fn test<'a>() { | -- lifetime `'a` defined here LL | let _:fn(&()) = |_:&'a ()| {}; - | ^ requires that `'a` must outlive `'static` + | ^ type annotation requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/method-call.stderr b/src/test/ui/nll/user-annotations/method-call.stderr index fcaeb465d140e..5ef74c4bfcdef 100644 --- a/src/test/ui/nll/user-annotations/method-call.stderr +++ b/src/test/ui/nll/user-annotations/method-call.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/method-call.rs:36:34 | LL | a.method::<&'static u32>(b, &c); - | -----------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'static` + | ---------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-call.rs:36:7 + | +LL | a.method::<&'static u32>(b, &c); + | ^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/method-call.rs:43:29 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here ... LL | a.method::<&'a u32>(b, &c); - | ------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ----------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-call.rs:43:7 + | +LL | a.method::<&'a u32>(b, &c); + | ^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/method-call.rs:57:33 @@ -33,10 +43,15 @@ LL | let _closure = || { | - `c` dropped here while still borrowed LL | let c = 66; LL | a.method::<&'a u32>(b, &c); - | ------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ----------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-call.rs:57:11 + | +LL | a.method::<&'a u32>(b, &c); + | ^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/method-ufcs-1.stderr b/src/test/ui/nll/user-annotations/method-ufcs-1.stderr index 962ddfd2bd151..208ad5277c7a6 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-1.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-1.stderr @@ -1,13 +1,18 @@ error[E0597]: `a` does not live long enough --> $DIR/method-ufcs-1.rs:30:7 | +LL | let x = <&'static u32 as Bazoom<_>>::method; + | ----------------------------------- type annotation requires that `a` is borrowed for `'static` LL | x(&a, b, c); - | --^^------- - | | | - | | borrowed value does not live long enough - | argument requires that `a` is borrowed for `'static` + | ^^ borrowed value does not live long enough LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-1.rs:29:13 + | +LL | let x = <&'static u32 as Bazoom<_>>::method; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `a` does not live long enough --> $DIR/method-ufcs-1.rs:37:36 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here ... LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); - | -------------------------------^^------- - | | | - | | borrowed value does not live long enough - | argument requires that `a` is borrowed for `'a` + | ------------------------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `a` is borrowed for `'a` LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-1.rs:37:5 + | +LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `a` does not live long enough --> $DIR/method-ufcs-1.rs:51:41 @@ -33,13 +43,18 @@ LL | let _closure = || { | -- value captured here LL | let c = 66; LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); - | --------------------------------^------- - | | | - | | borrowed value does not live long enough - | argument requires that `a` is borrowed for `'a` + | ------------------------------ ^ borrowed value does not live long enough + | | + | type annotation requires that `a` is borrowed for `'a` LL | }; LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-1.rs:51:9 + | +LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/method-ufcs-2.stderr b/src/test/ui/nll/user-annotations/method-ufcs-2.stderr index 63d59905e1c38..581cb2ee6c848 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-2.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-2.stderr @@ -1,13 +1,18 @@ error[E0597]: `a` does not live long enough --> $DIR/method-ufcs-2.rs:30:7 | +LL | let x = <&'static u32 as Bazoom<_>>::method; + | ----------------------------------- type annotation requires that `a` is borrowed for `'static` LL | x(&a, b, c); - | --^^------- - | | | - | | borrowed value does not live long enough - | argument requires that `a` is borrowed for `'static` + | ^^ borrowed value does not live long enough LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-2.rs:29:13 + | +LL | let x = <&'static u32 as Bazoom<_>>::method; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `b` does not live long enough --> $DIR/method-ufcs-2.rs:37:39 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here ... LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); - | ----------------------------------^^---- - | | | - | | borrowed value does not live long enough - | argument requires that `b` is borrowed for `'a` + | ------------------------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `b` is borrowed for `'a` LL | } | - `b` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-2.rs:37:5 + | +LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `b` does not live long enough --> $DIR/method-ufcs-2.rs:51:44 @@ -33,13 +43,18 @@ LL | let _closure = || { | -- value captured here LL | let c = 66; LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); - | -----------------------------------^---- - | | | - | | borrowed value does not live long enough - | argument requires that `b` is borrowed for `'a` + | ------------------------------ ^ borrowed value does not live long enough + | | + | type annotation requires that `b` is borrowed for `'a` LL | }; LL | } | - `b` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-2.rs:51:9 + | +LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/method-ufcs-3.stderr b/src/test/ui/nll/user-annotations/method-ufcs-3.stderr index 328dde9805aae..109a861587ee0 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-3.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-3.stderr @@ -2,12 +2,17 @@ error[E0597]: `c` does not live long enough --> $DIR/method-ufcs-3.rs:36:53 | LL | <_ as Bazoom<_>>::method::<&'static u32>(&a, b, &c); - | ------------------------------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'static` + | ---------------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'static` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-3.rs:36:5 + | +LL | <_ as Bazoom<_>>::method::<&'static u32>(&a, b, &c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/method-ufcs-3.rs:43:48 @@ -16,12 +21,17 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { | -- lifetime `'a` defined here ... LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); - | -------------------------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ----------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` LL | } | - `c` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-3.rs:43:5 + | +LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `c` does not live long enough --> $DIR/method-ufcs-3.rs:57:52 @@ -33,10 +43,15 @@ LL | let _closure = || { | - `c` dropped here while still borrowed LL | let c = 66; LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); - | -------------------------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'a` + | ----------------------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `c` is borrowed for `'a` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-3.rs:57:9 + | +LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr index 94861babd6f32..48aa37ef21774 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr @@ -5,13 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = A::<'a>::new(&v, 22); - | -------------^^----- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` LL | LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-1.rs:14:13 + | +LL | let x = A::<'a>::new(&v, 22); + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr index 06f20d9b23559..42dd20abd3eaf 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr @@ -5,13 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = A::<'a>::new::<&'a u32>(&v, &v); - | ------------------------^^----- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ----------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` ... LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-2.rs:14:13 + | +LL | let x = A::<'a>::new::<&'a u32>(&v, &v); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `v` does not live long enough --> $DIR/method-ufcs-inherent-2.rs:14:41 @@ -20,13 +25,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = A::<'a>::new::<&'a u32>(&v, &v); - | ----------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ----------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` ... LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-2.rs:14:13 + | +LL | let x = A::<'a>::new::<&'a u32>(&v, &v); + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr index 4ad61dc81c493..dd17556cff026 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr @@ -5,13 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = >::new(&v, 22); - | -------------^^----- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` LL | LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-3.rs:14:13 + | +LL | let x = >::new(&v, 22); + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr index 0f83e99cdfb92..c48e633675b4d 100644 --- a/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr @@ -5,13 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = >::new::<&'a u32>(&v, &v); - | ------------------------^^----- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ----------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` ... LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-4.rs:15:13 + | +LL | let x = >::new::<&'a u32>(&v, &v); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `v` does not live long enough --> $DIR/method-ufcs-inherent-4.rs:15:41 @@ -20,13 +25,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let v = 22; LL | let x = >::new::<&'a u32>(&v, &v); - | ----------------------------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `v` is borrowed for `'a` + | ----------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `v` is borrowed for `'a` ... LL | } | - `v` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/method-ufcs-inherent-4.rs:15:13 + | +LL | let x = >::new::<&'a u32>(&v, &v); + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/normalization.stderr b/src/test/ui/nll/user-annotations/normalization.stderr index 4c7893789a535..6e2639822cf50 100644 --- a/src/test/ui/nll/user-annotations/normalization.stderr +++ b/src/test/ui/nll/user-annotations/normalization.stderr @@ -7,6 +7,12 @@ LL | let b: <() as Foo>::Out = &a; | type annotation requires that `a` is borrowed for `'static` LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/normalization.rs:9:12 + | +LL | let b: <() as Foo>::Out = &a; + | ^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr index a97e7a9fd46fc..0b8fdb3189e6a 100644 --- a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr @@ -8,6 +8,12 @@ LL | let Foo::Bar::<'static> { field: _z } = foo; | --------------------------------- type annotation requires that `y` is borrowed for `'static` LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_brace_enum_variant.rs:9:9 + | +LL | let Foo::Bar::<'static> { field: _z } = foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `y` does not live long enough --> $DIR/pattern_substs_on_brace_enum_variant.rs:14:33 @@ -20,6 +26,12 @@ LL | Foo::Bar::<'static> { field: _z } => { ... LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_brace_enum_variant.rs:17:9 + | +LL | Foo::Bar::<'static> { field: _z } => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr index 408d7c2a5e2a5..e35cf96dd9a00 100644 --- a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr @@ -8,6 +8,12 @@ LL | let Foo::<'static> { field: _z } = foo; | ---------------------------- type annotation requires that `y` is borrowed for `'static` LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_brace_struct.rs:7:9 + | +LL | let Foo::<'static> { field: _z } = foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `y` does not live long enough --> $DIR/pattern_substs_on_brace_struct.rs:12:28 @@ -20,6 +26,12 @@ LL | Foo::<'static> { field: _z } => { ... LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_brace_struct.rs:15:9 + | +LL | Foo::<'static> { field: _z } => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr index 920c906f63a58..50452cfecb97f 100644 --- a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr @@ -8,6 +8,12 @@ LL | let Foo::Bar::<'static>(_z) = foo; | ----------------------- type annotation requires that `y` is borrowed for `'static` LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_tuple_enum_variant.rs:9:9 + | +LL | let Foo::Bar::<'static>(_z) = foo; + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `y` does not live long enough --> $DIR/pattern_substs_on_tuple_enum_variant.rs:14:24 @@ -20,6 +26,12 @@ LL | Foo::Bar::<'static>(_z) => { ... LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_tuple_enum_variant.rs:17:9 + | +LL | Foo::Bar::<'static>(_z) => { + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr index 3f01638d84757..179f6f59b1589 100644 --- a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr @@ -8,6 +8,12 @@ LL | let Foo::<'static>(_z) = foo; | ------------------ type annotation requires that `y` is borrowed for `'static` LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_tuple_struct.rs:7:9 + | +LL | let Foo::<'static>(_z) = foo; + | ^^^^^^^^^^^^^^^^^^ error[E0597]: `y` does not live long enough --> $DIR/pattern_substs_on_tuple_struct.rs:12:19 @@ -20,6 +26,12 @@ LL | Foo::<'static>(_z) => { ... LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/pattern_substs_on_tuple_struct.rs:15:9 + | +LL | Foo::<'static>(_z) => { + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs index 1f635d7f50cda..a5c207ab4f84a 100644 --- a/src/test/ui/nll/user-annotations/patterns.rs +++ b/src/test/ui/nll/user-annotations/patterns.rs @@ -129,8 +129,8 @@ fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 { } fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { - let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR - y + let (y, _z): (&'static u32, u32) = (x, 44); + y //~ ERROR } fn main() { } diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr index 60d6e6db36326..addc14bac64ac 100644 --- a/src/test/ui/nll/user-annotations/patterns.stderr +++ b/src/test/ui/nll/user-annotations/patterns.stderr @@ -7,6 +7,12 @@ LL | y = &x; | ^^ borrowed value does not live long enough LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:5:12 + | +LL | let y: &'static u32; + | ^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:14:9 @@ -17,6 +23,12 @@ LL | y = &x; | ^^ borrowed value does not live long enough LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:13:17 + | +LL | let (y, z): (&'static u32, &'static u32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:20:13 @@ -28,6 +40,12 @@ LL | let ref z: &'static u32 = y; LL | **z LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:21:16 + | +LL | let ref z: &'static u32 = y; + | ^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:39:9 @@ -38,14 +56,21 @@ LL | y = &x; | ^^ borrowed value does not live long enough LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:38:30 + | +LL | let Single { value: y }: Single<&'static u32>; + | ^^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:51:10 | -LL | let Single2 { value: mut _y }: Single2; - | ------------------ type annotation requires that `x` is borrowed for `'static` LL | _y = &x; - | ^^ borrowed value does not live long enough + | -----^^ + | | | + | | borrowed value does not live long enough + | assignment requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed @@ -58,6 +83,12 @@ LL | let y: &'static u32 = &x; | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:56:12 + | +LL | let y: &'static u32 = &x; + | ^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:61:27 @@ -69,6 +100,12 @@ LL | let _: &'static u32 = &x; ... LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:61:12 + | +LL | let _: &'static u32 = &x; + | ^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/patterns.rs:63:41 @@ -78,6 +115,12 @@ LL | let _: Vec<&'static String> = vec![&String::new()]; | | | | | creates a temporary which is freed while still in use | type annotation requires that borrow lasts for `'static` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:63:12 + | +LL | let _: Vec<&'static String> = vec![&String::new()]; + | ^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/patterns.rs:66:52 @@ -87,6 +130,12 @@ LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); | | | | | creates a temporary which is freed while still in use | type annotation requires that borrow lasts for `'static` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:66:17 + | +LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0716]: temporary value dropped while borrowed --> $DIR/patterns.rs:69:53 @@ -96,6 +145,12 @@ LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); | | | | | creates a temporary which is freed while still in use | type annotation requires that borrow lasts for `'static` + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:69:18 + | +LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:75:40 @@ -106,6 +161,12 @@ LL | let (_, _): (&'static u32, u32) = (&x, 44); | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:75:17 + | +LL | let (_, _): (&'static u32, u32) = (&x, 44); + | ^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:80:40 @@ -116,6 +177,12 @@ LL | let (y, _): (&'static u32, u32) = (&x, 44); | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:80:17 + | +LL | let (y, _): (&'static u32, u32) = (&x, 44); + | ^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:85:69 @@ -126,6 +193,12 @@ LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:85:30 + | +LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; + | ^^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:90:69 @@ -136,6 +209,12 @@ LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:90:30 + | +LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; + | ^^^^^^^^^^^^^^^^^^^^ error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:98:17 @@ -147,6 +226,12 @@ LL | value1: &x, ... LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/patterns.rs:97:42 + | +LL | let Double { value1: _, value2: _ }: Double<&'static u32> = Double { + | ^^^^^^^^^^^^^^^^^^^^ error: lifetime may not live long enough --> $DIR/patterns.rs:111:5 @@ -176,12 +261,13 @@ LL | y | ^ returning this value requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/patterns.rs:132:18 + --> $DIR/patterns.rs:133:5 | LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here LL | let (y, _z): (&'static u32, u32) = (x, 44); - | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` +LL | y + | ^ returning this value requires that `'a` must outlive `'static` error: aborting due to 19 previous errors diff --git a/src/test/ui/nll/user-annotations/promoted-annotation.stderr b/src/test/ui/nll/user-annotations/promoted-annotation.stderr index cb99a6a369d0b..7c0f182f46702 100644 --- a/src/test/ui/nll/user-annotations/promoted-annotation.stderr +++ b/src/test/ui/nll/user-annotations/promoted-annotation.stderr @@ -5,12 +5,18 @@ LL | fn foo<'a>() { | -- lifetime `'a` defined here LL | let x = 0; LL | let f = &drop::<&'a i32>; - | ---------------- assignment requires that `x` is borrowed for `'a` + | --------------- type annotation requires that `x` is borrowed for `'a` LL | f(&x); | ^^ borrowed value does not live long enough LL | LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/promoted-annotation.rs:5:14 + | +LL | let f = &drop::<&'a i32>; + | ^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/self-diagnostics.rs b/src/test/ui/nll/user-annotations/self-diagnostics.rs new file mode 100644 index 0000000000000..d4cda8d762f1d --- /dev/null +++ b/src/test/ui/nll/user-annotations/self-diagnostics.rs @@ -0,0 +1,73 @@ +// Some subtle cases where `Self` imposes unnecessary lifetime constraints. +// Make sure we detect these cases and suggest a proper fix. + +// check-fail + +struct S<'a>(&'a str); + +impl S<'_> { + const CLOSURE_ARGS: () = { + |s: &str| { + Self(s); + //~^ ERROR lifetime may not live long enough + }; + }; + + fn closure_body() { + let closure = |s| { + Self(s); + }; + closure(&String::new()); + //~^ ERROR temporary value dropped while borrowed + } +} + +impl<'x> S<'x> { + fn static_method(_: &'x str) {} + + // FIXME suggesting replacing `Self` is better than the current one. + fn test3(s: &str) { + let _ = || { + Self::static_method(s); + //~^ ERROR explicit lifetime required in the type of `s` + }; + } + + fn test_named_lt<'y>(s: &'y str) { + let _ = || { + Self::static_method(s); + //~^ ERROR lifetime may not live long enough + }; + } +} + +impl<'x> S<'x> { + fn test7(s: String) { + s.split('/') + //~^ ERROR `s` does not live long enough + .map(|s| Self(s)) + .collect::>(); + } + + // FIXME there is no suggestion here because we don't have a + // correct span for closure argument annotations. + fn test8(s: String) { + s.split('/') + //~^ ERROR `s` does not live long enough + .map(|s| S(s)) + .map(|_: Self| {}) + .collect::>(); + } +} + +impl<'x> S<'x> { + fn eq(self, _: T) {} + + // test annotations on method call. + fn method_call<'c>(self, s: &'c str) { + self.eq::(S(s)); // remove Self + //~^ ERROR lifetime may not live long enough + } +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/self-diagnostics.stderr b/src/test/ui/nll/user-annotations/self-diagnostics.stderr new file mode 100644 index 0000000000000..eb9aceb75d04f --- /dev/null +++ b/src/test/ui/nll/user-annotations/self-diagnostics.stderr @@ -0,0 +1,119 @@ +error: lifetime may not live long enough + --> $DIR/self-diagnostics.rs:11:13 + | +LL | impl S<'_> { + | -- lifetime `'2` appears in the `impl`'s self type +LL | const CLOSURE_ARGS: () = { +LL | |s: &str| { + | - let's call the lifetime of this reference `'1` +LL | Self(s); + | ^^^^ type annotation requires that `'1` must outlive `'2` + | + = help: consider replacing `Self` with `S` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/self-diagnostics.rs:20:18 + | +LL | impl S<'_> { + | -- lifetime `'1` appears in the `impl`'s self type +... +LL | Self(s); + | ---- type annotation requires that borrow lasts for `'1` +LL | }; +LL | closure(&String::new()); + | ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | + | creates a temporary which is freed while still in use + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/self-diagnostics.rs:18:13 + | +LL | Self(s); + | ^^^^ + = help: consider replacing `Self` with `S` + +error[E0621]: explicit lifetime required in the type of `s` + --> $DIR/self-diagnostics.rs:31:13 + | +LL | fn test3(s: &str) { + | ---- help: add explicit lifetime `'x` to the type of `s`: `&'x str` +LL | let _ = || { +LL | Self::static_method(s); + | ^^^^^^^^^^^^^^^^^^^ lifetime `'x` required + +error: lifetime may not live long enough + --> $DIR/self-diagnostics.rs:38:13 + | +LL | impl<'x> S<'x> { + | -- lifetime `'x` defined here +... +LL | fn test_named_lt<'y>(s: &'y str) { + | -- lifetime `'y` defined here +LL | let _ = || { +LL | Self::static_method(s); + | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'y` must outlive `'x` + | + = help: consider replacing `Self` with `S` + = help: consider adding the following bound: `'y: 'x` + +error[E0597]: `s` does not live long enough + --> $DIR/self-diagnostics.rs:46:9 + | +LL | impl<'x> S<'x> { + | -- lifetime `'x` defined here +LL | fn test7(s: String) { +LL | s.split('/') + | ^^^^^^^^^^^^ borrowed value does not live long enough +LL | +LL | .map(|s| Self(s)) + | ---- type annotation requires that `s` is borrowed for `'x` +LL | .collect::>(); +LL | } + | - `s` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/self-diagnostics.rs:48:22 + | +LL | .map(|s| Self(s)) + | ^^^^ + = help: consider replacing `Self` with `S` + +error[E0597]: `s` does not live long enough + --> $DIR/self-diagnostics.rs:55:9 + | +LL | impl<'x> S<'x> { + | -- lifetime `'x` defined here +... +LL | s.split('/') + | ^^^^^^^^^^^^ borrowed value does not live long enough +... +LL | .map(|_: Self| {}) + | - type annotation requires that `s` is borrowed for `'x` +LL | .collect::>(); +LL | } + | - `s` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/self-diagnostics.rs:58:19 + | +LL | .map(|_: Self| {}) + | ^ + +error: lifetime may not live long enough + --> $DIR/self-diagnostics.rs:68:14 + | +LL | impl<'x> S<'x> { + | -- lifetime `'x` defined here +... +LL | fn method_call<'c>(self, s: &'c str) { + | -- lifetime `'c` defined here +LL | self.eq::(S(s)); // remove Self + | ^^^^^^^^^^ type annotation requires that `'c` must outlive `'x` + | + = help: consider replacing `Self` with `S` + = help: consider adding the following bound: `'c: 'x` + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0597, E0621, E0716. +For more information about an error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/self-issue-100725.rs b/src/test/ui/nll/user-annotations/self-issue-100725.rs new file mode 100644 index 0000000000000..900187308d891 --- /dev/null +++ b/src/test/ui/nll/user-annotations/self-issue-100725.rs @@ -0,0 +1,26 @@ +// Make sure we suggest replacing `Self` with `Bigger` to make it pass. + +// check-fail + +pub struct Bigger<'a> { + _marker: &'a (), +} +impl<'a> Bigger<'a> { + pub fn get_addr(byte_list: &'a mut Vec) -> &mut u8 { + byte_list.iter_mut().find_map(|item| { + Self::other(item); // replace with `Bigger` + Some(()) + }); + + byte_list.push(0); + //~^ ERROR cannot borrow `*byte_list` as mutable more than once at a time + byte_list.last_mut().unwrap() + //~^ ERROR cannot borrow `*byte_list` as mutable more than once at a time + } + + pub fn other<'b: 'a>(_value: &'b mut u8) { + todo!() + } +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/self-issue-100725.stderr b/src/test/ui/nll/user-annotations/self-issue-100725.stderr new file mode 100644 index 0000000000000..c648ce00bef93 --- /dev/null +++ b/src/test/ui/nll/user-annotations/self-issue-100725.stderr @@ -0,0 +1,45 @@ +error[E0499]: cannot borrow `*byte_list` as mutable more than once at a time + --> $DIR/self-issue-100725.rs:15:9 + | +LL | impl<'a> Bigger<'a> { + | -- lifetime `'a` defined here +LL | pub fn get_addr(byte_list: &'a mut Vec) -> &mut u8 { +LL | byte_list.iter_mut().find_map(|item| { + | -------------------- first mutable borrow occurs here +LL | Self::other(item); // replace with `Bigger` + | ----------- type annotation requires that `*byte_list` is borrowed for `'a` +... +LL | byte_list.push(0); + | ^^^^^^^^^^^^^^^^^ second mutable borrow occurs here + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/self-issue-100725.rs:11:13 + | +LL | Self::other(item); // replace with `Bigger` + | ^^^^^^^^^^^ + = help: consider replacing `Self` with `Bigger` + +error[E0499]: cannot borrow `*byte_list` as mutable more than once at a time + --> $DIR/self-issue-100725.rs:17:9 + | +LL | impl<'a> Bigger<'a> { + | -- lifetime `'a` defined here +LL | pub fn get_addr(byte_list: &'a mut Vec) -> &mut u8 { +LL | byte_list.iter_mut().find_map(|item| { + | -------------------- first mutable borrow occurs here +LL | Self::other(item); // replace with `Bigger` + | ----------- type annotation requires that `*byte_list` is borrowed for `'a` +... +LL | byte_list.last_mut().unwrap() + | ^^^^^^^^^^^^^^^^^^^^ second mutable borrow occurs here + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/self-issue-100725.rs:11:13 + | +LL | Self::other(item); // replace with `Bigger` + | ^^^^^^^^^^^ + = help: consider replacing `Self` with `Bigger` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr index 133bbef52311d..212bb3c77a6da 100644 --- a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr +++ b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr @@ -8,6 +8,12 @@ LL | let y: &u32 = &x: &'static u32; | type annotation requires that `x` is borrowed for `'static` LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/type_ascription_static_lifetime.rs:6:19 + | +LL | let y: &u32 = &x: &'static u32; + | ^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/regions/issue-28848.stderr b/src/test/ui/regions/issue-28848.stderr index a29dac4c9c87c..f6c17436045f9 100644 --- a/src/test/ui/regions/issue-28848.stderr +++ b/src/test/ui/regions/issue-28848.stderr @@ -6,7 +6,7 @@ LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () { | | | lifetime `'a` defined here LL | Foo::<'a, 'b>::xmute(u) - | ^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` diff --git a/src/test/ui/regions/regions-addr-of-arg.stderr b/src/test/ui/regions/regions-addr-of-arg.stderr index e77289287e536..3092643c6a19d 100644 --- a/src/test/ui/regions/regions-addr-of-arg.stderr +++ b/src/test/ui/regions/regions-addr-of-arg.stderr @@ -7,6 +7,12 @@ LL | let _p: &'static isize = &a; | type annotation requires that `a` is borrowed for `'static` LL | } | - `a` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/regions-addr-of-arg.rs:5:13 + | +LL | let _p: &'static isize = &a; + | ^^^^^^^^^^^^^^ error[E0515]: cannot return reference to function parameter `a` --> $DIR/regions-addr-of-arg.rs:13:5 diff --git a/src/test/ui/regions/regions-addr-of-upvar-self.stderr b/src/test/ui/regions/regions-addr-of-upvar-self.stderr index c16a6f8585b69..bfcd4a5f1aa62 100644 --- a/src/test/ui/regions/regions-addr-of-upvar-self.stderr +++ b/src/test/ui/regions/regions-addr-of-upvar-self.stderr @@ -29,6 +29,12 @@ LL | let p: &'static mut usize = &mut self.food; ... LL | } | - `self` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/regions-addr-of-upvar-self.rs:8:20 + | +LL | let p: &'static mut usize = &mut self.food; + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr b/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr index eea68cc8f1c5b..c556c580e49f0 100644 --- a/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr +++ b/src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr @@ -4,7 +4,7 @@ error: lifetime may not live long enough LL | fn param_not_ok<'a>(x: &'a isize) { | -- lifetime `'a` defined here LL | assert_send::<&'a isize>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/regions-bounded-by-trait-requiring-static.rs:27:5 @@ -12,7 +12,7 @@ error: lifetime may not live long enough LL | fn param_not_ok1<'a>(_: &'a isize) { | -- lifetime `'a` defined here LL | assert_send::<&'a str>(); - | ^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/regions-bounded-by-trait-requiring-static.rs:32:5 @@ -20,7 +20,7 @@ error: lifetime may not live long enough LL | fn param_not_ok2<'a>(_: &'a isize) { | -- lifetime `'a` defined here LL | assert_send::<&'a [isize]>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/regions-bounded-by-trait-requiring-static.rs:47:5 @@ -28,7 +28,7 @@ error: lifetime may not live long enough LL | fn box_with_region_not_ok<'a>() { | -- lifetime `'a` defined here LL | assert_send::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/regions-bounded-by-trait-requiring-static.rs:59:5 @@ -36,7 +36,7 @@ error: lifetime may not live long enough LL | fn unsafe_ok2<'a>(_: &'a isize) { | -- lifetime `'a` defined here LL | assert_send::<*const &'a isize>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: lifetime may not live long enough --> $DIR/regions-bounded-by-trait-requiring-static.rs:64:5 @@ -44,7 +44,7 @@ error: lifetime may not live long enough LL | fn unsafe_ok3<'a>(_: &'a isize) { | -- lifetime `'a` defined here LL | assert_send::<*mut &'a isize>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to 6 previous errors diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters.stderr index b6d7b8aac5f19..3a5e47a08c2d2 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters.stderr @@ -4,7 +4,7 @@ error: lifetime may not live long enough LL | fn caller<'a>(x: &isize) { | -- lifetime `'a` defined here LL | Foo.some_method::<&'a isize>(); - | ^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/regions/regions-free-region-ordering-caller1.stderr b/src/test/ui/regions/regions-free-region-ordering-caller1.stderr index 8042b1740b141..b8a3d533da668 100644 --- a/src/test/ui/regions/regions-free-region-ordering-caller1.stderr +++ b/src/test/ui/regions/regions-free-region-ordering-caller1.stderr @@ -11,6 +11,12 @@ LL | let z: &'a & usize = &(&y); ... LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/regions-free-region-ordering-caller1.rs:9:12 + | +LL | let z: &'a & usize = &(&y); + | ^^^^^^^^^^^ error[E0597]: `y` does not live long enough --> $DIR/regions-free-region-ordering-caller1.rs:9:27 @@ -25,6 +31,12 @@ LL | let z: &'a & usize = &(&y); ... LL | } | - `y` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/regions-free-region-ordering-caller1.rs:9:12 + | +LL | let z: &'a & usize = &(&y); + | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/regions-outlives-projection-container.stderr b/src/test/ui/regions/regions-outlives-projection-container.stderr index 073a31900227e..410d6de0698ab 100644 --- a/src/test/ui/regions/regions-outlives-projection-container.stderr +++ b/src/test/ui/regions/regions-outlives-projection-container.stderr @@ -33,7 +33,7 @@ LL | fn call_with_assoc<'a,'b>() { | lifetime `'a` defined here ... LL | call::<&'a WithAssoc>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` @@ -46,7 +46,7 @@ LL | fn call_without_assoc<'a,'b>() { | lifetime `'a` defined here ... LL | call::<&'a WithoutAssoc>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` diff --git a/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr b/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr index 761e78d179e41..15853e6ca5d69 100644 --- a/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr +++ b/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr @@ -6,10 +6,6 @@ LL | fn use_<'b>(c: Invariant<'b>) { ... LL | let _: Invariant<'static> = c; | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'static` - | - = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant - = note: the struct `Invariant<'a>` is invariant over the parameter `'a` - = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/lifetime-update.stderr b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/lifetime-update.stderr index 5f93ad6e0279e..b495c5c146be6 100644 --- a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/lifetime-update.stderr +++ b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/lifetime-update.stderr @@ -9,6 +9,12 @@ LL | let m2: Machine<'static, State1> = Machine { ... LL | } | - `s` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/lifetime-update.rs:38:13 + | +LL | let m2: Machine<'static, State1> = Machine { + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/self/issue-61882-2.stderr b/src/test/ui/self/issue-61882-2.stderr index 0b8e134c9662e..f46544de3285c 100644 --- a/src/test/ui/self/issue-61882-2.stderr +++ b/src/test/ui/self/issue-61882-2.stderr @@ -2,13 +2,19 @@ error[E0597]: `x` does not live long enough --> $DIR/issue-61882-2.rs:6:14 | LL | Self(&x); - | ^^ - | | - | borrowed value does not live long enough - | this usage requires that `x` is borrowed for `'static` + | ---- ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` LL | LL | } | - `x` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-61882-2.rs:6:9 + | +LL | Self(&x); + | ^^^^ + = help: consider replacing `Self` with `A<&u8>` error: aborting due to previous error diff --git a/src/test/ui/statics/issue-44373.stderr b/src/test/ui/statics/issue-44373.stderr index 6f92fbb1eb689..bba128555b98b 100644 --- a/src/test/ui/statics/issue-44373.stderr +++ b/src/test/ui/statics/issue-44373.stderr @@ -7,6 +7,12 @@ LL | let _val: &'static [&'static u32] = &[&FOO]; | type annotation requires that borrow lasts for `'static` LL | } | - temporary value is freed at the end of this statement + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/issue-44373.rs:4:15 + | +LL | let _val: &'static [&'static u32] = &[&FOO]; + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/traits/object/supertrait-lifetime-bound.stderr b/src/test/ui/traits/object/supertrait-lifetime-bound.stderr index ed2f8624357bb..50e92a078a8d8 100644 --- a/src/test/ui/traits/object/supertrait-lifetime-bound.stderr +++ b/src/test/ui/traits/object/supertrait-lifetime-bound.stderr @@ -5,7 +5,7 @@ LL | fn test2<'a>() { | -- lifetime `'a` defined here ... LL | test1::, _>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.stderr b/src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.stderr index cbdb4dd0fb5c8..4fce643fec7aa 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.stderr @@ -39,6 +39,12 @@ LL | let g = factorial.as_ref().unwrap(); ... LL | } | - `factorial` dropped here while still borrowed + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:25:24 + | +LL | let mut factorial: Option u32 + 'static>> = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0506]: cannot assign to `factorial` because it is borrowed --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:33:5 @@ -53,6 +59,12 @@ LL | let g = factorial.as_ref().unwrap(); ... LL | factorial = Some(Box::new(f)); | ^^^^^^^^^ assignment to borrowed `factorial` occurs here + | +help: you can remove unnecessary lifetime annotations here + --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:25:24 + | +LL | let mut factorial: Option u32 + 'static>> = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/variance/variance-cell-is-invariant.stderr b/src/test/ui/variance/variance-cell-is-invariant.stderr index ab5435d1656d2..1fcdfc4b5bbb2 100644 --- a/src/test/ui/variance/variance-cell-is-invariant.stderr +++ b/src/test/ui/variance/variance-cell-is-invariant.stderr @@ -10,9 +10,6 @@ LL | let _: Foo<'long> = c; | ^^^^^^^^^^ type annotation requires that `'short` must outlive `'long` | = help: consider adding the following bound: `'short: 'long` - = note: requirement occurs because of the type `Foo<'_>`, which makes the generic argument `'_` invariant - = note: the struct `Foo<'a>` is invariant over the parameter `'a` - = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr b/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr index df9d93907cf4f..71aa37835a2d7 100644 --- a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr b/src/test/ui/variance/variance-contravariant-self-trait-match.stderr index bfea1b1b38070..aa660f0852cc6 100644 --- a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-self-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'min G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'max G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr b/src/test/ui/variance/variance-covariant-arg-trait-match.stderr index 4c7b6cf7ce988..6771a370a8da8 100644 --- a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-arg-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/variance/variance-covariant-self-trait-match.stderr b/src/test/ui/variance/variance-covariant-self-trait-match.stderr index 9b7ba3b66b806..72fea90fe9682 100644 --- a/src/test/ui/variance/variance-covariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-self-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'min G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'max G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr b/src/test/ui/variance/variance-invariant-arg-trait-match.stderr index 60ffdd02952ae..1e8e892151b7b 100644 --- a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-arg-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::() - | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/variance/variance-invariant-self-trait-match.stderr b/src/test/ui/variance/variance-invariant-self-trait-match.stderr index 5b64bd0913a55..98f4a45602045 100644 --- a/src/test/ui/variance/variance-invariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-self-trait-match.stderr @@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'min G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` @@ -20,7 +20,7 @@ LL | fn get_max_from_min<'min, 'max, G>() | lifetime `'min` defined here ... LL | impls_get::<&'max G>(); - | ^^^^^^^^^^^^^^^^^^^^ requires that `'min` must outlive `'max` + | ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'min` must outlive `'max` | = help: consider adding the following bound: `'min: 'max` diff --git a/src/test/ui/wf/wf-static-method.stderr b/src/test/ui/wf/wf-static-method.stderr index 161609a5f86a1..b2734b7d8aa6f 100644 --- a/src/test/ui/wf/wf-static-method.stderr +++ b/src/test/ui/wf/wf-static-method.stderr @@ -20,8 +20,9 @@ LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | lifetime `'a` defined here ... LL | let me = Self::make_me(); - | ^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | ^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a` | + = help: consider replacing `Self` with `IndirectEvil` = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough