]> git.proxmox.com Git - rustc.git/blobdiff - src/librustc/infer/error_reporting/nice_region_error/util.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / librustc / infer / error_reporting / nice_region_error / util.rs
index 30406f1fec55cd208ce6c56779f64c84deaa17b4..013c02f75b88315f1a7f776d2ed8d70c93e4522d 100644 (file)
@@ -15,7 +15,6 @@ use hir;
 use infer::error_reporting::nice_region_error::NiceRegionError;
 use ty::{self, Region, Ty};
 use hir::def_id::DefId;
-use hir::Node;
 use syntax_pos::Span;
 
 // The struct contains the information about the anonymous region
@@ -35,18 +34,6 @@ pub(super) struct AnonymousArgInfo<'tcx> {
     pub is_first: bool,
 }
 
-// This struct contains information regarding the
-// Refree((FreeRegion) corresponding to lifetime conflict
-#[derive(Debug)]
-pub(super) struct FreeRegionInfo {
-    // def id corresponding to FreeRegion
-    pub def_id: DefId,
-    // the bound region corresponding to FreeRegion
-    pub boundregion: ty::BoundRegion,
-    // checks if bound region is in Impl Item
-    pub is_impl_item: bool,
-}
-
 impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     // This method walks the Type of the function body arguments using
     // `fold_regions()` function and returns the
@@ -63,7 +50,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         &self,
         anon_region: Region<'tcx>,
         replace_region: Region<'tcx>,
-    ) -> Option<AnonymousArgInfo> {
+    ) -> Option<AnonymousArgInfo<'_>> {
         let (id, bound_region) = match *anon_region {
             ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
             ty::ReEarlyBound(ref ebr) => (
@@ -122,36 +109,6 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         }
     }
 
-    // This method returns the DefId and the BoundRegion corresponding to the given region.
-    pub(super) fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
-        let (suitable_region_binding_scope, bound_region) = match *region {
-            ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
-            ty::ReEarlyBound(ref ebr) => (
-                self.tcx.parent_def_id(ebr.def_id).unwrap(),
-                ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
-            ),
-            _ => return None, // not a free region
-        };
-
-        let node_id = self.tcx
-            .hir
-            .as_local_node_id(suitable_region_binding_scope)
-            .unwrap();
-        let is_impl_item = match self.tcx.hir.find(node_id) {
-            Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
-            Some(Node::ImplItem(..)) => {
-                self.is_bound_region_in_impl_item(suitable_region_binding_scope)
-            }
-            _ => return None,
-        };
-
-        return Some(FreeRegionInfo {
-            def_id: suitable_region_binding_scope,
-            boundregion: bound_region,
-            is_impl_item: is_impl_item,
-        });
-    }
-
     // Here, we check for the case where the anonymous region
     // is in the return type.
     // FIXME(#42703) - Need to handle certain cases here.
@@ -162,36 +119,17 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         decl: &hir::FnDecl,
     ) -> Option<Span> {
         let ret_ty = self.tcx.type_of(scope_def_id);
-        match ret_ty.sty {
-            ty::FnDef(_, _) => {
-                let sig = ret_ty.fn_sig(self.tcx);
-                let late_bound_regions = self.tcx
-                    .collect_referenced_late_bound_regions(&sig.output());
-                if late_bound_regions.iter().any(|r| *r == br) {
-                    return Some(decl.output.span());
-                }
+        if let ty::FnDef(_, _) = ret_ty.sty {
+            let sig = ret_ty.fn_sig(self.tcx);
+            let late_bound_regions = self.tcx
+                .collect_referenced_late_bound_regions(&sig.output());
+            if late_bound_regions.iter().any(|r| *r == br) {
+                return Some(decl.output.span());
             }
-            _ => {}
         }
         None
     }
 
-    pub(super) fn is_return_type_impl_trait(
-        &self,
-        scope_def_id: DefId,
-    ) -> bool {
-        let ret_ty = self.tcx.type_of(scope_def_id);
-        match ret_ty.sty {
-            ty::FnDef(_, _) => {
-                let sig = ret_ty.fn_sig(self.tcx);
-                let output = self.tcx.erase_late_bound_regions(&sig.output());
-                return output.is_impl_trait();
-            }
-            _ => {}
-        }
-        false
-    }
-
     // Here we check for the case where anonymous region
     // corresponds to self and if yes, we display E0312.
     // FIXME(#42700) - Need to format self properly to
@@ -199,28 +137,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
         is_first
             && self.tcx
-                .opt_associated_item(scope_def_id)
-                .map(|i| i.method_has_self_argument) == Some(true)
+                   .opt_associated_item(scope_def_id)
+                   .map(|i| i.method_has_self_argument) == Some(true)
     }
 
-    // Here we check if the bound region is in Impl Item.
-    pub(super) fn is_bound_region_in_impl_item(
-        &self,
-        suitable_region_binding_scope: DefId,
-    ) -> bool {
-        let container_id = self.tcx
-            .associated_item(suitable_region_binding_scope)
-            .container
-            .id();
-        if self.tcx.impl_trait_ref(container_id).is_some() {
-            // For now, we do not try to target impls of traits. This is
-            // because this message is going to suggest that the user
-            // change the fn signature, but they may not be free to do so,
-            // since the signature must match the trait.
-            //
-            // FIXME(#42706) -- in some cases, we could do better here.
-            return true;
-        }
-        false
-    }
 }