Skip to content
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

Provide more context when denying invalid type params #97471

Merged
merged 7 commits into from
Jun 3, 2022
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
364 changes: 287 additions & 77 deletions compiler/rustc_typeck/src/astconv/mod.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None
}
}),
|_| {},
);

if let Res::Local(hid) = res {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,13 +1564,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
QPath::TypeRelative(ref qself, ref segment) => {
let ty = self.to_ty(qself);

let res = if let hir::TyKind::Path(QPath::Resolved(_, ref path)) = qself.kind {
path.res
} else {
Res::Err
};
let result = <dyn AstConv<'_>>::associated_path_to_ty(
self, hir_id, path_span, ty, res, segment, true,
self, hir_id, path_span, ty, qself, segment, true,
);
let ty = result.map(|(ty, _, _)| ty).unwrap_or_else(|_| self.tcx().ty_error());
let result = result.map(|(_, kind, def_id)| (kind, def_id));
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/derives/issue-97343.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

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

Expand Down
12 changes: 10 additions & 2 deletions src/test/ui/derives/issue-97343.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on type parameter `Irrelevant`
--> $DIR/issue-97343.rs:4:23
|
LL | #[derive(Debug)]
| ----- in this derive macro expansion
| -----
| |
| not allowed on this
| in this derive macro expansion
LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^ type argument not allowed
|
note: type parameter `Irrelevant` defined here
--> $DIR/issue-97343.rs:4:23
|
LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
Expand Down
12 changes: 10 additions & 2 deletions src/test/ui/error-codes/E0109.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on this type
--> $DIR/E0109.rs:1:14
|
LL | type X = u32<i32>;
| ^^^ type argument not allowed
| --- ^^^ type argument not allowed
| |
| not allowed on this
|
help: primitive type `u32` doesn't have generic parameters
|
LL - type X = u32<i32>;
LL + type X = u32;
|

error: aborting due to previous error

Expand Down
12 changes: 10 additions & 2 deletions src/test/ui/error-codes/E0110.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
error[E0109]: lifetime arguments are not allowed for this type
error[E0109]: lifetime arguments are not allowed on this type
--> $DIR/E0110.rs:1:14
|
LL | type X = u32<'static>;
| ^^^^^^^ lifetime argument not allowed
| --- ^^^^^^^ lifetime argument not allowed
| |
| not allowed on this
|
help: primitive type `u32` doesn't have generic parameters
|
LL - type X = u32<'static>;
LL + type X = u32;
|

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-22706.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn is_copy<T: ::std::marker<i32>::Copy>() {}
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^ ERROR type arguments are not allowed on module `marker` [E0109]
fn main() {}
6 changes: 4 additions & 2 deletions src/test/ui/issues/issue-22706.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on module `marker`
--> $DIR/issue-22706.rs:1:29
|
LL | fn is_copy<T: ::std::marker<i32>::Copy>() {}
| ^^^ type argument not allowed
| ------ ^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-57924.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Gcm<E>(E);
impl<E> Gcm<E> {
pub fn crash(e: E) -> Self {
Self::<E>(e)
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on self constructor
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/issues/issue-57924.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self constructor
--> $DIR/issue-57924.rs:5:16
|
LL | Self::<E>(e)
| ^ type argument not allowed
| ---- ^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-60989.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl From<A> for B {
fn main() {
let c1 = ();
c1::<()>;
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on local variable

let c1 = A {};
c1::<dyn Into<B>>;
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on local variable
}
12 changes: 8 additions & 4 deletions src/test/ui/issues/issue-60989.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on local variable
--> $DIR/issue-60989.rs:12:10
|
LL | c1::<()>;
| ^^ type argument not allowed
| -- ^^ type argument not allowed
| |
| not allowed on this

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on local variable
--> $DIR/issue-60989.rs:16:10
|
LL | c1::<dyn Into<B>>;
| ^^^^^^^^^^^ type argument not allowed
| -- ^^^^^^^^^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mod-subitem-as-enum-variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod Mod {
fn main() {
Mod::FakeVariant::<i32>(0);
Mod::<i32>::FakeVariant(0);
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^ ERROR type arguments are not allowed on module `Mod` [E0109]
}
6 changes: 4 additions & 2 deletions src/test/ui/mod-subitem-as-enum-variant.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on module `Mod`
--> $DIR/mod-subitem-as-enum-variant.rs:7:11
|
LL | Mod::<i32>::FakeVariant(0);
| ^^^ type argument not allowed
| --- ^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/structs/struct-path-associated-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn f<T: Tr>() {
//~^ ERROR expected struct, variant or union type, found associated type
let z = T::A::<u8> {};
//~^ ERROR expected struct, variant or union type, found associated type
//~| ERROR type arguments are not allowed for this type
//~| ERROR type arguments are not allowed on this type
match S {
T::A {} => {}
//~^ ERROR expected struct, variant or union type, found associated type
Expand All @@ -22,7 +22,7 @@ fn f<T: Tr>() {

fn g<T: Tr<A = S>>() {
let s = T::A {}; // OK
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
match S {
T::A {} => {} // OK
}
Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/structs/struct-path-associated-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ error[E0071]: expected struct, variant or union type, found associated type
LL | let s = T::A {};
| ^^^^ not a struct

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

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

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on this type
--> $DIR/struct-path-associated-type.rs:25:20
|
LL | let z = T::A::<u8> {};
| ^^ type argument not allowed
| - ^^ type argument not allowed
| |
| not allowed on this

error[E0223]: ambiguous associated type
--> $DIR/struct-path-associated-type.rs:32:13
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/structs/struct-path-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trait Tr {
//~^ ERROR expected struct, variant or union type, found type parameter
let z = Self::<u8> {};
//~^ ERROR expected struct, variant or union type, found type parameter
//~| ERROR type arguments are not allowed for this type
//~| ERROR type arguments are not allowed on self type
match s {
Self { .. } => {}
//~^ ERROR expected struct, variant or union type, found type parameter
Expand All @@ -17,7 +17,7 @@ trait Tr {
impl Tr for S {
fn f() {
let s = Self {}; // OK
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
match s {
Self { .. } => {} // OK
}
Expand All @@ -27,7 +27,7 @@ impl Tr for S {
impl S {
fn g() {
let s = Self {}; // OK
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
match s {
Self { .. } => {} // OK
}
Expand Down
52 changes: 46 additions & 6 deletions src/test/ui/structs/struct-path-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
LL | let s = Self {};
| ^^^^ not a struct

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:7:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
help: the `Self` type doesn't accept type parameters
|
LL - let z = Self::<u8> {};
LL + let z = Self {};
|

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

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:20:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
note: `Self` is of type `S`
--> $DIR/struct-path-self.rs:1:8
|
LL | struct S;
| ^ `Self` corresponds to this type, which doesn't have generic parameters
...
LL | impl Tr for S {
| ------------- `Self` is on type `S` in this `impl`
help: the `Self` type doesn't accept type parameters
|
LL - let z = Self::<u8> {};
LL + let z = Self {};
|

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:30:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
note: `Self` is of type `S`
--> $DIR/struct-path-self.rs:1:8
|
LL | struct S;
| ^ `Self` corresponds to this type, which doesn't have generic parameters
...
LL | impl S {
| ------ `Self` is on type `S` in this `impl`
help: the `Self` type doesn't accept type parameters
|
LL - let z = Self::<u8> {};
LL + let z = Self {};
|

error: aborting due to 6 previous errors

Expand Down
Loading