Skip to content

Commit e843245

Browse files
committed
review comments
1 parent 3a9c3f9 commit e843245

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,11 +2748,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27482748
}
27492749

27502750
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
2751-
if crate::collect::is_infer_ty(ty) && expected_ty.is_some() {
2752-
self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
2753-
expected_ty.unwrap()
2754-
} else {
2755-
self.ast_ty_to_ty(ty)
2751+
match ty.kind {
2752+
hir::TyKind::Infer if expected_ty.is_some() => {
2753+
self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
2754+
expected_ty.unwrap()
2755+
}
2756+
_ => self.ast_ty_to_ty(ty),
27562757
}
27572758
}
27582759

src/librustc_typeck/collect.rs

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,52 +133,50 @@ crate fn placeholder_type_error(
133133
placeholder_types: Vec<Span>,
134134
suggest: bool,
135135
) {
136-
if !placeholder_types.is_empty() {
137-
let possible_names = ["T", "K", "L", "A", "B", "C"];
138-
let used_names = generics
139-
.iter()
140-
.filter_map(|p| match p.name {
141-
hir::ParamName::Plain(ident) => Some(ident.name),
142-
_ => None,
143-
})
144-
.collect::<Vec<_>>();
136+
if placeholder_types.is_empty() {
137+
return;
138+
}
139+
let possible_names = ["T", "K", "L", "A", "B", "C"];
140+
let used_names = generics
141+
.iter()
142+
.filter_map(|p| match p.name {
143+
hir::ParamName::Plain(ident) => Some(ident.name),
144+
_ => None,
145+
})
146+
.collect::<Vec<_>>();
145147

146-
let mut type_name = "ParamName";
147-
for name in &possible_names {
148-
if !used_names.contains(&Symbol::intern(name)) {
149-
type_name = name;
150-
break;
151-
}
152-
}
148+
let type_name = possible_names
149+
.iter()
150+
.find(|n| !used_names.contains(&Symbol::intern(n)))
151+
.unwrap_or(&"ParamName");
153152

154-
let mut sugg: Vec<_> =
155-
placeholder_types.iter().map(|sp| (*sp, type_name.to_string())).collect();
156-
if generics.is_empty() {
157-
sugg.push((ident_span.shrink_to_hi(), format!("<{}>", type_name)));
158-
} else {
159-
sugg.push((
160-
generics.iter().last().unwrap().span.shrink_to_hi(),
161-
format!(", {}", type_name),
162-
));
163-
}
164-
let mut err = struct_span_err!(
165-
tcx.sess,
166-
placeholder_types.clone(),
167-
E0121,
168-
"the type placeholder `_` is not allowed within types on item signatures",
153+
let mut sugg: Vec<_> =
154+
placeholder_types.iter().map(|sp| (*sp, type_name.to_string())).collect();
155+
if generics.is_empty() {
156+
sugg.push((ident_span.shrink_to_hi(), format!("<{}>", type_name)));
157+
} else {
158+
sugg.push((
159+
generics.iter().last().unwrap().span.shrink_to_hi(),
160+
format!(", {}", type_name),
161+
));
162+
}
163+
let mut err = struct_span_err!(
164+
tcx.sess,
165+
placeholder_types.clone(),
166+
E0121,
167+
"the type placeholder `_` is not allowed within types on item signatures",
168+
);
169+
for span in &placeholder_types {
170+
err.span_label(*span, "not allowed in type signatures");
171+
}
172+
if suggest {
173+
err.multipart_suggestion(
174+
"use type parameters instead",
175+
sugg,
176+
Applicability::HasPlaceholders,
169177
);
170-
for span in &placeholder_types {
171-
err.span_label(*span, "not allowed in type signatures");
172-
}
173-
if suggest {
174-
err.multipart_suggestion(
175-
"use type parameters instead",
176-
sugg,
177-
Applicability::HasPlaceholders,
178-
);
179-
}
180-
err.emit();
181178
}
179+
err.emit();
182180
}
183181

184182
fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {

0 commit comments

Comments
 (0)