Skip to content

Commit eeb76eb

Browse files
Rollup merge of rust-lang#106533 - TaKO8Ki:use-smaller-span-for-missing-lifetime/generic-args, r=compiler-errors
Use smaller spans for missing lifetime/generic args We can remove ident from suggestions.
2 parents 258257a + 804dea9 commit eeb76eb

28 files changed

+70
-62
lines changed

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
597597
let span = self.path_segment.ident.span;
598598

599599
// insert a suggestion of the form "Y<'a, 'b>"
600-
let ident = self.path_segment.ident.name.to_ident_string();
601-
let sugg = format!("{}<{}>", ident, suggested_args);
600+
let sugg = format!("<{}>", suggested_args);
602601
debug!("sugg: {:?}", sugg);
603602

604-
err.span_suggestion_verbose(span, &msg, sugg, Applicability::HasPlaceholders);
603+
err.span_suggestion_verbose(
604+
span.shrink_to_hi(),
605+
&msg,
606+
sugg,
607+
Applicability::HasPlaceholders,
608+
);
605609
}
606610

607611
AngleBrackets::Available => {
@@ -643,11 +647,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
643647
let span = self.path_segment.ident.span;
644648

645649
// insert a suggestion of the form "Y<T, U>"
646-
let ident = self.path_segment.ident.name.to_ident_string();
647-
let sugg = format!("{}<{}>", ident, suggested_args);
650+
let sugg = format!("<{}>", suggested_args);
648651
debug!("sugg: {:?}", sugg);
649652

650-
err.span_suggestion_verbose(span, &msg, sugg, Applicability::HasPlaceholders);
653+
err.span_suggestion_verbose(
654+
span.shrink_to_hi(),
655+
&msg,
656+
sugg,
657+
Applicability::HasPlaceholders,
658+
);
651659
}
652660
AngleBrackets::Available => {
653661
let gen_args_span = self.gen_args.span().unwrap();

src/test/rustdoc-ui/issue-105742.stderr

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Item<'a, T>;
1212
help: add missing lifetime argument
1313
|
1414
LL | <Self as SVec>::Item<'a>,
15-
| ~~~~~~~~
15+
| ++++
1616

1717
error[E0107]: missing generics for associated type `SVec::Item`
1818
--> $DIR/issue-105742.rs:13:21
@@ -28,7 +28,7 @@ LL | type Item<'a, T>;
2828
help: add missing generic argument
2929
|
3030
LL | <Self as SVec>::Item<T>,
31-
| ~~~~~~~
31+
| +++
3232

3333
error[E0107]: missing generics for associated type `SVec::Item`
3434
--> $DIR/issue-105742.rs:18:37
@@ -44,7 +44,7 @@ LL | type Item<'a, T>;
4444
help: add missing lifetime argument
4545
|
4646
LL | Output = <Index<<Self as SVec>::Item<'a>,
47-
| ~~~~~~~~
47+
| ++++
4848

4949
error[E0107]: missing generics for associated type `SVec::Item`
5050
--> $DIR/issue-105742.rs:18:37
@@ -60,7 +60,7 @@ LL | type Item<'a, T>;
6060
help: add missing generic argument
6161
|
6262
LL | Output = <Index<<Self as SVec>::Item<T>,
63-
| ~~~~~~~
63+
| +++
6464

6565
error[E0107]: missing generics for associated type `SVec::Item`
6666
--> $DIR/issue-105742.rs:23:30
@@ -76,7 +76,7 @@ LL | type Item<'a, T>;
7676
help: add missing lifetime argument
7777
|
7878
LL | Output = <Self as SVec>::Item<'a>> as SVec>::Item,
79-
| ~~~~~~~~
79+
| ++++
8080

8181
error[E0107]: missing generics for associated type `SVec::Item`
8282
--> $DIR/issue-105742.rs:23:30
@@ -92,7 +92,7 @@ LL | type Item<'a, T>;
9292
help: add missing generic argument
9393
|
9494
LL | Output = <Self as SVec>::Item<T>> as SVec>::Item,
95-
| ~~~~~~~
95+
| +++
9696

9797
error[E0107]: missing generics for associated type `SVec::Item`
9898
--> $DIR/issue-105742.rs:23:46
@@ -108,7 +108,7 @@ LL | type Item<'a, T>;
108108
help: add missing lifetime argument
109109
|
110110
LL | Output = <Self as SVec>::Item> as SVec>::Item<'a>,
111-
| ~~~~~~~~
111+
| ++++
112112

113113
error[E0107]: missing generics for associated type `SVec::Item`
114114
--> $DIR/issue-105742.rs:23:46
@@ -124,7 +124,7 @@ LL | type Item<'a, T>;
124124
help: add missing generic argument
125125
|
126126
LL | Output = <Self as SVec>::Item> as SVec>::Item<T>,
127-
| ~~~~~~~
127+
| +++
128128

129129
error[E0107]: missing generics for associated type `SVec::Item`
130130
--> $DIR/issue-105742.rs:5:40
@@ -140,7 +140,7 @@ LL | type Item<'a, T>;
140140
help: add missing lifetime argument
141141
|
142142
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item<'_> = T, Output = T>) {
143-
| ~~~~~~~~
143+
| ++++
144144

145145
error[E0107]: missing generics for associated type `SVec::Item`
146146
--> $DIR/issue-105742.rs:5:40
@@ -156,7 +156,7 @@ LL | type Item<'a, T>;
156156
help: add missing generic argument
157157
|
158158
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item<T> = T, Output = T>) {
159-
| ~~~~~~~
159+
| +++
160160

161161
error[E0107]: missing generics for associated type `SVec::Item`
162162
--> $DIR/issue-105742.rs:13:21
@@ -172,7 +172,7 @@ LL | type Item<'a, T>;
172172
help: add missing lifetime argument
173173
|
174174
LL | <Self as SVec>::Item<'a>,
175-
| ~~~~~~~~
175+
| ++++
176176

177177
error[E0107]: missing generics for associated type `SVec::Item`
178178
--> $DIR/issue-105742.rs:13:21
@@ -188,7 +188,7 @@ LL | type Item<'a, T>;
188188
help: add missing generic argument
189189
|
190190
LL | <Self as SVec>::Item<T>,
191-
| ~~~~~~~
191+
| +++
192192

193193
error[E0107]: missing generics for associated type `SVec::Item`
194194
--> $DIR/issue-105742.rs:18:37
@@ -204,7 +204,7 @@ LL | type Item<'a, T>;
204204
help: add missing lifetime argument
205205
|
206206
LL | Output = <Index<<Self as SVec>::Item<'a>,
207-
| ~~~~~~~~
207+
| ++++
208208

209209
error[E0107]: missing generics for associated type `SVec::Item`
210210
--> $DIR/issue-105742.rs:18:37
@@ -220,7 +220,7 @@ LL | type Item<'a, T>;
220220
help: add missing generic argument
221221
|
222222
LL | Output = <Index<<Self as SVec>::Item<T>,
223-
| ~~~~~~~
223+
| +++
224224

225225
error[E0107]: missing generics for associated type `SVec::Item`
226226
--> $DIR/issue-105742.rs:23:30
@@ -236,7 +236,7 @@ LL | type Item<'a, T>;
236236
help: add missing lifetime argument
237237
|
238238
LL | Output = <Self as SVec>::Item<'a>> as SVec>::Item,
239-
| ~~~~~~~~
239+
| ++++
240240

241241
error[E0107]: missing generics for associated type `SVec::Item`
242242
--> $DIR/issue-105742.rs:23:30
@@ -252,7 +252,7 @@ LL | type Item<'a, T>;
252252
help: add missing generic argument
253253
|
254254
LL | Output = <Self as SVec>::Item<T>> as SVec>::Item,
255-
| ~~~~~~~
255+
| +++
256256

257257
error[E0107]: missing generics for associated type `SVec::Item`
258258
--> $DIR/issue-105742.rs:23:46
@@ -268,7 +268,7 @@ LL | type Item<'a, T>;
268268
help: add missing lifetime argument
269269
|
270270
LL | Output = <Self as SVec>::Item> as SVec>::Item<'a>,
271-
| ~~~~~~~~
271+
| ++++
272272

273273
error[E0107]: missing generics for associated type `SVec::Item`
274274
--> $DIR/issue-105742.rs:23:46
@@ -284,7 +284,7 @@ LL | type Item<'a, T>;
284284
help: add missing generic argument
285285
|
286286
LL | Output = <Self as SVec>::Item> as SVec>::Item<T>,
287-
| ~~~~~~~
287+
| +++
288288

289289
error[E0038]: the trait `SVec` cannot be made into an object
290290
--> $DIR/issue-105742.rs:5:31
@@ -329,7 +329,7 @@ LL | type Item<'a, T>;
329329
help: add missing lifetime argument
330330
|
331331
LL | fn len(&self) -> <Self as SVec>::Item<'_>;
332-
| ~~~~~~~~
332+
| ++++
333333

334334
error[E0107]: missing generics for associated type `SVec::Item`
335335
--> $DIR/issue-105742.rs:35:38
@@ -345,7 +345,7 @@ LL | type Item<'a, T>;
345345
help: add missing generic argument
346346
|
347347
LL | fn len(&self) -> <Self as SVec>::Item<T>;
348-
| ~~~~~~~
348+
| +++
349349

350350
error[E0107]: missing generics for associated type `SVec::Item`
351351
--> $DIR/issue-105742.rs:35:38
@@ -361,7 +361,7 @@ LL | type Item<'a, T>;
361361
help: add missing lifetime argument
362362
|
363363
LL | fn len(&self) -> <Self as SVec>::Item<'_>;
364-
| ~~~~~~~~
364+
| ++++
365365

366366
error[E0107]: missing generics for associated type `SVec::Item`
367367
--> $DIR/issue-105742.rs:35:38
@@ -377,7 +377,7 @@ LL | type Item<'a, T>;
377377
help: add missing generic argument
378378
|
379379
LL | fn len(&self) -> <Self as SVec>::Item<T>;
380-
| ~~~~~~~
380+
| +++
381381

382382
error: aborting due to 23 previous errors
383383

src/test/ui/consts/issue-103790.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | struct S<const S: (), const S: S = { S }>;
2020
help: add missing generic argument
2121
|
2222
LL | struct S<const S: (), const S: S<S> = { S }>;
23-
| ~~~~
23+
| +++
2424

2525
error[E0391]: cycle detected when computing type of `S::S`
2626
--> $DIR/issue-103790.rs:4:32

src/test/ui/generic-associated-types/elided-in-expr-position.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Assoc<'a> where Self: 'a;
1212
help: add missing lifetime argument
1313
|
1414
LL | fn g(&self) -> Self::Assoc<'_>;
15-
| ~~~~~~~~~
15+
| ++++
1616

1717
error[E0107]: missing generics for associated type `Trait::Assoc`
1818
--> $DIR/elided-in-expr-position.rs:31:26
@@ -28,7 +28,7 @@ LL | type Assoc<'a> where Self: 'a;
2828
help: add missing lifetime argument
2929
|
3030
LL | fn g(&self) -> Self::Assoc<'_> {
31-
| ~~~~~~~~~
31+
| ++++
3232

3333
error: aborting due to 2 previous errors
3434

src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Y<'a>;
1212
help: add missing lifetime argument
1313
|
1414
LL | fn foo<'a, T1: X<Y<'a> = T1>>(t : T1) -> T1::Y<'a> {
15-
| ~~~~~
15+
| ++++
1616

1717
error[E0107]: missing generics for associated type `X::Y`
1818
--> $DIR/gat-trait-path-missing-lifetime.rs:8:20
@@ -28,7 +28,7 @@ LL | type Y<'a>;
2828
help: add missing lifetime argument
2929
|
3030
LL | fn foo<'a, T1: X<Y<'a> = T1>>(t : T1) -> T1::Y<'a> {
31-
| ~~~~~
31+
| ++++
3232

3333
error: aborting due to 2 previous errors
3434

src/test/ui/generic-associated-types/issue-71176.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type A<'a>;
1212
help: add missing lifetime argument
1313
|
1414
LL | inner: Box<dyn Provider<A<'a> = B>>,
15-
| ~~~~~
15+
| ++++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-76535.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type SubType<'a>: SubTrait where Self: 'a;
1212
help: add missing lifetime argument
1313
|
1414
LL | let sub: Box<dyn SuperTrait<SubType<'a> = SubStruct>> = Box::new(SuperStruct::new(0));
15-
| ~~~~~~~~~~~
15+
| ++++
1616

1717
error[E0038]: the trait `SuperTrait` cannot be made into an object
1818
--> $DIR/issue-76535.rs:39:14

src/test/ui/generic-associated-types/issue-76535.extended.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type SubType<'a>: SubTrait where Self: 'a;
1212
help: add missing lifetime argument
1313
|
1414
LL | let sub: Box<dyn SuperTrait<SubType<'a> = SubStruct>> = Box::new(SuperStruct::new(0));
15-
| ~~~~~~~~~~~
15+
| ++++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-78671.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Member<T>;
1212
help: add missing generic argument
1313
|
1414
LL | Box::new(Family) as &dyn CollectionFamily<Member<T>=usize>
15-
| ~~~~~~~~~
15+
| +++
1616

1717
error[E0038]: the trait `CollectionFamily` cannot be made into an object
1818
--> $DIR/issue-78671.rs:10:25

src/test/ui/generic-associated-types/issue-78671.extended.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Member<T>;
1212
help: add missing generic argument
1313
|
1414
LL | Box::new(Family) as &dyn CollectionFamily<Member<T>=usize>
15-
| ~~~~~~~~~
15+
| +++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-79422.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
1212
help: add missing lifetime argument
1313
|
1414
LL | as Box<dyn MapLike<u8, u8, VRefCont<'a> = dyn RefCont<'_, u8>>>;
15-
| ~~~~~~~~~~~~
15+
| ++++
1616

1717
error[E0038]: the trait `MapLike` cannot be made into an object
1818
--> $DIR/issue-79422.rs:47:12

src/test/ui/generic-associated-types/issue-79422.extended.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
1212
help: add missing lifetime argument
1313
|
1414
LL | as Box<dyn MapLike<u8, u8, VRefCont<'a> = dyn RefCont<'_, u8>>>;
15-
| ~~~~~~~~~~~~
15+
| ++++
1616

1717
error[E0271]: type mismatch resolving `<BTreeMap<u8, u8> as MapLike<u8, u8>>::VRefCont<'_> == (dyn RefCont<'_, u8> + 'static)`
1818
--> $DIR/issue-79422.rs:44:13

src/test/ui/generic-associated-types/issue-79636-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Wrapped<B>;
1212
help: add missing generic argument
1313
|
1414
LL | MInner: Monad<Unwrapped = A, Wrapped<B> = MOuter::Wrapped<A>>,
15-
| ~~~~~~~~~~
15+
| +++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-79636-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Wrapped<A>: SomeTrait;
1212
help: add missing generic argument
1313
|
1414
LL | W: SomeTrait<Wrapped<A> = W>,
15-
| ~~~~~~~~~~
15+
| +++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-80433.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Output<'a>;
1212
help: add missing lifetime argument
1313
|
1414
LL | fn test_simpler<'a>(dst: &'a mut impl TestMut<Output<'a> = &'a mut f32>)
15-
| ~~~~~~~~~~
15+
| ++++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-81712-cyclic-traits.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type DType<T>: D<T, CType = Self>;
1212
help: add missing generic argument
1313
|
1414
LL | type CType: C<DType<T> = Self>;
15-
| ~~~~~~~~
15+
| +++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/issue-81862.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Item<'a>;
1212
help: add missing lifetime argument
1313
|
1414
LL | fn next(&mut self) -> Option<Self::Item<'_>>;
15-
| ~~~~~~~~
15+
| ++++
1616

1717
error: aborting due to previous error
1818

src/test/ui/generic-associated-types/missing_lifetime_args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Y<'a, 'b>;
1212
help: add missing lifetime arguments
1313
|
1414
LL | fn foo<'c, 'd>(_arg: Box<dyn X<Y<'_, '_> = (&'c u32, &'d u32)>>) {}
15-
| ~~~~~~~~~
15+
| ++++++++
1616

1717
error[E0107]: this struct takes 3 lifetime arguments but 2 lifetime arguments were supplied
1818
--> $DIR/missing_lifetime_args.rs:14:26

0 commit comments

Comments
 (0)