Skip to content

More accurate span for type parameter suggestion #127888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,11 +1340,13 @@ pub fn prohibit_assoc_item_constraint(
format!("<{lifetimes}{type_with_constraints}>"),
)
};
let suggestions =
vec![param_decl, (constraint.span, format!("{}", matching_param.name))];
let suggestions = vec![
param_decl,
(constraint.span.with_lo(constraint.ident.span.hi()), String::new()),
];

err.multipart_suggestion_verbose(
format!("declare the type parameter right after the `impl` keyword"),
"declare the type parameter right after the `impl` keyword",
suggestions,
Applicability::MaybeIncorrect,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ LL | impl Foo<T: Default> for String {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<T: Default> Foo<T> for String {}
| ++++++++++++ ~
LL - impl Foo<T: Default> for String {}
LL + impl<T: Default> Foo<T> for String {}
|

error[E0229]: associated item constraints are not allowed here
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:7:10
Expand All @@ -25,8 +26,9 @@ LL | impl Foo<T: 'a + Default> for u8 {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<'a, T: 'a + Default> Foo<T> for u8 {}
| +++++++++++++++++++++ ~
LL - impl Foo<T: 'a + Default> for u8 {}
LL + impl<'a, T: 'a + Default> Foo<T> for u8 {}
|

error[E0229]: associated item constraints are not allowed here
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:13:13
Expand All @@ -36,8 +38,9 @@ LL | impl<T> Foo<T: Default> for u16 {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<T, T: Default> Foo<T> for u16 {}
| ++++++++++++ ~
LL - impl<T> Foo<T: Default> for u16 {}
LL + impl<T, T: Default> Foo<T> for u16 {}
|

error[E0229]: associated item constraints are not allowed here
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:17:14
Expand All @@ -47,8 +50,9 @@ LL | impl<'a> Foo<T: 'a + Default> for u32 {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<'a, 'a, T: 'a + Default> Foo<T> for u32 {}
| +++++++++++++++++++++ ~
LL - impl<'a> Foo<T: 'a + Default> for u32 {}
LL + impl<'a, 'a, T: 'a + Default> Foo<T> for u32 {}
|

error[E0229]: associated item constraints are not allowed here
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:23:10
Expand All @@ -58,8 +62,9 @@ LL | impl Bar<T: Default, K: Default> for String {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<T: Default> Bar<T, K: Default> for String {}
| ++++++++++++ ~
LL - impl Bar<T: Default, K: Default> for String {}
LL + impl<T: Default> Bar<T, K: Default> for String {}
|

error[E0107]: trait takes 2 generic arguments but 1 generic argument was supplied
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:27:9
Expand Down Expand Up @@ -87,8 +92,9 @@ LL | impl<T> Bar<T, K: Default> for u8 {}
|
help: declare the type parameter right after the `impl` keyword
|
LL | impl<T, K: Default> Bar<T, K> for u8 {}
| ++++++++++++ ~
LL - impl<T> Bar<T, K: Default> for u8 {}
LL + impl<T, K: Default> Bar<T, K> for u8 {}
|

error: aborting due to 8 previous errors

Expand Down
Loading