-
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.
- Loading branch information
Showing
3 changed files
with
96 additions
and
19 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
34 changes: 34 additions & 0 deletions
34
src/test/ui/generic-associated-types/type-param-defaults.rs
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Check that we disallow GAT param defaults, even with `invalid_type_param_default` allowed | ||
|
||
#![allow(invalid_type_param_default)] | ||
|
||
trait Trait { | ||
type Assoc<T = u32>; | ||
//~^ defaults for type parameters are only allowed | ||
} | ||
|
||
impl Trait for () { | ||
type Assoc<T = u32> = u64; | ||
//~^ defaults for type parameters are only allowed | ||
} | ||
|
||
impl Trait for u32 { | ||
type Assoc<T = u32> = T; | ||
//~^ defaults for type parameters are only allowed | ||
} | ||
|
||
trait Other {} | ||
impl Other for u32 {} | ||
|
||
fn foo<T>() | ||
where | ||
T: Trait<Assoc = u32>, | ||
T::Assoc: Other { | ||
} | ||
|
||
fn main() { | ||
// errors | ||
foo::<()>(); | ||
// works | ||
foo::<u32>(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/generic-associated-types/type-param-defaults.stderr
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/type-param-defaults.rs:6:16 | ||
| | ||
LL | type Assoc<T = u32>; | ||
| ^^^^^^^ | ||
|
||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/type-param-defaults.rs:11:16 | ||
| | ||
LL | type Assoc<T = u32> = u64; | ||
| ^^^^^^^ | ||
|
||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/type-param-defaults.rs:16:16 | ||
| | ||
LL | type Assoc<T = u32> = T; | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|