-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit suggestions when equality constraints are wronlgy used
- Loading branch information
Showing
17 changed files
with
421 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,53 @@ | ||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-102335-ty.rs:2:17 | ||
| | ||
LL | type A: S<C<i32 = u32> = ()>; | ||
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint | ||
| ^^^^^^^^^ associated type not allowed here | ||
| | ||
= note: `C` is not a generic type | ||
help: try removing this type binding | ||
| | ||
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint | ||
| ~~~~~~~~~~~ | ||
|
||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-102335-ty.rs:2:17 | ||
| | ||
LL | type A: S<C<i32 = u32> = ()>; | ||
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint | ||
| ^^^^^^^^^ associated type not allowed here | ||
| | ||
= note: `C` is not a generic type | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
help: try removing this type binding | ||
| | ||
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint | ||
| ~~~~~~~~~~~ | ||
|
||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-102335-ty.rs:8:17 | ||
| | ||
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints | ||
| ^^^^^^^^^ associated type not allowed here | ||
| | ||
= note: `C` is not a generic type | ||
help: try removing this type binding | ||
| | ||
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints | ||
| ~~~~~~~~~~ | ||
|
||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-102335-ty.rs:8:17 | ||
| | ||
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints | ||
| ^^^^^^^^^ associated type not allowed here | ||
| | ||
= note: `C` is not a generic type | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
help: try removing this type binding | ||
| | ||
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints | ||
| ~~~~~~~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0229`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,69 @@ | ||
// Test equality constraints on associated types. Check we get an error when an | ||
// equality constraint is used in a qualified path. | ||
// equality constraint is used outside of type parameter declarations | ||
|
||
pub trait Foo { | ||
type A; | ||
fn boo(&self) -> <Self as Foo>::A; | ||
} | ||
|
||
struct Bar; | ||
struct Qux; | ||
|
||
impl Foo for isize { | ||
type A = usize; | ||
fn boo(&self) -> usize { 42 } | ||
} | ||
|
||
fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {} | ||
fn baz<I: Foo>(_x: &<I as Foo<A=Bar>>::A) {} | ||
//~^ ERROR associated type bindings are not allowed here | ||
|
||
|
||
trait Tr1<T1> { | ||
} | ||
|
||
impl Tr1<T1 = String> for Bar { | ||
//~^ ERROR associated type bindings are not allowed here | ||
//~| ERROR trait takes 1 generic argument but 0 generic arguments were supplied | ||
} | ||
|
||
|
||
trait Tr2<T1, T2, T3> { | ||
} | ||
|
||
// E0229 is emitted only for the first erroneous equality | ||
// constraint (T2) not for any subequent ones (e.g. T3) | ||
impl Tr2<i32, T2 = Qux, T3 = usize> for Bar { | ||
//~^ ERROR associated type bindings are not allowed here | ||
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied | ||
} | ||
|
||
struct GenericStruct<T> { _t: T } | ||
|
||
impl Tr2<i32, Qux, T3 = GenericStruct<i32>> for Bar { | ||
//~^ ERROR associated type bindings are not allowed here | ||
//~| ERROR trait takes 3 generic arguments but 2 generic arguments were supplied | ||
} | ||
|
||
|
||
// Covers the case when the type has a const param | ||
trait Tr3<const N: i32, T2, T3> { | ||
} | ||
|
||
impl Tr3<N = 42, T2 = Qux, T3 = usize> for Bar { | ||
//~^ ERROR associated type bindings are not allowed here | ||
//~| ERROR associated const equality is incomplete | ||
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied | ||
} | ||
|
||
|
||
// Covers the case when the type | ||
// in question has no generic params | ||
trait Tr4 { | ||
} | ||
|
||
impl Tr4<T = Qux, T2 = usize> for Bar { | ||
//~^ ERROR associated type bindings are not allowed here | ||
} | ||
|
||
|
||
pub fn main() {} |
Oops, something went wrong.