about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorgaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-06-27 12:54:15 -0700
committergaurikholkar <f2013002@goa.bits-pilani.ac.in>2017-06-29 06:37:18 -0700
commite8b8f30373941f1d606d21c741bb136d81c3d082 (patch)
tree2b4fd47c8e9032f7a3c7367bdf0f9c42ffe28a73 /src
parent95409016f8e84a47715526a89929cd22a2f25c16 (diff)
downloadrust-e8b8f30373941f1d606d21c741bb136d81c3d082.tar.gz
rust-e8b8f30373941f1d606d21c741bb136d81c3d082.zip
Code review fixes
Diffstat (limited to 'src')
-rw-r--r--src/librustc/infer/error_reporting/mod.rs1
-rw-r--r--src/librustc/infer/error_reporting/named_anon_conflict.rs42
-rw-r--r--src/librustc/infer/error_reporting/util.rs30
-rw-r--r--src/librustc/ty/sty.rs14
4 files changed, 34 insertions, 53 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs
index 9e2d922b932..82bbb4a1bf5 100644
--- a/src/librustc/infer/error_reporting/mod.rs
+++ b/src/librustc/infer/error_reporting/mod.rs
@@ -76,7 +76,6 @@ mod note;
 
 mod need_type_info;
 mod named_anon_conflict;
-mod util;
 
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
diff --git a/src/librustc/infer/error_reporting/named_anon_conflict.rs b/src/librustc/infer/error_reporting/named_anon_conflict.rs
index fb0bd901db4..cdfb57c86f9 100644
--- a/src/librustc/infer/error_reporting/named_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/named_anon_conflict.rs
@@ -41,12 +41,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                 let id = free_region.scope;
                 let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
                 let body_id = self.tcx.hir.maybe_body_owned_by(node_id).unwrap();
-                let mut is_first = false;
                 let body = self.tcx.hir.body(body_id);
                 if let Some(tables) = self.in_progress_tables {
                     body.arguments
                         .iter()
-                        .filter_map(|arg| {
+                        .enumerate()
+                        .filter_map(|(index, arg)| {
                             let ty = tables.borrow().node_id_to_type(arg.id);
                             let mut found_anon_region = false;
                             let new_arg_ty = self.tcx
@@ -57,9 +57,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                                     r
                                 });
                             if found_anon_region {
-                                if body.arguments.iter().nth(0) == Some(&arg) {
-                                    is_first = true;
-                                }
+                                let is_first = index == 0;
                                 Some((arg, new_arg_ty, free_region.bound_region, is_first))
                             } else {
                                 None
@@ -91,19 +89,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
         // 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, (arg, new_ty, br, is_first), scope_def_id) = if
-            self.is_named_region(sub) && self.is_suitable_anonymous_region(sup).is_some() {
-            (sub,
-             self.find_arg_with_anonymous_region(sup, sub).unwrap(),
-             self.is_suitable_anonymous_region(sup).unwrap())
-        } else if
-            self.is_named_region(sup) && self.is_suitable_anonymous_region(sub).is_some() {
-            (sup,
-             self.find_arg_with_anonymous_region(sub, sup).unwrap(),
-             self.is_suitable_anonymous_region(sub).unwrap())
-        } else {
-            return false; // inapplicable
-        };
+        let (named, (arg, new_ty, br, is_first), scope_def_id) =
+            if sub.is_named_region() && self.is_suitable_anonymous_region(sup).is_some() {
+                (sub,
+                 self.find_arg_with_anonymous_region(sup, sub).unwrap(),
+                 self.is_suitable_anonymous_region(sup).unwrap())
+            } else if sup.is_named_region() && self.is_suitable_anonymous_region(sub).is_some() {
+                (sup,
+                 self.find_arg_with_anonymous_region(sub, sup).unwrap(),
+                 self.is_suitable_anonymous_region(sub).unwrap())
+            } else {
+                return false; // inapplicable
+            };
 
         // Here, we check for the case where the anonymous region
         // is in the return type.
@@ -179,8 +176,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                                 // proceed ahead //
                             }
                             Some(hir_map::NodeImplItem(..)) => {
-                                if self.tcx.impl_trait_ref(self.tcx.
-associated_item(anonymous_region_binding_scope).container.id()).is_some() {
+                                let container_id = self.tcx
+                                    .associated_item(anonymous_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,
@@ -189,8 +189,6 @@ associated_item(anonymous_region_binding_scope).container.id()).is_some() {
                                     // FIXME(#42706) -- in some cases, we could do better here.
                                     return None;
                                 }
-                              else{  }
-
                             }
                             _ => return None, // inapplicable
                             // we target only top-level functions
diff --git a/src/librustc/infer/error_reporting/util.rs b/src/librustc/infer/error_reporting/util.rs
deleted file mode 100644
index 66c351b49ac..00000000000
--- a/src/librustc/infer/error_reporting/util.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Helper for error reporting code for named_anon_conflict
-
-use ty::{self, Region};
-use infer::InferCtxt;
-
-impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-    // This method returns whether the given Region is Named
-    pub fn is_named_region(&self, region: Region<'tcx>) -> bool {
-
-        match *region {
-            ty::ReFree(ref free_region) => {
-                match free_region.bound_region {
-                    ty::BrNamed(..) => true,
-                    _ => false,
-                }
-            }
-            _ => false,
-        }
-    }
-}
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index ed3312d88a3..452775e9e13 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -990,6 +990,20 @@ impl RegionKind {
 
         flags
     }
+
+    // This method returns whether the given Region is Named
+    pub fn is_named_region(&self) -> bool {
+
+        match *self {
+            ty::ReFree(ref free_region) => {
+                match free_region.bound_region {
+                    ty::BrNamed(..) => true,
+                    _ => false,
+                }
+            }
+            _ => false,
+        }
+    }
 }
 
 /// Type utilities