Skip to content

Commit b46a7cb

Browse files
committed
review comments
1 parent c829db3 commit b46a7cb

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
@@ -174,7 +174,7 @@ fn suggest_restriction(
174174
return;
175175
}
176176
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
177-
if let Some((name, fn_sig)) =
177+
if let Some((bound_str, fn_sig)) =
178178
fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind {
179179
// Shenanigans to get the `Trait` from the `impl Trait`.
180180
ty::Param(param) => {
@@ -193,14 +193,14 @@ fn suggest_restriction(
193193
// but instead we choose to suggest replacing all instances of `impl Trait` with `T`
194194
// where `T: Trait`.
195195
let mut ty_spans = vec![];
196-
let impl_name = format!("impl {}", name);
196+
let impl_trait_str = format!("impl {}", bound_str);
197197
for input in fn_sig.decl.inputs {
198198
if let hir::TyKind::Path(hir::QPath::Resolved(
199199
None,
200200
hir::Path { segments: [segment], .. },
201201
)) = input.kind
202202
{
203-
if segment.ident.as_str() == impl_name.as_str() {
203+
if segment.ident.as_str() == impl_trait_str.as_str() {
204204
// `fn foo(t: impl Trait)`
205205
// ^^^^^^^^^^ get this to suggest `T` instead
206206

@@ -210,14 +210,14 @@ fn suggest_restriction(
210210
}
211211
}
212212

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

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

0 commit comments

Comments
 (0)