Skip to content

Commit cfeedec

Browse files
committed
Fix placement of suggested generic param when bounds are present
1 parent 374ab25 commit cfeedec

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/librustc_typeck/collect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ crate fn placeholder_type_error(
162162
// `struct S<T>(T);` instead of `struct S<_, T>(T);`.
163163
sugg.push((arg.span, (*type_name).to_string()));
164164
} else {
165+
let last = generics.iter().last().unwrap();
165166
sugg.push((
166-
generics.iter().last().unwrap().span.shrink_to_hi(),
167+
// Account for bounds, we want `fn foo<T: E, K>(_: K)` not `fn foo<T, K: E>(_: K)`.
168+
last.bounds_span().unwrap_or(last.span).shrink_to_hi(),
167169
format!(", {}", type_name),
168170
));
169171
}

src/test/ui/did_you_mean/bad-assoc-ty.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ LL | fn foo<X: K<_, _>>(x: X) {}
145145
|
146146
help: use type parameters instead
147147
|
148-
LL | fn foo<X, T: K<T, T>>(x: X) {}
149-
| ^^^ ^ ^
148+
LL | fn foo<X: K<T, T>, T>(x: X) {}
149+
| ^ ^ ^^^
150150

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

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

0 commit comments

Comments
 (0)