]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/infer/error_reporting/different_lifetimes.rs
Rollup merge of #44562 - eddyb:ugh-rustdoc, r=nikomatsakis
[rust.git] / src / librustc / infer / error_reporting / different_lifetimes.rs
index 23f6d1a3fb0d4521a1094e9f95d53c3e25fdd546..536715ffadb15b7f7501ac78af5cd39c6791e413 100644 (file)
@@ -173,6 +173,7 @@ fn find_component_for_bound_region(&self,
             hir_map: &self.tcx.hir,
             bound_region: *br,
             found_type: None,
+            depth: 1,
         };
         nested_visitor.visit_ty(arg);
         nested_visitor.found_type
@@ -195,6 +196,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     // The type where the anonymous lifetime appears
     // for e.g. Vec<`&u8`> and <`&u8`>
     found_type: Option<&'gcx hir::Ty>,
+    depth: u32,
 }
 
 impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
@@ -204,6 +206,21 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
 
     fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
         match arg.node {
+            hir::TyBareFn(_) => {
+                self.depth += 1;
+                intravisit::walk_ty(self, arg);
+                self.depth -= 1;
+                return;
+            }
+
+            hir::TyTraitObject(ref bounds, _) => {
+                for bound in bounds {
+                    self.depth += 1;
+                    self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
+                    self.depth -= 1;
+                }
+            }
+
             hir::TyRptr(ref lifetime, _) => {
                 // the lifetime of the TyRptr
                 let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
@@ -217,7 +234,7 @@ fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
                                debruijn_index.depth,
                                anon_index,
                                br_index);
-                        if debruijn_index.depth == 1 && anon_index == br_index {
+                        if debruijn_index.depth == self.depth && anon_index == br_index {
                             self.found_type = Some(arg);
                             return; // we can stop visiting now
                         }
@@ -246,7 +263,7 @@ fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
                         debug!("self.infcx.tcx.hir.local_def_id(id)={:?}",
                                self.infcx.tcx.hir.local_def_id(id));
                         debug!("def_id={:?}", def_id);
-                        if debruijn_index.depth == 1 &&
+                        if debruijn_index.depth == self.depth &&
                            self.infcx.tcx.hir.local_def_id(id) == def_id {
                             self.found_type = Some(arg);
                             return; // we can stop visiting now
@@ -270,6 +287,7 @@ fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
                                           found_it: false,
                                           bound_region: self.bound_region,
                                           hir_map: self.hir_map,
+                                          depth: self.depth,
                                       };
                 intravisit::walk_ty(subvisitor, arg); // call walk_ty; as visit_ty is empty,
                 // this will visit only outermost type
@@ -296,6 +314,7 @@ struct TyPathVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     hir_map: &'a hir::map::Map<'gcx>,
     found_it: bool,
     bound_region: ty::BoundRegion,
+    depth: u32,
 }
 
 impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
@@ -304,24 +323,47 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
     }
 
     fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) {
-        let br_index = match self.bound_region {
-            ty::BrAnon(index) => index,
-            _ => return,
-        };
 
         let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
-        match self.infcx.tcx.named_region(hir_id) {
+        match (self.infcx.tcx.named_region(hir_id), self.bound_region) {
             // the lifetime of the TyPath!
-            Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
-                if debruijn_index.depth == 1 && anon_index == br_index {
+            (Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)), ty::BrAnon(br_index)) => {
+                if debruijn_index.depth == self.depth && anon_index == br_index {
+                    self.found_it = true;
+                    return;
+                }
+            }
+
+            (Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
+                debug!("EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
+                                        def_id={:?}",
+                       self.infcx.tcx.hir.local_def_id(id),
+                       def_id);
+                if self.infcx.tcx.hir.local_def_id(id) == def_id {
+                    self.found_it = true;
+                    return; // we can stop visiting now
+                }
+            }
+
+            (Some(rl::Region::LateBound(debruijn_index, id)), ty::BrNamed(def_id, _)) => {
+                debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
+                       debruijn_index.depth);
+                debug!("self.infcx.tcx.hir.local_def_id(id)={:?}",
+                       self.infcx.tcx.hir.local_def_id(id));
+                debug!("def_id={:?}", def_id);
+                if debruijn_index.depth == self.depth &&
+                   self.infcx.tcx.hir.local_def_id(id) == def_id {
                     self.found_it = true;
+                    return; // we can stop visiting now
                 }
             }
-            Some(rl::Region::Static) |
-            Some(rl::Region::EarlyBound(_, _)) |
-            Some(rl::Region::LateBound(_, _)) |
-            Some(rl::Region::Free(_, _)) |
-            None => {
+
+            (Some(rl::Region::Static), _) |
+            (Some(rl::Region::EarlyBound(_, _)), _) |
+            (Some(rl::Region::LateBound(_, _)), _) |
+            (Some(rl::Region::LateBoundAnon(_, _)), _) |
+            (Some(rl::Region::Free(_, _)), _) |
+            (None, _) => {
                 debug!("no arg found");
             }
         }