diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8136417de038..7806f7832c11 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -162,8 +162,10 @@ crate fn placeholder_type_error( // `struct S(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(_: K)` not `fn foo(_: K)`. + last.bounds_span().unwrap_or(last.span).shrink_to_hi(), format!(", {}", type_name), )); } diff --git a/src/test/ui/did_you_mean/bad-assoc-ty.stderr b/src/test/ui/did_you_mean/bad-assoc-ty.stderr index 875c02bae4ae..c409ea9c6576 100644 --- a/src/test/ui/did_you_mean/bad-assoc-ty.stderr +++ b/src/test/ui/did_you_mean/bad-assoc-ty.stderr @@ -145,8 +145,8 @@ LL | fn foo>(x: X) {} | help: use type parameters instead | -LL | fn foo>(x: X) {} - | ^^^ ^ ^ +LL | fn foo, T>(x: X) {} + | ^ ^ ^^^ error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/bad-assoc-ty.rs:52:34 @@ -167,8 +167,8 @@ LL | fn baz _>(_: F) {} | help: use type parameters instead | -LL | fn baz T>(_: F) {} - | ^^^ ^ +LL | fn baz T, T>(_: F) {} + | ^^^^ error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/bad-assoc-ty.rs:58:33