diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 1176f131107..dab0b87f7ae 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -151,9 +151,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if mention_capture { spans.push(sup_origin.span()); } - // We sort the spans *ignoring* expansion context. Below, the closure logic is repeated - // because one method expects a closure taking `&Span` and the other `&mut Span`. - spans.sort_by_key(|span| (span.lo(), span.hi())); + // We dedup the spans *ignoring* expansion context. + spans.sort(); spans.dedup_by_key(|span| (span.lo(), span.hi())); // We try to make the output have fewer overlapping spans if possible. @@ -183,7 +182,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { err.span_note(*bound, "`'static` lifetime requirement introduced by this bound"); } if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = sub_origin { - if let ObligationCauseCode::BlockTailExpression(hir_id) = &cause.code { + if let ObligationCauseCode::ReturnValue(hir_id) + | ObligationCauseCode::BlockTailExpression(hir_id) = &cause.code + { let parent_id = tcx.hir().get_parent_item(*hir_id); if let Some(fn_decl) = tcx.hir().fn_decl_by_hir_id(parent_id) { let mut span: MultiSpan = fn_decl.output.span().into(); diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index b6c1e1f5922..08a58fa67e0 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -97,7 +97,7 @@ pub enum RegionResolutionError<'tcx> { Region<'tcx>, SubregionOrigin<'tcx>, Region<'tcx>, - Vec, + Vec, // All the influences on a given value that didn't meet its constraints. ), /// Indicates a `'b: 'a` constraint where `'a` is in a universe that @@ -570,9 +570,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // have to revisit this portion of the code and // think hard about it. =) -- nikomatsakis - // Obtain the spans for all the capture points for + // Obtain the spans for all the places that can + // influence the constraints on this value for // richer diagnostics in `static_impl_trait`. - let captures: Vec = self + let influences: Vec = self .data .constraints .iter() @@ -590,7 +591,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { &mut dup_vec, node_vid, errors, - captures, + influences, ); } } @@ -645,7 +646,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { dup_vec: &mut IndexVec>, node_idx: RegionVid, errors: &mut Vec>, - captures: Vec, + influences: Vec, ) { // Errors in expanding nodes result from a lower-bound that is // not contained by an upper-bound. @@ -700,7 +701,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { lower_bound.region, upper_bound.origin.clone(), upper_bound.region, - captures, + influences, )); return; }