-
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.
Auto merge of #62221 - jonas-schievink:normalize-impl-trait, r=nikoma…
…tsakis Normalize projections appearing in `impl Trait` Fixes #60414 This does not try to do the same for `existential type`s (which have the same bug), since that always seems to lead to cycle errors.
- Loading branch information
Showing
7 changed files
with
220 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
// See issue 60414 | ||
|
||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
async fn foo<T: Trait<Assoc=()>>() -> T::Assoc { | ||
() | ||
} | ||
|
||
fn main() {} |
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,53 @@ | ||
// compile-fail | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
#![feature(existential_type)] | ||
#![feature(impl_trait_in_bindings)] | ||
//~^ WARNING the feature `impl_trait_in_bindings` is incomplete | ||
|
||
// See issue 60414 | ||
|
||
///////////////////////////////////////////// | ||
// Reduction to `impl Trait` | ||
|
||
struct Foo<T>(T); | ||
|
||
trait FooLike { type Output; } | ||
|
||
impl<T> FooLike for Foo<T> { | ||
type Output = T; | ||
} | ||
|
||
mod impl_trait { | ||
use super::*; | ||
|
||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
/// `T::Assoc` can't be normalized any further here. | ||
fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> { | ||
//~^ ERROR: type mismatch | ||
Foo(()) | ||
} | ||
} | ||
|
||
///////////////////////////////////////////// | ||
// Same with lifetimes in the trait | ||
|
||
mod lifetimes { | ||
use super::*; | ||
|
||
trait Trait<'a> { | ||
type Assoc; | ||
} | ||
|
||
/// Missing bound constraining `Assoc`, `T::Assoc` can't be normalized further. | ||
fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> { | ||
//~^ ERROR: type mismatch | ||
Foo(()) | ||
} | ||
} | ||
|
||
fn main() {} |
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,29 @@ | ||
warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash | ||
--> $DIR/bound-normalization-fail.rs:6:12 | ||
| | ||
LL | #![feature(impl_trait_in_bindings)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc` | ||
--> $DIR/bound-normalization-fail.rs:30:32 | ||
| | ||
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type | ||
| | ||
= note: expected type `()` | ||
found type `<T as impl_trait::Trait>::Assoc` | ||
= note: the return type of a function must have a statically known size | ||
|
||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc` | ||
--> $DIR/bound-normalization-fail.rs:47:41 | ||
| | ||
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type | ||
| | ||
= note: expected type `()` | ||
found type `<T as lifetimes::Trait<'static>>::Assoc` | ||
= note: the return type of a function must have a statically known size | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
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,109 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
#![feature(existential_type)] | ||
#![feature(impl_trait_in_bindings)] | ||
//~^ WARNING the feature `impl_trait_in_bindings` is incomplete | ||
|
||
// See issue 60414 | ||
|
||
///////////////////////////////////////////// | ||
// Reduction to `impl Trait` | ||
|
||
struct Foo<T>(T); | ||
|
||
trait FooLike { type Output; } | ||
|
||
impl<T> FooLike for Foo<T> { | ||
type Output = T; | ||
} | ||
|
||
mod impl_trait { | ||
use super::*; | ||
|
||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
/// `T::Assoc` should be normalized to `()` here. | ||
fn foo_pass<T: Trait<Assoc=()>>() -> impl FooLike<Output=T::Assoc> { | ||
Foo(()) | ||
} | ||
} | ||
|
||
///////////////////////////////////////////// | ||
// Same with lifetimes in the trait | ||
|
||
mod lifetimes { | ||
use super::*; | ||
|
||
trait Trait<'a> { | ||
type Assoc; | ||
} | ||
|
||
/// Like above. | ||
/// | ||
/// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here | ||
fn foo2_pass<'a, T: Trait<'a, Assoc=()> + 'a>( | ||
) -> impl FooLike<Output=<T as Trait<'a>>::Assoc> + 'a { | ||
Foo(()) | ||
} | ||
|
||
/// Normalization to type containing bound region. | ||
/// | ||
/// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here | ||
fn foo2_pass2<'a, T: Trait<'a, Assoc=&'a ()> + 'a>( | ||
) -> impl FooLike<Output=<T as Trait<'a>>::Assoc> + 'a { | ||
Foo(&()) | ||
} | ||
} | ||
|
||
///////////////////////////////////////////// | ||
// Reduction using `impl Trait` in bindings | ||
|
||
mod impl_trait_in_bindings { | ||
struct Foo; | ||
|
||
trait FooLike { type Output; } | ||
|
||
impl FooLike for Foo { | ||
type Output = u32; | ||
} | ||
|
||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
fn foo<T: Trait<Assoc=u32>>() { | ||
let _: impl FooLike<Output=T::Assoc> = Foo; | ||
} | ||
} | ||
|
||
///////////////////////////////////////////// | ||
// The same applied to `existential type`s | ||
|
||
mod existential_types { | ||
trait Implemented { | ||
type Assoc; | ||
} | ||
impl<T> Implemented for T { | ||
type Assoc = u8; | ||
} | ||
|
||
trait Trait { | ||
type Out; | ||
} | ||
|
||
impl Trait for () { | ||
type Out = u8; | ||
} | ||
|
||
existential type Ex: Trait<Out = <() as Implemented>::Assoc>; | ||
|
||
fn define() -> Ex { | ||
() | ||
} | ||
} | ||
|
||
fn main() {} |
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,6 @@ | ||
warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash | ||
--> $DIR/bound-normalization-pass.rs:6:12 | ||
| | ||
LL | #![feature(impl_trait_in_bindings)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|