-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement consecutive shorthand projections
- Loading branch information
Showing
13 changed files
with
184 additions
and
43 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
16 changes: 16 additions & 0 deletions
16
tests/ui/associated-types/consecutive-shorthand-projections-ambiguous.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,16 @@ | ||
trait ChooseMe { | ||
type Type; | ||
} | ||
|
||
trait PickMe { | ||
type Type; | ||
} | ||
|
||
trait HaveItAll { | ||
type See: ChooseMe + PickMe; | ||
} | ||
|
||
struct Env<T: HaveItAll>(T::See::Type); | ||
//~^ ERROR ambiguous associated type `Type` in bounds of `<T as HaveItAll>::See` | ||
|
||
fn main() {} |
24 changes: 24 additions & 0 deletions
24
tests/ui/associated-types/consecutive-shorthand-projections-ambiguous.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,24 @@ | ||
error[E0221]: ambiguous associated type `Type` in bounds of `<T as HaveItAll>::See` | ||
--> $DIR/consecutive-shorthand-projections-ambiguous.rs:13:26 | ||
| | ||
LL | type Type; | ||
| --------- ambiguous `Type` from `ChooseMe` | ||
... | ||
LL | type Type; | ||
| --------- ambiguous `Type` from `PickMe` | ||
... | ||
LL | struct Env<T: HaveItAll>(T::See::Type); | ||
| ^^^^^^^^^^^^ ambiguous associated type `Type` | ||
| | ||
help: use fully-qualified syntax to disambiguate | ||
| | ||
LL | struct Env<T: HaveItAll>(<<T as HaveItAll>::See as ChooseMe>::Type); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
help: use fully-qualified syntax to disambiguate | ||
| | ||
LL | struct Env<T: HaveItAll>(<<T as HaveItAll>::See as PickMe>::Type); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0221`. |
75 changes: 75 additions & 0 deletions
75
tests/ui/associated-types/consecutive-shorthand-projections.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,75 @@ | ||
//@ check-pass | ||
|
||
fn factory0<T: Factory>() { | ||
let _: T::Output::Category; | ||
} | ||
|
||
fn factory1<T: Factory<Output: Product<Category = u16>>>(category: u16) { | ||
let _: T::Output::Category = category; | ||
} | ||
|
||
fn factory2<T: Factory>(_: T::Output::Category) {} | ||
|
||
trait Factory { | ||
type Output: Product; | ||
} | ||
|
||
impl Factory for () { | ||
type Output = u128; | ||
} | ||
|
||
trait Product { | ||
type Category; | ||
} | ||
|
||
impl Product for u128 { | ||
type Category = u16; | ||
} | ||
|
||
///////////////////////// | ||
|
||
fn chain<C: Chain<Link = C>>(chain: C) { | ||
let _: C::Link::Link::Link::Link::Link = chain; | ||
} | ||
|
||
trait Chain { type Link: Chain; } | ||
|
||
impl Chain for () { | ||
type Link = Self; | ||
} | ||
|
||
///////////////////////// | ||
|
||
fn scope<'r, T: Main<'static, (i32, U), 1>, U, const Q: usize>() { | ||
let _: T::Next<'r, (), Q>::Final; | ||
} | ||
|
||
trait Main<'a, T, const N: usize> { | ||
type Next<'b, U, const M: usize>: Aux<'a, 'b, (T, U), N, M>; | ||
} | ||
|
||
impl<'a, T, const N: usize> Main<'a, T, N> for () { | ||
type Next<'_b, _U, const _M: usize> = (); | ||
} | ||
|
||
trait Aux<'a, 'b, T, const N: usize, const M: usize> { | ||
type Final; | ||
} | ||
|
||
impl<'a, 'b, T, const N: usize, const M: usize> Aux<'a, 'b, T, N, M> for () { | ||
type Final = [[(T, &'a (), &'b ()); N]; M]; | ||
} | ||
|
||
///////////////////////// | ||
|
||
fn main() { | ||
factory0::<()>(); | ||
factory1::<()>(360); | ||
factory2::<()>(720); | ||
let _: <() as Factory>::Output::Product; | ||
|
||
chain(()); | ||
let _: <() as Chain>::Link::Link::Link; | ||
|
||
scope::<(), bool, 32>(); | ||
} |
5 changes: 4 additions & 1 deletion
5
tests/ui/issues/issue-23073.rs → tests/ui/associated-types/defaults-23073.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
//@ check-pass | ||
|
||
#![feature(associated_type_defaults)] | ||
|
||
trait Foo { type T; } | ||
|
||
trait Bar { | ||
type Foo: Foo; | ||
type FooT = <<Self as Bar>::Foo>::T; //~ ERROR ambiguous associated type | ||
type FooT = <<Self as Bar>::Foo>::T; | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
tests/ui/associated-types/semi-consecutive-shorthand-projections.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,16 @@ | ||
// FIXME(fmease): Should we allow this as part of this MVP? | ||
// Of course, under #22519 (arbitrary shorthand projections), this should obviously typeck. | ||
// For reference, `T::Alias` typeck'ing does *not* imply `Identity<T>::Alias` typeck'ing. | ||
//@ check-pass | ||
|
||
type Identity<T> = T; | ||
|
||
trait Trait { | ||
type Project; | ||
} | ||
|
||
fn scope<T: Trait>() { | ||
let _: Identity<T>::Project; | ||
} | ||
|
||
fn main() {} |
This file was deleted.
Oops, something went wrong.
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,14 +1,9 @@ | ||
error[E0223]: ambiguous associated type | ||
--> $DIR/qualified-path-params-2.rs:18:10 | ||
error[E0220]: associated type `f` not found for `<S as Tr>::A` | ||
--> $DIR/qualified-path-params-2.rs:17:24 | ||
| | ||
LL | type A = <S as Tr>::A::f<u8>; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: if there were a trait named `Example` with associated type `f` implemented for `<S as Tr>::A`, you could use the fully-qualified path | ||
| | ||
LL | type A = <<S as Tr>::A as Example>::f; | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ^ there is a similarly named associated type `A` in the trait `Tr` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0223`. | ||
For more information about this error, try `rustc --explain E0220`. |
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