Skip to content

Commit 6b80b15

Browse files
authored
Rollup merge of #97471 - estebank:prohibit-generics, r=cjgillot
Provide more context when denying invalid type params
2 parents 53ab3b2 + cd8cfbf commit 6b80b15

30 files changed

+998
-315
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+287-77
Large diffs are not rendered by default.

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12281228
None
12291229
}
12301230
}),
1231+
|_| {},
12311232
);
12321233

12331234
if let Res::Local(hid) = res {

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1564,13 +1564,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15641564
QPath::TypeRelative(ref qself, ref segment) => {
15651565
let ty = self.to_ty(qself);
15661566

1567-
let res = if let hir::TyKind::Path(QPath::Resolved(_, ref path)) = qself.kind {
1568-
path.res
1569-
} else {
1570-
Res::Err
1571-
};
15721567
let result = <dyn AstConv<'_>>::associated_path_to_ty(
1573-
self, hir_id, path_span, ty, res, segment, true,
1568+
self, hir_id, path_span, ty, qself, segment, true,
15741569
);
15751570
let ty = result.map(|(ty, _, _)| ty).unwrap_or_else(|_| self.tcx().ty_error());
15761571
let result = result.map(|(_, kind, def_id)| (kind, def_id));

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
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
|
12+
note: type parameter `Irrelevant` defined here
13+
--> $DIR/issue-97343.rs:4:23
14+
|
15+
LL | pub struct Irrelevant<Irrelevant> {
16+
| ^^^^^^^^^^
917
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
1018

1119
error: aborting due to previous error

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
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
8+
|
9+
help: primitive type `u32` doesn't have generic parameters
10+
|
11+
LL - type X = u32<i32>;
12+
LL + type X = u32;
13+
|
614

715
error: aborting due to previous error
816

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
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
8+
|
9+
help: primitive type `u32` doesn't have generic parameters
10+
|
11+
LL - type X = u32<'static>;
12+
LL + type X = u32;
13+
|
614

715
error: aborting due to previous error
816

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

+46-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ 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
14+
|
15+
help: the `Self` type doesn't accept type parameters
16+
|
17+
LL - let z = Self::<u8> {};
18+
LL + let z = Self {};
19+
|
1220

1321
error[E0071]: expected struct, variant or union type, found type parameter `Self`
1422
--> $DIR/struct-path-self.rs:7:17
@@ -22,17 +30,49 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
2230
LL | Self { .. } => {}
2331
| ^^^^ not a struct
2432

25-
error[E0109]: type arguments are not allowed for this type
33+
error[E0109]: type arguments are not allowed on self type
2634
--> $DIR/struct-path-self.rs:20:24
2735
|
2836
LL | let z = Self::<u8> {};
29-
| ^^ type argument not allowed
37+
| ---- ^^ type argument not allowed
38+
| |
39+
| not allowed on this
40+
|
41+
note: `Self` is of type `S`
42+
--> $DIR/struct-path-self.rs:1:8
43+
|
44+
LL | struct S;
45+
| ^ `Self` corresponds to this type, which doesn't have generic parameters
46+
...
47+
LL | impl Tr for S {
48+
| ------------- `Self` is on type `S` in this `impl`
49+
help: the `Self` type doesn't accept type parameters
50+
|
51+
LL - let z = Self::<u8> {};
52+
LL + let z = Self {};
53+
|
3054

31-
error[E0109]: type arguments are not allowed for this type
55+
error[E0109]: type arguments are not allowed on self type
3256
--> $DIR/struct-path-self.rs:30:24
3357
|
3458
LL | let z = Self::<u8> {};
35-
| ^^ type argument not allowed
59+
| ---- ^^ type argument not allowed
60+
| |
61+
| not allowed on this
62+
|
63+
note: `Self` is of type `S`
64+
--> $DIR/struct-path-self.rs:1:8
65+
|
66+
LL | struct S;
67+
| ^ `Self` corresponds to this type, which doesn't have generic parameters
68+
...
69+
LL | impl S {
70+
| ------ `Self` is on type `S` in this `impl`
71+
help: the `Self` type doesn't accept type parameters
72+
|
73+
LL - let z = Self::<u8> {};
74+
LL + let z = Self {};
75+
|
3676

3777
error: aborting due to 6 previous errors
3878

0 commit comments

Comments
 (0)