Skip to content

Commit ad63f90

Browse files
committed
Make output more specific
1 parent 196a30e commit ad63f90

28 files changed

+391
-217
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+45-2
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,46 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21082108
extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
21092109
) -> bool {
21102110
let args = segments.clone().flat_map(|segment| segment.args().args);
2111+
let types_and_spans: Vec<_> = segments
2112+
.clone()
2113+
.flat_map(|segment| {
2114+
segment.res.and_then(|res| {
2115+
if segment.args().args.is_empty() {
2116+
None
2117+
} else {
2118+
let mut desc = res.descr();
2119+
if desc == "unresolved item" {
2120+
desc = "this type";
2121+
};
2122+
2123+
let name = match res {
2124+
Res::PrimTy(ty) => Some(ty.name()),
2125+
Res::Def(_, def_id) => self.tcx().opt_item_name(def_id),
2126+
_ => None,
2127+
};
2128+
Some((
2129+
match name {
2130+
Some(ty) => format!("{desc} `{ty}`"),
2131+
None => desc.to_string(),
2132+
},
2133+
segment.ident.span,
2134+
))
2135+
}
2136+
})
2137+
})
2138+
.collect();
2139+
let this_type = match &types_and_spans[..] {
2140+
[.., _, (last, _)] => format!(
2141+
"{} and {last}",
2142+
types_and_spans[..types_and_spans.len() - 1]
2143+
.iter()
2144+
.map(|(x, _)| x.as_str())
2145+
.intersperse(&", ")
2146+
.collect::<String>()
2147+
),
2148+
[(only, _)] => only.to_string(),
2149+
[] => "this type".to_string(),
2150+
};
21112151

21122152
let (lt, ty, ct, inf) =
21132153
args.clone().fold((false, false, false, false), |(lt, ty, ct, inf), arg| match arg {
@@ -2143,7 +2183,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21432183
let (kind, s) = match types[..] {
21442184
[.., _, last] => (
21452185
format!(
2146-
"{} and `{last}`",
2186+
"{} and {last}",
21472187
types[..types.len() - 1]
21482188
.iter()
21492189
.map(|&x| x)
@@ -2161,9 +2201,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21612201
self.tcx().sess,
21622202
span,
21632203
E0109,
2164-
"{kind} arguments are not allowed for this type",
2204+
"{kind} arguments are not allowed on {this_type}",
21652205
);
21662206
err.span_label(last_span, format!("{kind} argument{s} not allowed"));
2207+
for (_, span) in types_and_spans {
2208+
err.span_label(span, "not allowed on this");
2209+
}
21672210
extend(&mut err);
21682211
err.emit();
21692212
emitted = true;

src/test/ui/derives/issue-97343.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22

33
#[derive(Debug)]
4-
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed for this type
4+
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter
55
irrelevant: Irrelevant,
66
}
77

src/test/ui/derives/issue-97343.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on type parameter `Irrelevant`
22
--> $DIR/issue-97343.rs:4:23
33
|
44
LL | #[derive(Debug)]
5-
| ----- in this derive macro expansion
5+
| -----
6+
| |
7+
| not allowed on this
8+
| in this derive macro expansion
69
LL | pub struct Irrelevant<Irrelevant> {
710
| ^^^^^^^^^^ type argument not allowed
811
|

src/test/ui/error-codes/E0109.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on this type
22
--> $DIR/E0109.rs:1:14
33
|
44
LL | type X = u32<i32>;
5-
| ^^^ type argument not allowed
5+
| --- ^^^ type argument not allowed
6+
| |
7+
| not allowed on this
68
|
79
help: primitive type `u32` doesn't have type parameters
810
|

src/test/ui/error-codes/E0110.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0109]: lifetime arguments are not allowed for this type
1+
error[E0109]: lifetime arguments are not allowed on this type
22
--> $DIR/E0110.rs:1:14
33
|
44
LL | type X = u32<'static>;
5-
| ^^^^^^^ lifetime argument not allowed
5+
| --- ^^^^^^^ lifetime argument not allowed
6+
| |
7+
| not allowed on this
68
|
79
help: primitive type `u32` doesn't have type parameters
810
|

src/test/ui/issues/issue-22706.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn is_copy<T: ::std::marker<i32>::Copy>() {}
2-
//~^ ERROR type arguments are not allowed for this type [E0109]
2+
//~^ ERROR type arguments are not allowed on module `marker` [E0109]
33
fn main() {}

src/test/ui/issues/issue-22706.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on module `marker`
22
--> $DIR/issue-22706.rs:1:29
33
|
44
LL | fn is_copy<T: ::std::marker<i32>::Copy>() {}
5-
| ^^^ type argument not allowed
5+
| ------ ^^^ type argument not allowed
6+
| |
7+
| not allowed on this
68

79
error: aborting due to previous error
810

src/test/ui/issues/issue-57924.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub struct Gcm<E>(E);
33
impl<E> Gcm<E> {
44
pub fn crash(e: E) -> Self {
55
Self::<E>(e)
6-
//~^ ERROR type arguments are not allowed for this type
6+
//~^ ERROR type arguments are not allowed on self constructor
77
}
88
}
99

src/test/ui/issues/issue-57924.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on self constructor
22
--> $DIR/issue-57924.rs:5:16
33
|
44
LL | Self::<E>(e)
5-
| ^ type argument not allowed
5+
| ---- ^ type argument not allowed
6+
| |
7+
| not allowed on this
68

79
error: aborting due to previous error
810

src/test/ui/issues/issue-60989.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ impl From<A> for B {
1010
fn main() {
1111
let c1 = ();
1212
c1::<()>;
13-
//~^ ERROR type arguments are not allowed for this type
13+
//~^ ERROR type arguments are not allowed on local variable
1414

1515
let c1 = A {};
1616
c1::<dyn Into<B>>;
17-
//~^ ERROR type arguments are not allowed for this type
17+
//~^ ERROR type arguments are not allowed on local variable
1818
}

src/test/ui/issues/issue-60989.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on local variable
22
--> $DIR/issue-60989.rs:12:10
33
|
44
LL | c1::<()>;
5-
| ^^ type argument not allowed
5+
| -- ^^ type argument not allowed
6+
| |
7+
| not allowed on this
68

7-
error[E0109]: type arguments are not allowed for this type
9+
error[E0109]: type arguments are not allowed on local variable
810
--> $DIR/issue-60989.rs:16:10
911
|
1012
LL | c1::<dyn Into<B>>;
11-
| ^^^^^^^^^^^ type argument not allowed
13+
| -- ^^^^^^^^^^^ type argument not allowed
14+
| |
15+
| not allowed on this
1216

1317
error: aborting due to 2 previous errors
1418

src/test/ui/mod-subitem-as-enum-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ mod Mod {
55
fn main() {
66
Mod::FakeVariant::<i32>(0);
77
Mod::<i32>::FakeVariant(0);
8-
//~^ ERROR type arguments are not allowed for this type [E0109]
8+
//~^ ERROR type arguments are not allowed on module `Mod` [E0109]
99
}

src/test/ui/mod-subitem-as-enum-variant.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0109]: type arguments are not allowed for this type
1+
error[E0109]: type arguments are not allowed on module `Mod`
22
--> $DIR/mod-subitem-as-enum-variant.rs:7:11
33
|
44
LL | Mod::<i32>::FakeVariant(0);
5-
| ^^^ type argument not allowed
5+
| --- ^^^ type argument not allowed
6+
| |
7+
| not allowed on this
68

79
error: aborting due to previous error
810

src/test/ui/structs/struct-path-associated-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn f<T: Tr>() {
1313
//~^ ERROR expected struct, variant or union type, found associated type
1414
let z = T::A::<u8> {};
1515
//~^ ERROR expected struct, variant or union type, found associated type
16-
//~| ERROR type arguments are not allowed for this type
16+
//~| ERROR type arguments are not allowed on this type
1717
match S {
1818
T::A {} => {}
1919
//~^ ERROR expected struct, variant or union type, found associated type
@@ -22,7 +22,7 @@ fn f<T: Tr>() {
2222

2323
fn g<T: Tr<A = S>>() {
2424
let s = T::A {}; // OK
25-
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed for this type
25+
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
2626
match S {
2727
T::A {} => {} // OK
2828
}

src/test/ui/structs/struct-path-associated-type.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ error[E0071]: expected struct, variant or union type, found associated type
44
LL | let s = T::A {};
55
| ^^^^ not a struct
66

7-
error[E0109]: type arguments are not allowed for this type
7+
error[E0109]: type arguments are not allowed on this type
88
--> $DIR/struct-path-associated-type.rs:14:20
99
|
1010
LL | let z = T::A::<u8> {};
11-
| ^^ type argument not allowed
11+
| - ^^ type argument not allowed
12+
| |
13+
| not allowed on this
1214

1315
error[E0071]: expected struct, variant or union type, found associated type
1416
--> $DIR/struct-path-associated-type.rs:14:13
@@ -22,11 +24,13 @@ error[E0071]: expected struct, variant or union type, found associated type
2224
LL | T::A {} => {}
2325
| ^^^^ not a struct
2426

25-
error[E0109]: type arguments are not allowed for this type
27+
error[E0109]: type arguments are not allowed on this type
2628
--> $DIR/struct-path-associated-type.rs:25:20
2729
|
2830
LL | let z = T::A::<u8> {};
29-
| ^^ type argument not allowed
31+
| - ^^ type argument not allowed
32+
| |
33+
| not allowed on this
3034

3135
error[E0223]: ambiguous associated type
3236
--> $DIR/struct-path-associated-type.rs:32:13

src/test/ui/structs/struct-path-self.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Tr {
66
//~^ ERROR expected struct, variant or union type, found type parameter
77
let z = Self::<u8> {};
88
//~^ ERROR expected struct, variant or union type, found type parameter
9-
//~| ERROR type arguments are not allowed for this type
9+
//~| ERROR type arguments are not allowed on self type
1010
match s {
1111
Self { .. } => {}
1212
//~^ ERROR expected struct, variant or union type, found type parameter
@@ -17,7 +17,7 @@ trait Tr {
1717
impl Tr for S {
1818
fn f() {
1919
let s = Self {}; // OK
20-
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
20+
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
2121
match s {
2222
Self { .. } => {} // OK
2323
}
@@ -27,7 +27,7 @@ impl Tr for S {
2727
impl S {
2828
fn g() {
2929
let s = Self {}; // OK
30-
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
30+
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
3131
match s {
3232
Self { .. } => {} // OK
3333
}

src/test/ui/structs/struct-path-self.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
44
LL | let s = Self {};
55
| ^^^^ not a struct
66

7-
error[E0109]: type arguments are not allowed for this type
7+
error[E0109]: type arguments are not allowed on self type
88
--> $DIR/struct-path-self.rs:7:24
99
|
1010
LL | let z = Self::<u8> {};
11-
| ^^ type argument not allowed
11+
| ---- ^^ type argument not allowed
12+
| |
13+
| not allowed on this
1214
|
1315
help: the `Self` type doesn't accept type parameters
1416
|
@@ -28,11 +30,13 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
2830
LL | Self { .. } => {}
2931
| ^^^^ not a struct
3032

31-
error[E0109]: type arguments are not allowed for this type
33+
error[E0109]: type arguments are not allowed on self type
3234
--> $DIR/struct-path-self.rs:20:24
3335
|
3436
LL | let z = Self::<u8> {};
35-
| ^^ type argument not allowed
37+
| ---- ^^ type argument not allowed
38+
| |
39+
| not allowed on this
3640
|
3741
note: `Self` is of type `S`
3842
--> $DIR/struct-path-self.rs:1:8
@@ -48,11 +52,13 @@ LL - let z = Self::<u8> {};
4852
LL + let z = Self {};
4953
|
5054

51-
error[E0109]: type arguments are not allowed for this type
55+
error[E0109]: type arguments are not allowed on self type
5256
--> $DIR/struct-path-self.rs:30:24
5357
|
5458
LL | let z = Self::<u8> {};
55-
| ^^ type argument not allowed
59+
| ---- ^^ type argument not allowed
60+
| |
61+
| not allowed on this
5662
|
5763
note: `Self` is of type `S`
5864
--> $DIR/struct-path-self.rs:1:8

0 commit comments

Comments
 (0)