about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-12-26 14:01:45 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-12-29 19:16:53 -0800
commite843245716586222fe997b8ffe10ab8bf91fc399 (patch)
tree104c76f9d528e2b2d5d589132b8a0de99c9831f0
parent3a9c3f92ccc2056e73a88840afde6b9df0dbf7ec (diff)
downloadrust-e843245716586222fe997b8ffe10ab8bf91fc399.tar.gz
rust-e843245716586222fe997b8ffe10ab8bf91fc399.zip
review comments
-rw-r--r--src/librustc_typeck/astconv.rs11
-rw-r--r--src/librustc_typeck/collect.rs82
2 files changed, 46 insertions, 47 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 9916d1b8999..e0908d5d18b 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -2748,11 +2748,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
     }
 
     pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
-        if crate::collect::is_infer_ty(ty) && expected_ty.is_some() {
-            self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
-            expected_ty.unwrap()
-        } else {
-            self.ast_ty_to_ty(ty)
+        match ty.kind {
+            hir::TyKind::Infer if expected_ty.is_some() => {
+                self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
+                expected_ty.unwrap()
+            }
+            _ => self.ast_ty_to_ty(ty),
         }
     }
 
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index fd173bfbb92..6b968155e74 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -133,52 +133,50 @@ crate fn placeholder_type_error(
     placeholder_types: Vec<Span>,
     suggest: bool,
 ) {
-    if !placeholder_types.is_empty() {
-        let possible_names = ["T", "K", "L", "A", "B", "C"];
-        let used_names = generics
-            .iter()
-            .filter_map(|p| match p.name {
-                hir::ParamName::Plain(ident) => Some(ident.name),
-                _ => None,
-            })
-            .collect::<Vec<_>>();
+    if placeholder_types.is_empty() {
+        return;
+    }
+    let possible_names = ["T", "K", "L", "A", "B", "C"];
+    let used_names = generics
+        .iter()
+        .filter_map(|p| match p.name {
+            hir::ParamName::Plain(ident) => Some(ident.name),
+            _ => None,
+        })
+        .collect::<Vec<_>>();
 
-        let mut type_name = "ParamName";
-        for name in &possible_names {
-            if !used_names.contains(&Symbol::intern(name)) {
-                type_name = name;
-                break;
-            }
-        }
+    let type_name = possible_names
+        .iter()
+        .find(|n| !used_names.contains(&Symbol::intern(n)))
+        .unwrap_or(&"ParamName");
 
-        let mut sugg: Vec<_> =
-            placeholder_types.iter().map(|sp| (*sp, type_name.to_string())).collect();
-        if generics.is_empty() {
-            sugg.push((ident_span.shrink_to_hi(), format!("<{}>", type_name)));
-        } else {
-            sugg.push((
-                generics.iter().last().unwrap().span.shrink_to_hi(),
-                format!(", {}", type_name),
-            ));
-        }
-        let mut err = struct_span_err!(
-            tcx.sess,
-            placeholder_types.clone(),
-            E0121,
-            "the type placeholder `_` is not allowed within types on item signatures",
+    let mut sugg: Vec<_> =
+        placeholder_types.iter().map(|sp| (*sp, type_name.to_string())).collect();
+    if generics.is_empty() {
+        sugg.push((ident_span.shrink_to_hi(), format!("<{}>", type_name)));
+    } else {
+        sugg.push((
+            generics.iter().last().unwrap().span.shrink_to_hi(),
+            format!(", {}", type_name),
+        ));
+    }
+    let mut err = struct_span_err!(
+        tcx.sess,
+        placeholder_types.clone(),
+        E0121,
+        "the type placeholder `_` is not allowed within types on item signatures",
+    );
+    for span in &placeholder_types {
+        err.span_label(*span, "not allowed in type signatures");
+    }
+    if suggest {
+        err.multipart_suggestion(
+            "use type parameters instead",
+            sugg,
+            Applicability::HasPlaceholders,
         );
-        for span in &placeholder_types {
-            err.span_label(*span, "not allowed in type signatures");
-        }
-        if suggest {
-            err.multipart_suggestion(
-                "use type parameters instead",
-                sugg,
-                Applicability::HasPlaceholders,
-            );
-        }
-        err.emit();
     }
+    err.emit();
 }
 
 fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {