]> git.lizzy.rs Git - rust.git/commitdiff
Fix placement of suggested generic param when bounds are present
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 24 Mar 2020 01:46:09 +0000 (18:46 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 24 Mar 2020 18:36:08 +0000 (11:36 -0700)
src/librustc_typeck/collect.rs
src/test/ui/did_you_mean/bad-assoc-ty.stderr

index 8136417de03871701ee6362c9a21ee7e53ea8e16..7806f7832c1144b3b3265334f3678aa74e759045 100644 (file)
@@ -162,8 +162,10 @@ struct CollectItemTypesVisitor<'tcx> {
         // `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),
         ));
     }
index 875c02bae4ae01ac71a859ce5644b9a71bb35349..c409ea9c6576d78a32c3601ec81a451ad9241148 100644 (file)
@@ -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
@@ -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