Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d78be31

Browse files
Rollup merge of #127888 - estebank:type-param-sugg, r=compiler-errors
More accurate span for type parameter suggestion After: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL - impl Foo<T: Default> for String {} LL + impl<T: Default> Foo<T> for String {} | ``` Before: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL | impl<T: Default> Foo<T> for String {} | ++++++++++++ ~ ```
2 parents b52883d + be9d961 commit d78be31

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,13 @@ pub fn prohibit_assoc_item_constraint(
13381338
format!("<{lifetimes}{type_with_constraints}>"),
13391339
)
13401340
};
1341-
let suggestions =
1342-
vec![param_decl, (constraint.span, format!("{}", matching_param.name))];
1341+
let suggestions = vec![
1342+
param_decl,
1343+
(constraint.span.with_lo(constraint.ident.span.hi()), String::new()),
1344+
];
13431345

13441346
err.multipart_suggestion_verbose(
1345-
format!("declare the type parameter right after the `impl` keyword"),
1347+
"declare the type parameter right after the `impl` keyword",
13461348
suggestions,
13471349
Applicability::MaybeIncorrect,
13481350
);

‎tests/ui/generics/impl-block-params-declared-in-wrong-spot-issue-113073.stderr‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ LL | impl Foo<T: Default> for String {}
1414
|
1515
help: declare the type parameter right after the `impl` keyword
1616
|
17-
LL | impl<T: Default> Foo<T> for String {}
18-
| ++++++++++++ ~
17+
LL - impl Foo<T: Default> for String {}
18+
LL + impl<T: Default> Foo<T> for String {}
19+
|
1920

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

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

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

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

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

9399
error: aborting due to 8 previous errors
94100

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /