From e843245716586222fe997b8ffe10ab8bf91fc399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 26 Dec 2019 14:01:45 -0800 Subject: [PATCH] review comments --- src/librustc_typeck/astconv.rs | 11 +++-- src/librustc_typeck/collect.rs | 88 +++++++++++++++++----------------- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9916d1b8999f..e0908d5d18b1 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> { - 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 fd173bfbb926..6b968155e744 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, 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::>(); - - let mut type_name = "ParamName"; - for name in &possible_names { - if !used_names.contains(&Symbol::intern(name)) { - type_name = name; - break; - } - } - - 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, - ); - } - err.emit(); + 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::>(); + + 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", + ); + 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(); } fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {