about summary refs log tree commit diff
path: root/compiler/rustc_infer
diff options
context:
space:
mode:
authorEsteban Kuber <esteban@kuber.com.ar>2021-10-12 13:14:11 +0000
committerEsteban Kuber <esteban@kuber.com.ar>2021-12-10 03:08:24 +0000
commit10a74ac2e0f57f3aaf67991bf4c5be994f240236 (patch)
tree9bba5012f3530840f58c293e9ced0961a4551419 /compiler/rustc_infer
parentee0fd105d86f4998a341b9a819735f1087423492 (diff)
downloadrust-10a74ac2e0f57f3aaf67991bf4c5be994f240236.tar.gz
rust-10a74ac2e0f57f3aaf67991bf4c5be994f240236.zip
Use a more accurate `Span` for `'static` obligation from return type
Diffstat (limited to 'compiler/rustc_infer')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs28
1 files changed, 23 insertions, 5 deletions
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 34015b97e3c..80bdccd4f2c 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
@@ -10,7 +10,8 @@ use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
 use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
 use rustc_middle::ty::{
-    self, AssocItemContainer, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor,
+    self, AssocItemContainer, RegionKind, StaticLifetimeVisitor, Ty, TyCtxt, TypeFoldable,
+    TypeVisitor,
 };
 use rustc_span::symbol::Ident;
 use rustc_span::{MultiSpan, Span};
@@ -186,10 +187,27 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
                 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();
-                    span.push_span_label(
-                        fn_decl.output.span(),
-                        "requirement introduced by this return type".to_string(),
-                    );
+                    let mut add_label = true;
+                    if let hir::FnRetTy::Return(ty) = fn_decl.output {
+                        let mut v = StaticLifetimeVisitor(vec![], tcx.hir());
+                        v.visit_ty(ty);
+                        if !v.0.is_empty() {
+                            span = v.0.clone().into();
+                            for sp in v.0 {
+                                span.push_span_label(
+                                    sp,
+                                    "`'static` requirement introduced here".to_string(),
+                                );
+                            }
+                            add_label = false;
+                        }
+                    }
+                    if add_label {
+                        span.push_span_label(
+                            fn_decl.output.span(),
+                            "requirement introduced by this return type".to_string(),
+                        );
+                    }
                     span.push_span_label(
                         cause.span,
                         "because of this returned expression".to_string(),