Skip to content

Commit

Permalink
Fix placement of suggested generic param when bounds are present
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 24, 2020
1 parent 374ab25 commit cfeedec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ crate fn placeholder_type_error(
// `struct S<T>(T);` instead of `struct S<_, T>(T);`.
sugg.push((arg.span, (*type_name).to_string()));
} else {
let last = generics.iter().last().unwrap();
sugg.push((
generics.iter().last().unwrap().span.shrink_to_hi(),
// Account for bounds, we want `fn foo<T: E, K>(_: K)` not `fn foo<T, K: E>(_: K)`.
last.bounds_span().unwrap_or(last.span).shrink_to_hi(),
format!(", {}", type_name),
));
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ LL | fn foo<X: K<_, _>>(x: X) {}
|
help: use type parameters instead
|
LL | fn foo<X, T: K<T, T>>(x: X) {}
| ^^^ ^ ^
LL | fn foo<X: K<T, T>, T>(x: X) {}
| ^ ^ ^^^

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/bad-assoc-ty.rs:52:34
Expand All @@ -167,8 +167,8 @@ LL | fn baz<F: Fn() -> _>(_: F) {}
|
help: use type parameters instead
|
LL | fn baz<F, T: Fn() -> T>(_: F) {}
| ^^^ ^
LL | fn baz<F: Fn() -> T, T>(_: F) {}
| ^^^^

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/bad-assoc-ty.rs:58:33
Expand Down

0 comments on commit cfeedec

Please sign in to comment.