about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-08-18 00:15:30 +0530
committergaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-08-18 00:19:55 +0530
commit8b89f3168d593e4bfd3babc0a37b624e9593aec1 (patch)
treedb9509faba282bd2a740e60a2b6cd649630b7370
parentb1cee113c7ecc6eac0d9898d5e5870ad15f70f77 (diff)
downloadrust-8b89f3168d593e4bfd3babc0a37b624e9593aec1.tar.gz
rust-8b89f3168d593e4bfd3babc0a37b624e9593aec1.zip
code review fixes
-rw-r--r--src/librustc/infer/error_reporting/anon_anon_conflict.rs7
-rw-r--r--src/librustc/infer/error_reporting/named_anon_conflict.rs37
-rw-r--r--src/librustc/infer/error_reporting/util.rs16
3 files changed, 38 insertions, 22 deletions
diff --git a/src/librustc/infer/error_reporting/anon_anon_conflict.rs b/src/librustc/infer/error_reporting/anon_anon_conflict.rs
index c5e26f43120..4a2b751f5e8 100644
--- a/src/librustc/infer/error_reporting/anon_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/anon_anon_conflict.rs
@@ -50,7 +50,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
             if let (Some(anon_reg_sup), Some(anon_reg_sub)) =
                 (self.is_suitable_anonymous_region(sup, true),
                  self.is_suitable_anonymous_region(sub, true)) {
-                let ((def_id_sup, br_sup), (def_id_sub, br_sub)) = (anon_reg_sup, anon_reg_sub);
+                let (def_id_sup, br_sup, def_id_sub, br_sub) = (anon_reg_sup.def_id,
+                                                                anon_reg_sup.boundregion,
+                                                                anon_reg_sub.def_id,
+                                                                anon_reg_sub.boundregion);
                 if let (Some(anonarg_sup), Some(anonarg_sub)) =
                     (self.find_anon_type(sup, &br_sup), self.find_anon_type(sub, &br_sub)) {
                     (anonarg_sup, anonarg_sub, def_id_sup, def_id_sub, br_sup, br_sub)
@@ -124,7 +127,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     /// for e.g. `&u8` and Vec<`&u8`.
     pub fn find_anon_type(&self, region: Region<'tcx>, br: &ty::BoundRegion) -> Option<&hir::Ty> {
         if let Some(anon_reg) = self.is_suitable_anonymous_region(region, true) {
-            let (def_id, _) = anon_reg;
+            let def_id = anon_reg.def_id;
             if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
                 let ret_ty = self.tcx.type_of(def_id);
                 if let ty::TyFnDef(_, _) = ret_ty.sty {
diff --git a/src/librustc/infer/error_reporting/named_anon_conflict.rs b/src/librustc/infer/error_reporting/named_anon_conflict.rs
index 005eb900c11..7fa1eca5535 100644
--- a/src/librustc/infer/error_reporting/named_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/named_anon_conflict.rs
@@ -29,25 +29,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
         // where the anonymous region appears (there must always be one; we
         // only introduced anonymous regions in parameters) as well as a
         // version new_ty of its type where the anonymous region is replaced
-        // with the named one.
-        let (named, anon_arg_info, (scope_def_id, _)) = if
-            sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
-            (sub,
-             self.find_arg_with_anonymous_region(sup, sub).unwrap(),
-             self.is_suitable_anonymous_region(sup, false).unwrap())
-        } else if
-            sup.is_named_region() && self.is_suitable_anonymous_region(sub, false).is_some() {
-            (sup,
-             self.find_arg_with_anonymous_region(sub, sup).unwrap(),
-             self.is_suitable_anonymous_region(sub, false).unwrap())
-        } else {
-            return false; // inapplicable
-        };
+        // with the named one.//scope_def_id
+        let (named, anon_arg_info, region_info) =
+            if sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
+                (sub,
+                 self.find_arg_with_anonymous_region(sup, sub).unwrap(),
+                 self.is_suitable_anonymous_region(sup, false).unwrap())
+            } else if sup.is_named_region() &&
+                      self.is_suitable_anonymous_region(sub, false).is_some() {
+                (sup,
+                 self.find_arg_with_anonymous_region(sub, sup).unwrap(),
+                 self.is_suitable_anonymous_region(sub, false).unwrap())
+            } else {
+                return false; // inapplicable
+            };
 
-        let (arg, new_ty, br, is_first) = (anon_arg_info.arg,
-                                           anon_arg_info.arg_ty,
-                                           anon_arg_info.bound_region,
-                                           anon_arg_info.is_first);
+        let (arg, new_ty, br, is_first, scope_def_id) = (anon_arg_info.arg,
+                                                         anon_arg_info.arg_ty,
+                                                         anon_arg_info.bound_region,
+                                                         anon_arg_info.is_first,
+                                                         region_info.def_id);
         if self.is_return_type_anon(scope_def_id, br) || self.is_self_anon(is_first, scope_def_id) {
             return false;
         } else {
diff --git a/src/librustc/infer/error_reporting/util.rs b/src/librustc/infer/error_reporting/util.rs
index 902e388ca7b..84429fea86e 100644
--- a/src/librustc/infer/error_reporting/util.rs
+++ b/src/librustc/infer/error_reporting/util.rs
@@ -30,6 +30,15 @@ pub struct AnonymousArgInfo<'tcx> {
     pub is_first: bool,
 }
 
+// This struct contains information regarding the
+// Refree((FreeRegion) corresponding to lifetime conflict
+pub struct FreeRegionInfo {
+    // def id corresponding to FreeRegion
+    pub def_id: DefId,
+    // the bound region corresponding to FreeRegion
+    pub boundregion: ty::BoundRegion,
+}
+
 impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     // This method walks the Type of the function body arguments using
     // `fold_regions()` function and returns the
@@ -102,7 +111,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     pub fn is_suitable_anonymous_region(&self,
                                         region: Region<'tcx>,
                                         is_anon_anon: bool)
-                                        -> Option<(DefId, ty::BoundRegion)> {
+                                        -> Option<FreeRegionInfo> {
         if let ty::ReFree(ref free_region) = *region {
             if let ty::BrAnon(..) = free_region.bound_region {
                 let anonymous_region_binding_scope = free_region.scope;
@@ -136,7 +145,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                     _ => return None, // inapplicable
                     // we target only top-level functions
                 }
-                return Some((anonymous_region_binding_scope, free_region.bound_region));
+                return Some(FreeRegionInfo {
+                                def_id: anonymous_region_binding_scope,
+                                boundregion: free_region.bound_region,
+                            });
             }
         }
         None