Skip to content

Commit ca25e28

Browse files
committed
review comments
1 parent 4439470 commit ca25e28

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn suggest_restriction(
175175
return;
176176
}
177177
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
178-
if let Some((name, fn_sig)) =
178+
if let Some((bound_str, fn_sig)) =
179179
fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind {
180180
// Shenanigans to get the `Trait` from the `impl Trait`.
181181
ty::Param(param) => {
@@ -194,14 +194,14 @@ fn suggest_restriction(
194194
// but instead we choose to suggest replacing all instances of `impl Trait` with `T`
195195
// where `T: Trait`.
196196
let mut ty_spans = vec![];
197-
let impl_name = format!("impl {}", name);
197+
let impl_trait_str = format!("impl {}", bound_str);
198198
for input in fn_sig.decl.inputs {
199199
if let hir::TyKind::Path(hir::QPath::Resolved(
200200
None,
201201
hir::Path { segments: [segment], .. },
202202
)) = input.kind
203203
{
204-
if segment.ident.as_str() == impl_name.as_str() {
204+
if segment.ident.as_str() == impl_trait_str.as_str() {
205205
// `fn foo(t: impl Trait)`
206206
// ^^^^^^^^^^ get this to suggest `T` instead
207207

@@ -211,14 +211,14 @@ fn suggest_restriction(
211211
}
212212
}
213213

214-
let type_param_name = generics.params.next_type_param_name(Some(&name));
214+
let type_param_name = generics.params.next_type_param_name(Some(&bound_str));
215215
// The type param `T: Trait` we will suggest to introduce.
216-
let type_param = format!("{}: {}", type_param_name, name);
216+
let type_param = format!("{}: {}", type_param_name, bound_str);
217217

218218
// FIXME: modify the `trait_ref` instead of string shenanigans.
219219
// Turn `<impl Trait as Foo>::Bar: Qux` into `<T as Foo>::Bar: Qux`.
220220
let pred = trait_ref.without_const().to_predicate().to_string();
221-
let pred = pred.replace(&impl_name, &type_param_name);
221+
let pred = pred.replace(&impl_trait_str, &type_param_name);
222222
let mut sugg = vec![
223223
match generics
224224
.params
@@ -258,10 +258,10 @@ fn suggest_restriction(
258258
);
259259
} else {
260260
// Trivial case: `T` needs an extra bound: `T: Bound`.
261-
let (sp, s) =
261+
let (sp, sugg) =
262262
predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string());
263263
let appl = Applicability::MachineApplicable;
264-
err.span_suggestion(sp, &format!("consider further restricting {}", msg), s, appl);
264+
err.span_suggestion(sp, &format!("consider further restricting {}", msg), sugg, appl);
265265
}
266266
}
267267

0 commit comments

Comments
 (0)