Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two
### user visible change 1: RPIT inference from recursive call sites
Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.
```rust
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return 42
}
let x: u32 = bar(false); // this errors on stable
99
}
```
The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.
### user visible change 2: divergence between RPIT and TAIT in return statements
Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So
```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
return vec![42];
}
std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return vec![42]
}
std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```
But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:
```rust
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
return vec![];
}
let mut x = foo(false);
x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
vec![]
}
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return vec![];
}
let mut x = bar(false);
x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
vec![]
}
```
### user visible change 3: TAIT does not merge types across branches
In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.
```rust
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
vec![42_i32]
} else {
std::iter::empty().collect()
//~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
}
}
```
It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).
### PR formalities
previous attempt: #92007
This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893
fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895
This commit is contained in:
commit
f132bcf3bd
419 changed files with 5208 additions and 2490 deletions
|
|
@ -305,7 +305,7 @@ pub fn return_impl_trait() -> i32 {
|
|||
}
|
||||
|
||||
#[cfg(not(any(cfail1,cfail4)))]
|
||||
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig")]
|
||||
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
|
||||
#[rustc_clean(cfg = "cfail3")]
|
||||
#[rustc_clean(cfg = "cfail5", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
|
||||
#[rustc_clean(cfg = "cfail6")]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl Thing for AssocNoCopy {
|
|||
type Out = Box<dyn Bar<Assoc: Copy>>;
|
||||
|
||||
fn func() -> Self::Out {
|
||||
//~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
Box::new(AssocNoCopy)
|
||||
//~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:32:18
|
||||
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:33:9
|
||||
|
|
||||
LL | fn func() -> Self::Out {
|
||||
| ^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
LL | Box::new(AssocNoCopy)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
= note: required for the cast to the object type `dyn Bar<Assoc = <AssocNoCopy as Thing>::Out::{opaque#0}>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ fn bar() -> impl Bar {
|
|||
}
|
||||
|
||||
fn baz() -> impl Bar<Item = i32> {
|
||||
//~^ ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
|
||||
//~^ ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
|
||||
//~| ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
|
||||
bar()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,18 +2,43 @@ error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32`
|
|||
--> $DIR/impl-trait-return-missing-constraint.rs:25:13
|
||||
|
|
||||
LL | fn bar() -> impl Bar {
|
||||
| -------- the found opaque type
|
||||
| -------- the expected opaque type
|
||||
...
|
||||
LL | fn baz() -> impl Bar<Item = i32> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found associated type
|
||||
| ^^^^^^^^^^^^^^^^^^^^ expected associated type, found `i32`
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found associated type `<impl Bar as Foo>::Item`
|
||||
= note: expected associated type `<impl Bar as Foo>::Item`
|
||||
found type `i32`
|
||||
= help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` or calling a method that returns `<impl Bar as Foo>::Item`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32`
|
||||
|
|
||||
LL | fn bar() -> impl Bar<Item = i32> {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32`
|
||||
--> $DIR/impl-trait-return-missing-constraint.rs:25:34
|
||||
|
|
||||
LL | fn bar() -> impl Bar {
|
||||
| -------- the expected opaque type
|
||||
...
|
||||
LL | fn baz() -> impl Bar<Item = i32> {
|
||||
| __________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | bar()
|
||||
LL | | }
|
||||
| |_^ expected associated type, found `i32`
|
||||
|
|
||||
= note: expected associated type `<impl Bar as Foo>::Item`
|
||||
found type `i32`
|
||||
= help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` or calling a method that returns `<impl Bar as Foo>::Item`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32`
|
||||
|
|
||||
LL | fn bar() -> impl Bar<Item = i32> {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ LL | Box::new(async { x } )
|
|||
| may outlive borrowed value `x`
|
||||
|
|
||||
note: async block is returned here
|
||||
--> $DIR/async-borrowck-escaping-block-error.rs:4:20
|
||||
--> $DIR/async-borrowck-escaping-block-error.rs:6:5
|
||||
|
|
||||
LL | fn test_boxed() -> Box<impl std::future::Future<Output = u32>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | Box::new(async { x } )
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword
|
||||
|
|
||||
LL | Box::new(async move { x } )
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::future::Future;
|
||||
fn foo<T: Send, U>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
|
||||
//~^ Error future cannot be sent between threads safely
|
||||
//~^ Error future cannot be sent between threads safely
|
||||
async { (ty, ty1) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,16 @@ LL | | }
|
|||
= help: consider adding the following bound: `'a: 'b`
|
||||
|
||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
||||
--> $DIR/ret-impl-trait-one.rs:16:80
|
||||
|
|
||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||
| -- ^^^^^^^^^^^^^^
|
||||
| |
|
||||
| hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||
| ____________________________________--__________________________________________^
|
||||
| | |
|
||||
| | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||
LL | |
|
||||
LL | | (a, b)
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||
|
|
||||
|
|
|
|||
|
|
@ -1,19 +1,26 @@
|
|||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/ret-impl-trait-one.rs:10:65
|
||||
--> $DIR/ret-impl-trait-one.rs:10:85
|
||||
|
|
||||
LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
|
||||
| ------ ^^^^^^^^^^^^^^^^^^^
|
||||
| | |
|
||||
| | ...but data from `a` is returned here
|
||||
| this parameter and the return type are declared with different lifetimes...
|
||||
LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
|
||||
| ______________________________________________________------_____-------------------_^
|
||||
| | |
|
||||
| | this parameter and the return type are declared with different lifetimes...
|
||||
LL | |
|
||||
LL | | (a, b)
|
||||
LL | | }
|
||||
| |_^ ...but data from `a` is returned here
|
||||
|
||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/ret-impl-trait-one.rs:16:65
|
||||
--> $DIR/ret-impl-trait-one.rs:16:80
|
||||
|
|
||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||
| -- ^^^^^^^^^^^^^^
|
||||
| |
|
||||
| hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
|
||||
| ____________________________________--__________________________________________^
|
||||
| | |
|
||||
| | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
|
||||
LL | |
|
||||
LL | | (a, b)
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||
|
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@
|
|||
|
||||
pub const async fn x() {}
|
||||
//~^ ERROR functions cannot be both `const` and `async`
|
||||
//~| ERROR cycle detected
|
||||
|
|
|
|||
|
|
@ -7,5 +7,36 @@ LL | pub const async fn x() {}
|
|||
| | `async` because of this
|
||||
| `const` because of this
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0391]: cycle detected when computing type of `x::{opaque#0}`
|
||||
--> $DIR/no-const-async.rs:4:24
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^
|
||||
|
|
||||
note: ...which requires borrow-checking `x`...
|
||||
--> $DIR/no-const-async.rs:4:1
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing `x`...
|
||||
--> $DIR/no-const-async.rs:4:1
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires const checking `x`...
|
||||
--> $DIR/no-const-async.rs:4:1
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which requires computing whether `impl core::future::future::Future<Output = ()>` is freeze...
|
||||
= note: ...which requires evaluating trait selection obligation `impl core::future::future::Future<Output = ()>: core::marker::Freeze`...
|
||||
= note: ...which again requires computing type of `x::{opaque#0}`, completing the cycle
|
||||
note: cycle used when checking item types in top-level module
|
||||
--> $DIR/no-const-async.rs:4:1
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0391`.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
// Test that impl trait does not allow creating recursive types that are
|
||||
// otherwise forbidden when using `async` and `await`.
|
||||
|
||||
async fn recursive_async_function() -> () { //~ ERROR
|
||||
async fn recursive_async_function() -> () {
|
||||
//~^ ERROR recursion in an `async fn` requires boxing
|
||||
recursive_async_function().await;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ async fn dummy() {}
|
|||
async fn suggest_await_in_async_fn_return() {
|
||||
dummy()
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP consider using a semicolon here
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| HELP consider using a semicolon here
|
||||
//~| SUGGESTION .await
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,13 @@ LL | T: Generator<ResumeTy, Yield = ()>,
|
|||
| ^^^^^^^^^^ required by this bound in `from_generator`
|
||||
|
||||
error[E0280]: the requirement `<impl Future as Future>::Output == u32` is not satisfied
|
||||
--> $DIR/async.rs:7:25
|
||||
--> $DIR/async.rs:7:29
|
||||
|
|
||||
LL | async fn foo(x: u32) -> u32 {
|
||||
| ^^^
|
||||
LL | async fn foo(x: u32) -> u32 {
|
||||
| _____________________________^
|
||||
LL | | x
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ LL | println!("{:?}", p);
|
|||
| - `p` is borrowed here
|
||||
|
|
||||
note: closure is returned here
|
||||
--> $DIR/borrowck-4.rs:8:14
|
||||
--> $DIR/borrowck-4.rs:15:5
|
||||
|
|
||||
LL | fn foo () -> impl FnMut()->() {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
LL | c
|
||||
| ^
|
||||
help: to force the closure to take ownership of `p` (and any other referenced variables), use the `move` keyword
|
||||
|
|
||||
LL | let mut c = move || {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
|
||||
//~^ ERROR `()` is not an iterator
|
||||
//~| ERROR `()` is not an iterator
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,18 @@ LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
|
|||
|
|
||||
= help: the trait `Iterator` is not implemented for `()`
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0277]: `()` is not an iterator
|
||||
--> $DIR/conservative_impl_trait.rs:3:60
|
||||
|
|
||||
LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
|
||||
| ____________________________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^ `()` is not an iterator
|
||||
|
|
||||
= help: the trait `Iterator` is not implemented for `()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ impl<const N: u32> Trait for Uwu<N> {}
|
|||
|
||||
fn rawr() -> impl Trait {
|
||||
//~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
|
||||
//~| error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
|
||||
Uwu::<10, 12>
|
||||
}
|
||||
|
||||
|
|
@ -16,11 +17,13 @@ impl Traitor<1, 2> for u64 {}
|
|||
|
||||
fn uwu<const N: u8>() -> impl Traitor<N> {
|
||||
//~^ error: the trait bound `u32: Traitor<N, N>` is not satisfied
|
||||
//~| error: the trait bound `u32: Traitor<N, N>` is not satisfied
|
||||
1_u32
|
||||
}
|
||||
|
||||
fn owo() -> impl Traitor {
|
||||
//~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
|
||||
//~| error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
|
||||
1_u64
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,22 @@ LL | fn rawr() -> impl Trait {
|
|||
= help: the following implementations were found:
|
||||
<Uwu<N> as Trait>
|
||||
|
||||
error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
|
||||
--> $DIR/rp_impl_trait_fail.rs:6:25
|
||||
|
|
||||
LL | fn rawr() -> impl Trait {
|
||||
| _________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Uwu::<10, 12>
|
||||
LL | | }
|
||||
| |_^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<Uwu<N> as Trait>
|
||||
|
||||
error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
|
||||
--> $DIR/rp_impl_trait_fail.rs:17:26
|
||||
--> $DIR/rp_impl_trait_fail.rs:18:26
|
||||
|
|
||||
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
|
||||
| ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32`
|
||||
|
|
@ -17,8 +31,23 @@ LL | fn uwu<const N: u8>() -> impl Traitor<N> {
|
|||
<u32 as Traitor<N, 2_u8>>
|
||||
<u64 as Traitor<1_u8, 2_u8>>
|
||||
|
||||
error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
|
||||
--> $DIR/rp_impl_trait_fail.rs:18:42
|
||||
|
|
||||
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
|
||||
| __________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | 1_u32
|
||||
LL | | }
|
||||
| |_^ the trait `Traitor<N, N>` is not implemented for `u32`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<u32 as Traitor<N, 2_u8>>
|
||||
<u64 as Traitor<1_u8, 2_u8>>
|
||||
|
||||
error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
|
||||
--> $DIR/rp_impl_trait_fail.rs:22:13
|
||||
--> $DIR/rp_impl_trait_fail.rs:24:13
|
||||
|
|
||||
LL | fn owo() -> impl Traitor {
|
||||
| ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
|
||||
|
|
@ -27,6 +56,21 @@ LL | fn owo() -> impl Traitor {
|
|||
<u64 as Traitor<1_u8, 2_u8>>
|
||||
<u32 as Traitor<N, 2_u8>>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
|
||||
--> $DIR/rp_impl_trait_fail.rs:24:26
|
||||
|
|
||||
LL | fn owo() -> impl Traitor {
|
||||
| __________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | 1_u64
|
||||
LL | | }
|
||||
| |_^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<u64 as Traitor<1_u8, 2_u8>>
|
||||
<u32 as Traitor<N, 2_u8>>
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -3,11 +3,9 @@
|
|||
#![allow(incomplete_features)]
|
||||
pub mod foo {
|
||||
type MainFn = impl Fn();
|
||||
//~^ ERROR could not find defining uses
|
||||
|
||||
fn bar() {}
|
||||
pub const BAR: MainFn = bar;
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
use foo::BAR as main; //~ ERROR `main` function not found in crate
|
||||
|
|
|
|||
|
|
@ -1,30 +1,11 @@
|
|||
error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden`
|
||||
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:13:22
|
||||
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:11:22
|
||||
|
|
||||
LL | use foo::BAR as main;
|
||||
| ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs`
|
||||
| |
|
||||
| non-function item at `crate::main` is found
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:9:29
|
||||
|
|
||||
LL | type MainFn = impl Fn();
|
||||
| --------- the expected opaque type
|
||||
...
|
||||
LL | pub const BAR: MainFn = bar;
|
||||
| ^^^ expected opaque type, found fn item
|
||||
|
|
||||
= note: expected opaque type `impl Fn()`
|
||||
found fn item `fn() {bar}`
|
||||
error: aborting due to previous error
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:5:19
|
||||
|
|
||||
LL | type MainFn = impl Fn();
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0601.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
For more information about this error, try `rustc --explain E0601`.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
// ignore-compare-mode-chalk
|
||||
// check-pass
|
||||
#![feature(type_alias_impl_trait)]
|
||||
use std::fmt::Debug;
|
||||
|
||||
type Foo = impl Debug;
|
||||
//~^ ERROR could not find defining uses
|
||||
|
||||
struct Bar(Foo);
|
||||
fn define() -> Bar {
|
||||
Bar(42) //~ ERROR mismatched types
|
||||
Bar(42)
|
||||
}
|
||||
|
||||
type Foo2 = impl Debug;
|
||||
|
|
@ -17,21 +17,18 @@ fn define2() {
|
|||
}
|
||||
|
||||
type Foo3 = impl Debug;
|
||||
//~^ ERROR could not find defining uses
|
||||
|
||||
fn define3(x: Foo3) {
|
||||
let y: i32 = x; //~ ERROR mismatched types
|
||||
let y: i32 = x;
|
||||
}
|
||||
fn define3_1() {
|
||||
define3(42) //~ ERROR mismatched types
|
||||
define3(42)
|
||||
}
|
||||
|
||||
type Foo4 = impl Debug;
|
||||
//~^ ERROR could not find defining uses
|
||||
|
||||
fn define4() {
|
||||
let y: Foo4 = 42;
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:10:9
|
||||
|
|
||||
LL | type Foo = impl Debug;
|
||||
| ---------- the expected opaque type
|
||||
...
|
||||
LL | Bar(42)
|
||||
| ^^ expected opaque type, found integer
|
||||
|
|
||||
= note: expected opaque type `impl Debug`
|
||||
found type `{integer}`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:23:18
|
||||
|
|
||||
LL | type Foo3 = impl Debug;
|
||||
| ---------- the found opaque type
|
||||
...
|
||||
LL | let y: i32 = x;
|
||||
| --- ^ expected `i32`, found opaque type
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found opaque type `impl Debug`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:26:13
|
||||
|
|
||||
LL | type Foo3 = impl Debug;
|
||||
| ---------- the expected opaque type
|
||||
...
|
||||
LL | define3(42)
|
||||
| ^^ expected opaque type, found integer
|
||||
|
|
||||
= note: expected opaque type `impl Debug`
|
||||
found type `{integer}`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:33:19
|
||||
|
|
||||
LL | type Foo4 = impl Debug;
|
||||
| ---------- the expected opaque type
|
||||
...
|
||||
LL | let y: Foo4 = 42;
|
||||
| ---- ^^ expected opaque type, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected opaque type `impl Debug`
|
||||
found type `{integer}`
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:5:12
|
||||
|
|
||||
LL | type Foo = impl Debug;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:19:13
|
||||
|
|
||||
LL | type Foo3 = impl Debug;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:29:13
|
||||
|
|
||||
LL | type Foo4 = impl Debug;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
@ -6,10 +6,14 @@
|
|||
use std::ops::Generator;
|
||||
|
||||
fn foo(bar: bool) -> impl Generator<(bool,)> {
|
||||
//~^ ERROR: type mismatch in generator arguments [E0631]
|
||||
//~| NOTE: expected signature of `fn((bool,)) -> _`
|
||||
//~^ ERROR: type mismatch in generator arguments [E0631]
|
||||
//~| ERROR: type mismatch in generator arguments [E0631]
|
||||
//~| NOTE: expected signature of `fn((bool,)) -> _`
|
||||
//~| NOTE: expected signature of `fn((bool,)) -> _`
|
||||
//~| NOTE: in this expansion of desugaring of `impl Trait`
|
||||
|bar| {
|
||||
//~^ NOTE: found signature of `fn(bool) -> _`
|
||||
//~^ NOTE: found signature of `fn(bool) -> _`
|
||||
//~| NOTE: found signature of `fn(bool) -> _`
|
||||
if bar {
|
||||
yield bar;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,22 @@ LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
|
|||
LL | |bar| {
|
||||
| ----- found signature of `fn(bool) -> _`
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0631]: type mismatch in generator arguments
|
||||
--> $DIR/issue-88653.rs:8:46
|
||||
|
|
||||
LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
|
||||
| ______________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | |bar| {
|
||||
| | ----- found signature of `fn(bool) -> _`
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^ expected signature of `fn((bool,)) -> _`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0631`.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
use std::ops::Generator;
|
||||
|
||||
fn foo() -> impl Generator<Return = i32> { //~ ERROR type mismatch
|
||||
fn foo() -> impl Generator<Return = i32> {
|
||||
//~^ ERROR type mismatch
|
||||
//~| ERROR type mismatch
|
||||
|| {
|
||||
if false {
|
||||
return Ok(6);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:13:9
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:15:9
|
||||
|
|
||||
LL | 5
|
||||
| ^ expected enum `Result`, found integer
|
||||
|
|
@ -7,21 +7,37 @@ LL | 5
|
|||
= note: expected type `Result<{integer}, _>`
|
||||
found type `{integer}`
|
||||
note: return type inferred to be `Result<{integer}, _>` here
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:8:20
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:10:20
|
||||
|
|
||||
LL | return Ok(6);
|
||||
| ^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:6:5: 14:6] as Generator>::Return == i32`
|
||||
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:8:5: 16:6] as Generator>::Return == i32`
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:5:13
|
||||
|
|
||||
LL | fn foo() -> impl Generator<Return = i32> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found enum `Result`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Result`, found `i32`
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found enum `Result<{integer}, _>`
|
||||
= note: expected enum `Result<{integer}, _>`
|
||||
found type `i32`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:8:5: 16:6] as Generator>::Return == i32`
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:5:42
|
||||
|
|
||||
LL | fn foo() -> impl Generator<Return = i32> {
|
||||
| __________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | || {
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^ expected enum `Result`, found `i32`
|
||||
|
|
||||
= note: expected enum `Result<{integer}, _>`
|
||||
found type `i32`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0271, E0308.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0477]: the type `impl Stream<Item = i32>` does not fulfill the required lifetime
|
||||
error[E0477]: the type `<() as Yay<&'a ()>>::InnerStream<'s>` does not fulfill the required lifetime
|
||||
--> $DIR/issue-86218.rs:23:28
|
||||
|
|
||||
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
|
||||
|
|
@ -10,6 +10,14 @@ note: type must outlive the lifetime `'s` as defined here as required by this bi
|
|||
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
|
||||
| ^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: unconstrained opaque type
|
||||
--> $DIR/issue-86218.rs:23:28
|
||||
|
|
||||
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `InnerStream` must be used in combination with a concrete type within the same module
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0477`.
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == impl Stream<Item = Repr>`
|
||||
--> $DIR/issue-89008.rs:39:43
|
||||
error[E0271]: type mismatch resolving `<Empty<_> as Stream>::Item == Repr`
|
||||
--> $DIR/issue-89008.rs:40:9
|
||||
|
|
||||
LL | type LineStream<'a, Repr> = impl Stream<Item = Repr>;
|
||||
| ------------------------ the expected opaque type
|
||||
...
|
||||
LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found struct `Empty`
|
||||
| ---- this type parameter
|
||||
LL | async {empty()}
|
||||
| ^^^^^^^^^^^^^^^ type mismatch resolving `<Empty<_> as Stream>::Item == Repr`
|
||||
|
|
||||
= note: expected opaque type `impl Stream<Item = Repr>`
|
||||
found struct `Empty<_>`
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/issue-89008.rs:35:33
|
||||
note: expected this to be `()`
|
||||
--> $DIR/issue-89008.rs:18:17
|
||||
|
|
||||
LL | type LineStream<'a, Repr> = impl Stream<Item = Repr>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | type Item = ();
|
||||
| ^^
|
||||
= note: expected unit type `()`
|
||||
found type parameter `Repr`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ pub trait Trait2 {
|
|||
|
||||
impl<'c, S: Trait2> Trait2 for &'c mut S {
|
||||
type FooFuture<'a> = impl Trait1;
|
||||
fn foo<'a>() -> Self::FooFuture<'a> { //~ ERROR
|
||||
//~^ ERROR unconstrained opaque type
|
||||
fn foo<'a>() -> Self::FooFuture<'a> {
|
||||
Struct(unimplemented!())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/issue-87258_a.rs:19:21
|
||||
error: unconstrained opaque type
|
||||
--> $DIR/issue-87258_a.rs:18:26
|
||||
|
|
||||
LL | fn foo<'a>() -> Self::FooFuture<'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | type FooFuture<'a> = impl Trait1;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: hidden type `Struct<'_>` captures lifetime '_#7r
|
||||
= note: `FooFuture` must be used in combination with a concrete type within the same module
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0700`.
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ pub trait Trait2 {
|
|||
}
|
||||
|
||||
type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1;
|
||||
//~^ ERROR unconstrained opaque type
|
||||
|
||||
impl<'c, S: Trait2> Trait2 for &'c mut S {
|
||||
type FooFuture<'a> = Helper<'c, 'a, S>;
|
||||
fn foo<'a>() -> Self::FooFuture<'a> { //~ ERROR
|
||||
fn foo<'a>() -> Self::FooFuture<'a> {
|
||||
Struct(unimplemented!())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/issue-87258_b.rs:21:21
|
||||
error: unconstrained opaque type
|
||||
--> $DIR/issue-87258_b.rs:17:49
|
||||
|
|
||||
LL | fn foo<'a>() -> Self::FooFuture<'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: hidden type `Struct<'_>` captures lifetime '_#7r
|
||||
= note: `Helper` must be used in combination with a concrete type within the same module
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0700`.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ struct C;
|
|||
|
||||
impl<'a> A<'a> for C {
|
||||
type B<'b> = impl Clone;
|
||||
//~^ ERROR: could not find defining uses
|
||||
|
||||
fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/issue-88595.rs:22:23
|
||||
--> $DIR/issue-88595.rs:21:35
|
||||
|
|
||||
LL | fn a(&'a self) -> Self::B<'a> {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^
|
||||
|
|
||||
note: lifetime used multiple times
|
||||
--> $DIR/issue-88595.rs:18:6
|
||||
|
|
@ -12,11 +12,5 @@ LL | impl<'a> A<'a> for C {
|
|||
LL | type B<'b> = impl Clone;
|
||||
| ^^
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/issue-88595.rs:19:18
|
||||
|
|
||||
LL | type B<'b> = impl Clone;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
28
src/test/ui/impl-trait/async_scope_creep.rs
Normal file
28
src/test/ui/impl-trait/async_scope_creep.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
// edition:2021
|
||||
// check-pass
|
||||
|
||||
struct Pending {}
|
||||
|
||||
struct CantOpen {}
|
||||
|
||||
trait AsyncRead {}
|
||||
|
||||
impl AsyncRead for i32 {}
|
||||
|
||||
type PendingReader<'a> = impl AsyncRead + 'a;
|
||||
|
||||
type OpeningReadFuture<'a> =
|
||||
impl std::future::Future<Output = Result<PendingReader<'a>, CantOpen>>;
|
||||
|
||||
impl Pending {
|
||||
async fn read(&mut self) -> Result<impl AsyncRead + '_, CantOpen> {
|
||||
Ok(42)
|
||||
}
|
||||
|
||||
fn read_fut(&mut self) -> OpeningReadFuture<'_> {
|
||||
self.read()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -11,6 +11,7 @@ fn main() {
|
|||
// return type, which can't depend on the obligation.
|
||||
fn cycle1() -> impl Clone {
|
||||
//~^ ERROR cycle detected
|
||||
//~| ERROR cycle detected
|
||||
send(cycle2().clone());
|
||||
|
||||
Rc::new(Cell::new(5))
|
||||
|
|
|
|||
|
|
@ -30,47 +30,45 @@ note: ...which requires building MIR for `cycle1`...
|
|||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires type-checking `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:14:5
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | send(cycle2().clone());
|
||||
| ^^^^
|
||||
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires computing type of `cycle2::{opaque#0}`...
|
||||
--> $DIR/auto-trait-leak.rs:19:16
|
||||
--> $DIR/auto-trait-leak.rs:20:16
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^
|
||||
note: ...which requires borrow-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:19:1
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:19:1
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing MIR for `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:19:1
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires unsafety-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:19:1
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires building MIR for `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:19:1
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires type-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:5
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | send(cycle1().clone());
|
||||
| ^^^^
|
||||
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle
|
||||
note: cycle used when checking item types in top-level module
|
||||
--> $DIR/auto-trait-leak.rs:1:1
|
||||
|
|
@ -84,6 +82,90 @@ LL | | Rc::new(String::from("foo"))
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0391]: cycle detected when computing type of `cycle1::{opaque#0}`
|
||||
--> $DIR/auto-trait-leak.rs:12:16
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires borrow-checking `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing MIR for `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires unsafety-checking `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires building MIR for `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires type-checking `cycle1`...
|
||||
--> $DIR/auto-trait-leak.rs:12:1
|
||||
|
|
||||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires computing type of `cycle2::{opaque#0}`...
|
||||
--> $DIR/auto-trait-leak.rs:20:16
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^
|
||||
note: ...which requires borrow-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires processing MIR for `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires unsafety-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires building MIR for `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires type-checking `cycle2`...
|
||||
--> $DIR/auto-trait-leak.rs:20:1
|
||||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle
|
||||
note: cycle used when checking item types in top-level module
|
||||
--> $DIR/auto-trait-leak.rs:1:1
|
||||
|
|
||||
LL | / use std::cell::Cell;
|
||||
LL | | use std::rc::Rc;
|
||||
LL | |
|
||||
LL | | fn send<T: Send>(_: T) {}
|
||||
... |
|
||||
LL | | Rc::new(String::from("foo"))
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0391`.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl<T: Send> AnotherTrait for T {}
|
|||
// (We treat opaque types as "foreign types" that could grow more impls
|
||||
// in the future.)
|
||||
impl AnotherTrait for D<OpaqueType> {
|
||||
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<impl OpaqueTrait>`
|
||||
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<impl OpaqueTrait>`
|
||||
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
|
||||
--> $DIR/auto-trait.rs:21:1
|
||||
|
|
||||
LL | impl<T: Send> AnotherTrait for T {}
|
||||
| -------------------------------- first implementation here
|
||||
...
|
||||
LL | impl AnotherTrait for D<OpaqueType> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<impl OpaqueTrait>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
19
src/test/ui/impl-trait/autoderef.rs
Normal file
19
src/test/ui/impl-trait/autoderef.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// check-pass
|
||||
|
||||
use std::path::Path;
|
||||
use std::ffi::OsStr;
|
||||
use std::ops::Deref;
|
||||
|
||||
fn frob(path: &str) -> impl Deref<Target = Path> + '_ {
|
||||
OsStr::new(path).as_ref()
|
||||
}
|
||||
|
||||
fn open_parent<'path>(_path: &'path Path) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let old_path = frob("hello");
|
||||
|
||||
open_parent(&old_path);
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ mod impl_trait {
|
|||
/// `T::Assoc` can't be normalized any further here.
|
||||
fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
|
||||
//~^ ERROR: type mismatch
|
||||
//~| ERROR: type mismatch
|
||||
Foo(())
|
||||
}
|
||||
}
|
||||
|
|
@ -39,8 +40,9 @@ mod lifetimes {
|
|||
|
||||
/// 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
|
||||
//~^^ ERROR `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
|
||||
//~^ ERROR `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
|
||||
//~| ERROR: type mismatch
|
||||
//~| ERROR: type mismatch
|
||||
Foo(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,43 +4,90 @@ error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as imp
|
|||
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
||||
|
|
||||
note: expected this to be `<T as impl_trait::Trait>::Assoc`
|
||||
note: expected this to be `()`
|
||||
--> $DIR/bound-normalization-fail.rs:14:19
|
||||
|
|
||||
LL | type Output = T;
|
||||
| ^
|
||||
= note: expected associated type `<T as impl_trait::Trait>::Assoc`
|
||||
found unit type `()`
|
||||
= note: expected unit type `()`
|
||||
found associated type `<T as impl_trait::Trait>::Assoc`
|
||||
help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc` to `()`
|
||||
|
|
||||
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ++++++++++++
|
||||
|
||||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
||||
--> $DIR/bound-normalization-fail.rs:25:64
|
||||
|
|
||||
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ________________________________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Foo(())
|
||||
LL | | }
|
||||
| |_____^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
||||
|
|
||||
note: expected this to be `()`
|
||||
--> $DIR/bound-normalization-fail.rs:14:19
|
||||
|
|
||||
LL | type Output = T;
|
||||
| ^
|
||||
= note: expected unit type `()`
|
||||
found associated type `<T as impl_trait::Trait>::Assoc`
|
||||
help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc` to `()`
|
||||
|
|
||||
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ++++++++++++
|
||||
|
||||
error[E0760]: `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
|
||||
--> $DIR/bound-normalization-fail.rs:41:41
|
||||
--> $DIR/bound-normalization-fail.rs:42:41
|
||||
|
|
||||
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
|
||||
--> $DIR/bound-normalization-fail.rs:41:41
|
||||
--> $DIR/bound-normalization-fail.rs:42:41
|
||||
|
|
||||
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
|
||||
|
|
||||
note: expected this to be `<T as lifetimes::Trait<'static>>::Assoc`
|
||||
note: expected this to be `()`
|
||||
--> $DIR/bound-normalization-fail.rs:14:19
|
||||
|
|
||||
LL | type Output = T;
|
||||
| ^
|
||||
= note: expected associated type `<T as lifetimes::Trait<'static>>::Assoc`
|
||||
found unit type `()`
|
||||
= note: expected unit type `()`
|
||||
found associated type `<T as lifetimes::Trait<'static>>::Assoc`
|
||||
help: consider constraining the associated type `<T as lifetimes::Trait<'static>>::Assoc` to `()`
|
||||
|
|
||||
LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
|
||||
--> $DIR/bound-normalization-fail.rs:42:73
|
||||
|
|
||||
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| _________________________________________________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Foo(())
|
||||
LL | | }
|
||||
| |_____^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
|
||||
|
|
||||
note: expected this to be `()`
|
||||
--> $DIR/bound-normalization-fail.rs:14:19
|
||||
|
|
||||
LL | type Output = T;
|
||||
| ^
|
||||
= note: expected unit type `()`
|
||||
found associated type `<T as lifetimes::Trait<'static>>::Assoc`
|
||||
help: consider constraining the associated type `<T as lifetimes::Trait<'static>>::Assoc` to `()`
|
||||
|
|
||||
LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0271, E0760.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
45
src/test/ui/impl-trait/cross-return-site-inference.rs
Normal file
45
src/test/ui/impl-trait/cross-return-site-inference.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// edition:2021
|
||||
|
||||
fn foo(b: bool) -> impl std::fmt::Debug {
|
||||
if b {
|
||||
return vec![42]
|
||||
}
|
||||
[].into_iter().collect()
|
||||
}
|
||||
|
||||
fn bar(b: bool) -> impl std::fmt::Debug {
|
||||
if b {
|
||||
return [].into_iter().collect()
|
||||
}
|
||||
vec![42]
|
||||
}
|
||||
|
||||
fn bak(b: bool) -> impl std::fmt::Debug {
|
||||
if b {
|
||||
return std::iter::empty().collect()
|
||||
}
|
||||
vec![42]
|
||||
}
|
||||
|
||||
fn baa(b: bool) -> impl std::fmt::Debug {
|
||||
if b {
|
||||
return [42].into_iter().collect()
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn muh() -> Result<(), impl std::fmt::Debug> {
|
||||
Err("whoops")?; //~ ERROR `?` couldn't convert the error to `impl Debug`
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn muh2() -> Result<(), impl std::fmt::Debug> {
|
||||
return Err(From::from("foo")); //~ ERROR the trait bound `impl Debug: From<&str>` is not satisfied
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn muh3() -> Result<(), impl std::fmt::Debug> {
|
||||
Err(From::from("foo")) //~ ERROR the trait bound `impl Debug: From<&str>` is not satisfied
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
26
src/test/ui/impl-trait/cross-return-site-inference.stderr
Normal file
26
src/test/ui/impl-trait/cross-return-site-inference.stderr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
error[E0277]: `?` couldn't convert the error to `impl Debug`
|
||||
--> $DIR/cross-return-site-inference.rs:32:18
|
||||
|
|
||||
LL | fn muh() -> Result<(), impl std::fmt::Debug> {
|
||||
| -------------------------------- expected `impl Debug` because of this
|
||||
LL | Err("whoops")?;
|
||||
| ^ the trait `From<&str>` is not implemented for `impl Debug`
|
||||
|
|
||||
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
|
||||
= note: required because of the requirements on the impl of `FromResidual<Result<Infallible, &str>>` for `Result<(), impl Debug>`
|
||||
|
||||
error[E0277]: the trait bound `impl Debug: From<&str>` is not satisfied
|
||||
--> $DIR/cross-return-site-inference.rs:37:16
|
||||
|
|
||||
LL | return Err(From::from("foo"));
|
||||
| ^^^^^^^^^^ the trait `From<&str>` is not implemented for `impl Debug`
|
||||
|
||||
error[E0277]: the trait bound `impl Debug: From<&str>` is not satisfied
|
||||
--> $DIR/cross-return-site-inference.rs:42:9
|
||||
|
|
||||
LL | Err(From::from("foo"))
|
||||
| ^^^^^^^^^^ the trait `From<&str>` is not implemented for `impl Debug`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
13
src/test/ui/impl-trait/divergence.rs
Normal file
13
src/test/ui/impl-trait/divergence.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// check-pass
|
||||
|
||||
fn foo() -> impl MyTrait {
|
||||
panic!();
|
||||
MyStruct
|
||||
}
|
||||
|
||||
struct MyStruct;
|
||||
trait MyTrait {}
|
||||
|
||||
impl MyTrait for MyStruct {}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -7,10 +7,10 @@ LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref
|
|||
| may outlive borrowed value `prefix`
|
||||
|
|
||||
note: closure is returned here
|
||||
--> $DIR/does-not-live-long-enough.rs:5:55
|
||||
--> $DIR/does-not-live-long-enough.rs:6:9
|
||||
|
|
||||
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: to force the closure to take ownership of `prefix` (and any other referenced variables), use the `move` keyword
|
||||
|
|
||||
LL | self.data.iter().filter(move |s| s.starts_with(prefix)).map(|s| s.as_ref())
|
||||
|
|
|
|||
|
|
@ -12,19 +12,10 @@ error[E0308]: mismatched types
|
|||
--> $DIR/equality.rs:15:5
|
||||
|
|
||||
LL | fn two(x: bool) -> impl Foo {
|
||||
| -------- expected because this return type...
|
||||
LL | if x {
|
||||
LL | return 1_i32;
|
||||
| ----- ...is found to be `i32` here
|
||||
LL | }
|
||||
| -------- expected `_` because of return type
|
||||
...
|
||||
LL | 0_u32
|
||||
| ^^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: to return `impl Trait`, all returned values must be of the same type
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= help: if the trait `Foo` were object safe, you could return a boxed trait object
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
= help: you could instead create a new `enum` with a variant for each returned type
|
||||
|
||||
error[E0277]: cannot add `impl Foo` to `u32`
|
||||
--> $DIR/equality.rs:24:11
|
||||
|
|
|
|||
9
src/test/ui/impl-trait/fallback.rs
Normal file
9
src/test/ui/impl-trait/fallback.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// check-pass
|
||||
|
||||
fn take_edge_counters(
|
||||
x: &mut Option<Vec<i32>>,
|
||||
) -> Option<impl Iterator<Item = i32>> {
|
||||
x.take().map_or(None, |m| Some(m.into_iter()))
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -26,8 +26,8 @@ impl<T> Swap for Rc<RefCell<T>> {
|
|||
// Here we are hiding `'b` making the caller believe that `&'a mut &'s T` and
|
||||
// `&'a mut &'l T` are the same type.
|
||||
fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
|
||||
//~^ ERROR hidden type
|
||||
x
|
||||
//~^ ERROR hidden type
|
||||
}
|
||||
|
||||
fn dangle_ref() -> &'static [i32; 3] {
|
||||
|
|
@ -43,8 +43,8 @@ fn dangle_ref() -> &'static [i32; 3] {
|
|||
// This is different to the previous example because the concrete return type
|
||||
// only has a single lifetime.
|
||||
fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
|
||||
//~^ ERROR hidden type
|
||||
x
|
||||
//~^ ERROR hidden type
|
||||
}
|
||||
|
||||
fn dangle_rc_refcell() -> &'static [i32; 3] {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-lifetimes.rs:28:54
|
||||
--> $DIR/hidden-lifetimes.rs:29:5
|
||||
|
|
||||
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
|
||||
| -- ^^^^^^^^^^^^^^
|
||||
| |
|
||||
| hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
|
||||
| -- hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
|
||||
LL | x
|
||||
| ^
|
||||
|
|
||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||
|
|
||||
|
|
@ -12,12 +12,12 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
|
|||
| ++++
|
||||
|
||||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-lifetimes.rs:45:70
|
||||
--> $DIR/hidden-lifetimes.rs:46:5
|
||||
|
|
||||
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
|
||||
| -- ^^^^^^^^^^^^^^
|
||||
| |
|
||||
| hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here
|
||||
| -- hidden type `Rc<RefCell<&'b T>>` captures the lifetime `'b` as defined here
|
||||
LL | x
|
||||
| ^
|
||||
|
|
||||
help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
|
||||
|
|
||||
|
|
|
|||
45
src/test/ui/impl-trait/hidden-type-is-opaque-2.rs
Normal file
45
src/test/ui/impl-trait/hidden-type-is-opaque-2.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// This doesn't work, because we don't flow information from opaque types
|
||||
// into function arguments via the function's generic parameters
|
||||
// FIXME(oli-obk): make `expected_inputs_for_expected_output` support this
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
fn reify_as() -> Thunk<impl FnOnce(Continuation) -> Continuation> {
|
||||
Thunk::new(|mut cont| { //~ ERROR type annotations needed
|
||||
cont.reify_as();
|
||||
cont
|
||||
})
|
||||
}
|
||||
|
||||
type Tait = impl FnOnce(Continuation) -> Continuation;
|
||||
|
||||
fn reify_as_tait() -> Thunk<Tait> {
|
||||
Thunk::new(|mut cont| { //~ ERROR type annotations needed
|
||||
cont.reify_as();
|
||||
cont
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
struct Thunk<F>(F);
|
||||
|
||||
impl<F> Thunk<F> {
|
||||
fn new(f: F) -> Self
|
||||
where
|
||||
F: ContFn,
|
||||
{
|
||||
Thunk(f)
|
||||
}
|
||||
}
|
||||
|
||||
trait ContFn {}
|
||||
|
||||
impl<F: FnOnce(Continuation) -> Continuation> ContFn for F {}
|
||||
|
||||
struct Continuation;
|
||||
|
||||
impl Continuation {
|
||||
fn reify_as(&mut self) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
19
src/test/ui/impl-trait/hidden-type-is-opaque-2.stderr
Normal file
19
src/test/ui/impl-trait/hidden-type-is-opaque-2.stderr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/hidden-type-is-opaque-2.rs:8:17
|
||||
|
|
||||
LL | Thunk::new(|mut cont| {
|
||||
| ^^^^^^^^ consider giving this closure parameter a type
|
||||
|
|
||||
= note: type must be known at this point
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/hidden-type-is-opaque-2.rs:17:17
|
||||
|
|
||||
LL | Thunk::new(|mut cont| {
|
||||
| ^^^^^^^^ consider giving this closure parameter a type
|
||||
|
|
||||
= note: type must be known at this point
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
42
src/test/ui/impl-trait/hidden-type-is-opaque.rs
Normal file
42
src/test/ui/impl-trait/hidden-type-is-opaque.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// check-pass
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
fn reify_as() -> Thunk<impl ContFn> {
|
||||
Thunk::new(|mut cont| {
|
||||
cont.reify_as();
|
||||
cont
|
||||
})
|
||||
}
|
||||
|
||||
type Tait = impl ContFn;
|
||||
|
||||
fn reify_as_tait() -> Thunk<Tait> {
|
||||
Thunk::new(|mut cont| {
|
||||
cont.reify_as();
|
||||
cont
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
struct Thunk<F>(F);
|
||||
|
||||
impl<F> Thunk<F> {
|
||||
fn new(f: F) -> Self
|
||||
where
|
||||
F: FnOnce(Continuation) -> Continuation,
|
||||
{
|
||||
Thunk(f)
|
||||
}
|
||||
}
|
||||
|
||||
trait ContFn {}
|
||||
|
||||
impl<F: FnOnce(Continuation) -> Continuation> ContFn for F {}
|
||||
|
||||
struct Continuation;
|
||||
|
||||
impl Continuation {
|
||||
fn reify_as(&mut self) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -10,11 +10,10 @@ impl<S: Default> Bar for S {
|
|||
type E = impl Copy;
|
||||
|
||||
fn foo<T: Default>() -> Self::E {
|
||||
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
//~| ERROR impl has stricter requirements than trait
|
||||
//~| ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
|
||||
//~| ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
|
||||
//~^ ERROR impl has stricter requirements than trait
|
||||
(S::default(), T::default())
|
||||
//~^ ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
|
||||
//~| ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ LL | fn foo<T: Default>() -> Self::E {
|
|||
| ^^^^^^^ impl has extra requirement `T: Default`
|
||||
|
||||
error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
|
||||
--> $DIR/issue-55872-1.rs:12:29
|
||||
--> $DIR/issue-55872-1.rs:14:9
|
||||
|
|
||||
LL | fn foo<T: Default>() -> Self::E {
|
||||
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
|
||||
LL | (S::default(), T::default())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
|
||||
|
|
||||
= note: required because it appears within the type `(S, T)`
|
||||
help: consider further restricting this bound
|
||||
|
|
@ -20,10 +20,10 @@ LL | impl<S: Default + std::marker::Copy> Bar for S {
|
|||
| +++++++++++++++++++
|
||||
|
||||
error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
|
||||
--> $DIR/issue-55872-1.rs:12:29
|
||||
--> $DIR/issue-55872-1.rs:14:9
|
||||
|
|
||||
LL | fn foo<T: Default>() -> Self::E {
|
||||
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
|
||||
LL | (S::default(), T::default())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
|
||||
|
|
||||
= note: required because it appears within the type `(S, T)`
|
||||
help: consider further restricting this bound
|
||||
|
|
@ -31,20 +31,7 @@ help: consider further restricting this bound
|
|||
LL | fn foo<T: Default + std::marker::Copy>() -> Self::E {
|
||||
| +++++++++++++++++++
|
||||
|
||||
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
--> $DIR/issue-55872-1.rs:12:37
|
||||
|
|
||||
LL | fn foo<T: Default>() -> Self::E {
|
||||
| _____________________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | (S::default(), T::default())
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0276, E0277.
|
||||
For more information about an error, try `rustc --explain E0276`.
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
pub trait Bar {
|
||||
type E: Copy;
|
||||
type E: Send;
|
||||
|
||||
fn foo<T>() -> Self::E;
|
||||
}
|
||||
|
||||
impl<S> Bar for S {
|
||||
type E = impl std::marker::Copy;
|
||||
type E = impl std::marker::Send;
|
||||
fn foo<T>() -> Self::E {
|
||||
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
//~| ERROR the trait bound `impl Future: Copy` is not satisfied
|
||||
async {}
|
||||
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,8 @@
|
|||
error[E0277]: the trait bound `impl Future: Copy` is not satisfied
|
||||
--> $DIR/issue-55872-2.rs:13:20
|
||||
|
|
||||
LL | fn foo<T>() -> Self::E {
|
||||
| ^^^^^^^ the trait `Copy` is not implemented for `impl Future`
|
||||
|
||||
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
--> $DIR/issue-55872-2.rs:13:28
|
||||
--> $DIR/issue-55872-2.rs:14:9
|
||||
|
|
||||
LL | fn foo<T>() -> Self::E {
|
||||
| ____________________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | async {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | async {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
20
src/test/ui/impl-trait/issue-55872-3.rs
Normal file
20
src/test/ui/impl-trait/issue-55872-3.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// edition:2018
|
||||
// ignore-compare-mode-chalk
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
pub trait Bar {
|
||||
type E: Copy;
|
||||
|
||||
fn foo<T>() -> Self::E;
|
||||
}
|
||||
|
||||
impl<S> Bar for S {
|
||||
type E = impl std::marker::Copy;
|
||||
fn foo<T>() -> Self::E {
|
||||
async {}
|
||||
//~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
9
src/test/ui/impl-trait/issue-55872-3.stderr
Normal file
9
src/test/ui/impl-trait/issue-55872-3.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0277]: the trait bound `impl Future: Copy` is not satisfied
|
||||
--> $DIR/issue-55872-3.rs:15:9
|
||||
|
|
||||
LL | async {}
|
||||
| ^^^^^^^^ the trait `Copy` is not implemented for `impl Future`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -10,8 +10,8 @@ impl<S> Bar for S {
|
|||
type E = impl Copy;
|
||||
|
||||
fn foo<T>() -> Self::E {
|
||||
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
|| ()
|
||||
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
|
||||
--> $DIR/issue-55872.rs:12:28
|
||||
--> $DIR/issue-55872.rs:13:9
|
||||
|
|
||||
LL | fn foo<T>() -> Self::E {
|
||||
| ____________________________^
|
||||
LL | |
|
||||
LL | | || ()
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | || ()
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub struct Lint {}
|
|||
impl Lint {}
|
||||
|
||||
pub fn gather_all() -> impl Iterator<Item = Lint> {
|
||||
//~^ ERROR: cannot resolve opaque type
|
||||
//~^ ERROR `()` is not an iterator
|
||||
lint_files().flat_map(|f| gather_from_file(&f))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,25 +10,15 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo`
|
|||
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
|
||||
| ^^^ use of undeclared crate or module `foo`
|
||||
|
||||
error[E0720]: cannot resolve opaque type
|
||||
error[E0277]: `()` is not an iterator
|
||||
--> $DIR/issue-72911.rs:7:24
|
||||
|
|
||||
LL | pub fn gather_all() -> impl Iterator<Item = Lint> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive opaque type
|
||||
LL |
|
||||
LL | lint_files().flat_map(|f| gather_from_file(&f))
|
||||
| -----------------------------------------------
|
||||
| |
|
||||
| returning here with type `FlatMap<impl Iterator<Item = [type error]>, [type error], [closure@$DIR/issue-72911.rs:9:27: 9:51]>`
|
||||
| returning here with type `FlatMap<impl Iterator<Item = [type error]>, [type error], [closure@$DIR/issue-72911.rs:9:27: 9:51]>`
|
||||
...
|
||||
LL | fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint> {
|
||||
| -------------------------- returning this opaque type `FlatMap<impl Iterator<Item = [type error]>, [type error], [closure@$DIR/issue-72911.rs:9:27: 9:51]>`
|
||||
...
|
||||
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
|
||||
| -------------------------------------- returning this opaque type `FlatMap<impl Iterator<Item = [type error]>, [type error], [closure@$DIR/issue-72911.rs:9:27: 9:51]>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
||||
|
|
||||
= help: the trait `Iterator` is not implemented for `()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0433, E0720.
|
||||
For more information about an error, try `rustc --explain E0433`.
|
||||
Some errors have detailed explanations: E0277, E0433.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
type X<'a, 'b> = impl std::fmt::Debug;
|
||||
|
||||
fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
|
||||
//~^ ERROR concrete type differs from previous defining opaque type use
|
||||
(a, a)
|
||||
//~^ ERROR concrete type differs from previous defining opaque type use
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
error: concrete type differs from previous defining opaque type use
|
||||
--> $DIR/issue-86465.rs:5:1
|
||||
--> $DIR/issue-86465.rs:6:5
|
||||
|
|
||||
LL | fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&'a u32`, got `&'b u32`
|
||||
|
|
||||
note: previous use here
|
||||
--> $DIR/issue-86465.rs:5:1
|
||||
|
|
||||
LL | fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | (a, a)
|
||||
| ^^^^^^
|
||||
| |
|
||||
| expected `&'a u32`, got `&'b u32`
|
||||
| this expression supplies two conflicting concrete types for the same opaque type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
23
src/test/ui/impl-trait/issues/issue-54895.rs
Normal file
23
src/test/ui/impl-trait/issues/issue-54895.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// check-pass
|
||||
|
||||
trait Trait<'a> {
|
||||
type Out;
|
||||
fn call(&'a self) -> Self::Out;
|
||||
}
|
||||
|
||||
struct X(());
|
||||
|
||||
impl<'a> Trait<'a> for X {
|
||||
type Out = ();
|
||||
fn call(&'a self) -> Self::Out {
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
||||
X(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = f();
|
||||
}
|
||||
32
src/test/ui/impl-trait/issues/issue-62742.rs
Normal file
32
src/test/ui/impl-trait/issues/issue-62742.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
fn _alias_check() {
|
||||
WrongImpl::foo(0i32);
|
||||
//~^ ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
|
||||
WrongImpl::<()>::foo(0i32);
|
||||
//~^ ERROR the trait bound `RawImpl<()>: Raw<()>` is not satisfied
|
||||
//~| ERROR trait bounds were not satisfied
|
||||
CorrectImpl::foo(0i32);
|
||||
}
|
||||
|
||||
pub trait Raw<T: ?Sized> {
|
||||
type Value;
|
||||
}
|
||||
|
||||
pub type WrongImpl<T> = SafeImpl<T, RawImpl<T>>;
|
||||
|
||||
pub type CorrectImpl<T> = SafeImpl<[T], RawImpl<T>>;
|
||||
|
||||
pub struct RawImpl<T>(PhantomData<T>);
|
||||
|
||||
impl<T> Raw<[T]> for RawImpl<T> {
|
||||
type Value = T;
|
||||
}
|
||||
|
||||
pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
|
||||
|
||||
impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
|
||||
pub fn foo(value: A::Value) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
54
src/test/ui/impl-trait/issues/issue-62742.stderr
Normal file
54
src/test/ui/impl-trait/issues/issue-62742.stderr
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
|
||||
--> $DIR/issue-62742.rs:4:5
|
||||
|
|
||||
LL | WrongImpl::foo(0i32);
|
||||
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<RawImpl<T> as Raw<[T]>>
|
||||
note: required by a bound in `SafeImpl`
|
||||
--> $DIR/issue-62742.rs:26:35
|
||||
|
|
||||
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
|
||||
| ^^^^^^ required by this bound in `SafeImpl`
|
||||
|
||||
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<(), RawImpl<()>>`, but its trait bounds were not satisfied
|
||||
--> $DIR/issue-62742.rs:6:22
|
||||
|
|
||||
LL | WrongImpl::<()>::foo(0i32);
|
||||
| ^^^ function or associated item cannot be called on `SafeImpl<(), RawImpl<()>>` due to unsatisfied trait bounds
|
||||
...
|
||||
LL | pub struct RawImpl<T>(PhantomData<T>);
|
||||
| -------------------------------------- doesn't satisfy `RawImpl<()>: Raw<()>`
|
||||
...
|
||||
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
|
||||
| --------------------------------------------------------------- function or associated item `foo` not found for this
|
||||
|
|
||||
= note: the following trait bounds were not satisfied:
|
||||
`RawImpl<()>: Raw<()>`
|
||||
note: the following trait must be implemented
|
||||
--> $DIR/issue-62742.rs:12:1
|
||||
|
|
||||
LL | / pub trait Raw<T: ?Sized> {
|
||||
LL | | type Value;
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied
|
||||
--> $DIR/issue-62742.rs:6:5
|
||||
|
|
||||
LL | WrongImpl::<()>::foo(0i32);
|
||||
| ^^^^^^^^^^^^^^^ the trait `Raw<()>` is not implemented for `RawImpl<()>`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<RawImpl<T> as Raw<[T]>>
|
||||
note: required by a bound in `SafeImpl`
|
||||
--> $DIR/issue-62742.rs:26:35
|
||||
|
|
||||
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
|
||||
| ^^^^^^ required by this bound in `SafeImpl`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0599.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
20
src/test/ui/impl-trait/issues/issue-67830.nll.stderr
Normal file
20
src/test/ui/impl-trait/issues/issue-67830.nll.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error: implementation of `FnOnce` is not general enough
|
||||
--> $DIR/issue-67830.rs:23:5
|
||||
|
|
||||
LL | Wrap(|a| Some(a).into_iter())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||
|
|
||||
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
|
||||
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
|
||||
|
||||
error: implementation of `FnOnce` is not general enough
|
||||
--> $DIR/issue-67830.rs:23:5
|
||||
|
|
||||
LL | Wrap(|a| Some(a).into_iter())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||
|
|
||||
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
|
||||
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
26
src/test/ui/impl-trait/issues/issue-67830.rs
Normal file
26
src/test/ui/impl-trait/issues/issue-67830.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
trait MyFn<Arg> {
|
||||
type Output;
|
||||
fn call(&self, arg: Arg) -> Self::Output;
|
||||
}
|
||||
|
||||
struct Wrap<F>(F);
|
||||
|
||||
impl<A, B, F> MyFn<A> for Wrap<F>
|
||||
where
|
||||
F: Fn(A) -> B
|
||||
{
|
||||
type Output = B;
|
||||
|
||||
fn call(&self, arg: A) -> Self::Output {
|
||||
(self.0)(arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct A;
|
||||
fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
||||
//~^ ERROR implementation of `FnOnce` is not general enough
|
||||
Wrap(|a| Some(a).into_iter())
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/impl-trait/issues/issue-67830.stderr
Normal file
15
src/test/ui/impl-trait/issues/issue-67830.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error: implementation of `FnOnce` is not general enough
|
||||
--> $DIR/issue-67830.rs:21:66
|
||||
|
|
||||
LL | fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
||||
| __________________________________________________________________^
|
||||
LL | |
|
||||
LL | | Wrap(|a| Some(a).into_iter())
|
||||
LL | | }
|
||||
| |_^ implementation of `FnOnce` is not general enough
|
||||
|
|
||||
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
|
||||
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -4,7 +4,7 @@ type FooArg<'a> = &'a dyn ToString;
|
|||
type FooRet = impl std::fmt::Debug;
|
||||
|
||||
type FooItem = Box<dyn Fn(FooArg) -> FooRet>;
|
||||
type Foo = impl Iterator<Item = FooItem>; //~ ERROR: type mismatch
|
||||
type Foo = impl Iterator<Item = FooItem>;
|
||||
|
||||
#[repr(C)]
|
||||
struct Bar(u8);
|
||||
|
|
@ -13,7 +13,7 @@ impl Iterator for Bar {
|
|||
type Item = FooItem;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
Some(Box::new(quux))
|
||||
Some(Box::new(quux)) //~ ERROR mismatched types
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ fn ham() -> Foo {
|
|||
fn oof() -> impl std::fmt::Debug {
|
||||
let mut bar = ham();
|
||||
let func = bar.next().unwrap();
|
||||
return func(&"oof");
|
||||
return func(&"oof"); //~ ERROR opaque type's hidden type cannot be another opaque type
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,34 @@
|
|||
error[E0271]: type mismatch resolving `<Bar as Iterator>::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
|
||||
--> $DIR/issue-70877.rs:7:12
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-70877.rs:16:9
|
||||
|
|
||||
LL | type FooRet = impl std::fmt::Debug;
|
||||
| -------------------- the found opaque type
|
||||
| -------------------- the expected opaque type
|
||||
...
|
||||
LL | type Foo = impl Iterator<Item = FooItem>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Bar as Iterator>::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
|
||||
LL | fn next(&mut self) -> Option<Self::Item> {
|
||||
| ------------------ expected `Option<Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>` because of return type
|
||||
LL | Some(Box::new(quux))
|
||||
| ^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found fn item
|
||||
|
|
||||
note: expected this to be `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
|
||||
--> $DIR/issue-70877.rs:13:17
|
||||
= note: expected enum `Option<Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>`
|
||||
found enum `Option<Box<for<'r> fn(&'r (dyn ToString + 'r)) -> FooRet {quux}>>`
|
||||
|
||||
error: opaque type's hidden type cannot be another opaque type from the same scope
|
||||
--> $DIR/issue-70877.rs:31:12
|
||||
|
|
||||
LL | type Item = FooItem;
|
||||
| ^^^^^^^
|
||||
= note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
|
||||
found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>`
|
||||
LL | return func(&"oof");
|
||||
| ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope
|
||||
|
|
||||
note: opaque type whose hidden type is being assigned
|
||||
--> $DIR/issue-70877.rs:28:13
|
||||
|
|
||||
LL | fn oof() -> impl std::fmt::Debug {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
note: opaque type being used as hidden type
|
||||
--> $DIR/issue-70877.rs:4:15
|
||||
|
|
||||
LL | type FooRet = impl std::fmt::Debug;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
11
src/test/ui/impl-trait/issues/issue-74282.rs
Normal file
11
src/test/ui/impl-trait/issues/issue-74282.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
type Closure = impl Fn() -> u64;
|
||||
struct Anonymous(Closure);
|
||||
|
||||
fn main() {
|
||||
let y = || -> Closure { || 3 };
|
||||
Anonymous(|| { //~ ERROR mismatched types
|
||||
3 //~^ ERROR mismatched types
|
||||
})
|
||||
}
|
||||
33
src/test/ui/impl-trait/issues/issue-74282.stderr
Normal file
33
src/test/ui/impl-trait/issues/issue-74282.stderr
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-74282.rs:8:15
|
||||
|
|
||||
LL | type Closure = impl Fn() -> u64;
|
||||
| ---------------- the expected opaque type
|
||||
...
|
||||
LL | Anonymous(|| {
|
||||
| _______________^
|
||||
LL | | 3
|
||||
LL | | })
|
||||
| |_____^ expected closure, found a different closure
|
||||
|
|
||||
= note: expected opaque type `Closure`
|
||||
found closure `[closure@$DIR/issue-74282.rs:8:15: 10:6]`
|
||||
= note: no two closures, even if identical, have the same type
|
||||
= help: consider boxing your closure and/or using it as a trait object
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-74282.rs:8:5
|
||||
|
|
||||
LL | fn main() {
|
||||
| - expected `()` because of default return type
|
||||
LL | let y = || -> Closure { || 3 };
|
||||
LL | / Anonymous(|| {
|
||||
LL | | 3
|
||||
LL | | })
|
||||
| | ^- help: consider using a semicolon here: `;`
|
||||
| |______|
|
||||
| expected `()`, found struct `Anonymous`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
21
src/test/ui/impl-trait/issues/issue-77987.rs
Normal file
21
src/test/ui/impl-trait/issues/issue-77987.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// check-pass
|
||||
|
||||
trait Foo<T> {}
|
||||
impl<T, U> Foo<T> for U {}
|
||||
|
||||
type Scope = impl Foo<()>;
|
||||
|
||||
#[allow(unused)]
|
||||
fn infer_scope() -> Scope {
|
||||
()
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn ice() -> impl Foo<Scope>
|
||||
{
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -7,10 +7,11 @@ type F = impl core::future::Future<Output = u8>;
|
|||
struct Bug {
|
||||
V1: [(); {
|
||||
fn concrete_use() -> F {
|
||||
async {}
|
||||
async {} //~ ERROR type mismatch
|
||||
}
|
||||
let f: F = async { 1 };
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~^ ERROR `async` blocks are not allowed in constants
|
||||
//~| ERROR destructors cannot be evaluated at compile-time
|
||||
1
|
||||
}],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
error[E0308]: mismatched types
|
||||
error[E0658]: `async` blocks are not allowed in constants
|
||||
--> $DIR/issue-78722.rs:12:20
|
||||
|
|
||||
LL | type F = impl core::future::Future<Output = u8>;
|
||||
| -------------------------------------- the expected opaque type
|
||||
...
|
||||
LL | let f: F = async { 1 };
|
||||
| - ^^^^^^^^^^^ expected opaque type, found a different opaque type
|
||||
| |
|
||||
| expected due to this
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
|
||||
|
|
||||
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
|
||||
| ------------------------------- the found opaque type
|
||||
|
|
||||
= note: expected opaque type `impl Future<Output = u8>`
|
||||
found opaque type `impl Future`
|
||||
= note: distinct uses of `impl Trait` result in different opaque types
|
||||
= note: see issue #85368 <https://github.com/rust-lang/rust/issues/85368> for more information
|
||||
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0493]: destructors cannot be evaluated at compile-time
|
||||
--> $DIR/issue-78722.rs:12:13
|
||||
|
|
||||
LL | let f: F = async { 1 };
|
||||
| ^ constants cannot evaluate destructors
|
||||
...
|
||||
LL | }],
|
||||
| - value is dropped here
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == u8`
|
||||
--> $DIR/issue-78722.rs:10:13
|
||||
|
|
||||
LL | async {}
|
||||
| ^^^^^^^^ expected `()`, found `u8`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0271, E0493, E0658.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
19
src/test/ui/impl-trait/issues/issue-82139.rs
Normal file
19
src/test/ui/impl-trait/issues/issue-82139.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait Trait {
|
||||
type Associated;
|
||||
fn func() -> Self::Associated;
|
||||
}
|
||||
|
||||
trait Bound {}
|
||||
pub struct Struct;
|
||||
|
||||
impl Trait for Struct {
|
||||
type Associated = impl Bound;
|
||||
|
||||
fn func() -> Self::Associated {
|
||||
Some(42).map(|_| j) //~ ERROR cannot find value `j` in this scope
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
9
src/test/ui/impl-trait/issues/issue-82139.stderr
Normal file
9
src/test/ui/impl-trait/issues/issue-82139.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0425]: cannot find value `j` in this scope
|
||||
--> $DIR/issue-82139.rs:15:26
|
||||
|
|
||||
LL | Some(42).map(|_| j)
|
||||
| ^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0425`.
|
||||
31
src/test/ui/impl-trait/issues/issue-83919.rs
Normal file
31
src/test/ui/impl-trait/issues/issue-83919.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// edition:2021
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
trait Foo {
|
||||
type T;
|
||||
type Fut2: Future<Output=Self::T>; // ICE got triggered with traits other than Future here
|
||||
type Fut: Future<Output=Self::Fut2>;
|
||||
fn get_fut(&self) -> Self::Fut;
|
||||
}
|
||||
|
||||
struct Implementor;
|
||||
|
||||
impl Foo for Implementor {
|
||||
type T = u64;
|
||||
type Fut2 = impl Future<Output=u64>;
|
||||
type Fut = impl Future<Output=Self::Fut2>;
|
||||
|
||||
fn get_fut(&self) -> Self::Fut {
|
||||
async move {
|
||||
42 //~^ ERROR `{integer}` is not a future
|
||||
// 42 does not impl Future and rustc does actually point out the error,
|
||||
// but rustc used to panic.
|
||||
// Putting a valid Future here always worked fine.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
17
src/test/ui/impl-trait/issues/issue-83919.stderr
Normal file
17
src/test/ui/impl-trait/issues/issue-83919.stderr
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
error[E0277]: `{integer}` is not a future
|
||||
--> $DIR/issue-83919.rs:22:9
|
||||
|
|
||||
LL | / async move {
|
||||
LL | | 42
|
||||
LL | | // 42 does not impl Future and rustc does actually point out the error,
|
||||
LL | | // but rustc used to panic.
|
||||
LL | | // Putting a valid Future here always worked fine.
|
||||
LL | | }
|
||||
| |_________^ `{integer}` is not a future
|
||||
|
|
||||
= help: the trait `Future` is not implemented for `{integer}`
|
||||
= note: {integer} must be a future or must implement `IntoFuture` to be awaited
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
33
src/test/ui/impl-trait/issues/issue-84073.rs
Normal file
33
src/test/ui/impl-trait/issues/issue-84073.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
pub trait StatefulFuture<S> {}
|
||||
pub struct Never<T>(PhantomData<T>);
|
||||
impl<T> StatefulFuture<T> for Never<T> {}
|
||||
|
||||
pub struct RaceBuilder<F, S> {
|
||||
future: F,
|
||||
_phantom: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<T, F> RaceBuilder<T, F>
|
||||
where
|
||||
F: StatefulFuture<Option<T>>,
|
||||
{
|
||||
pub fn when(self) {}
|
||||
}
|
||||
|
||||
pub struct Race<T, R> {
|
||||
race: R,
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T, R> Race<T, R>
|
||||
where
|
||||
R: Fn(RaceBuilder<T, Never<T>>),
|
||||
{
|
||||
pub fn new(race: R) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Race::new(|race| race.when()); //~ ERROR type annotations needed
|
||||
}
|
||||
9
src/test/ui/impl-trait/issues/issue-84073.stderr
Normal file
9
src/test/ui/impl-trait/issues/issue-84073.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0282]: type annotations needed for `RaceBuilder<T, Never<T>>`
|
||||
--> $DIR/issue-84073.rs:32:16
|
||||
|
|
||||
LL | Race::new(|race| race.when());
|
||||
| ^^^^ consider giving this closure parameter the explicit type `RaceBuilder<T, Never<T>>`, where the type parameter `T` is specified
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#![feature(unboxed_closures)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// check-pass
|
||||
|
||||
type FunType = impl Fn<()>;
|
||||
//~^ ERROR could not find defining uses
|
||||
static STATIC_FN: FunType = some_fn;
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
fn some_fn() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-86201.rs:6:29
|
||||
|
|
||||
LL | type FunType = impl Fn<()>;
|
||||
| ----------- the expected opaque type
|
||||
LL |
|
||||
LL | static STATIC_FN: FunType = some_fn;
|
||||
| ^^^^^^^ expected opaque type, found fn item
|
||||
|
|
||||
= note: expected opaque type `impl Fn<()>`
|
||||
found fn item `fn() {some_fn}`
|
||||
|
||||
error: could not find defining uses
|
||||
--> $DIR/issue-86201.rs:4:16
|
||||
|
|
||||
LL | type FunType = impl Fn<()>;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
12
src/test/ui/impl-trait/issues/issue-86719.rs
Normal file
12
src/test/ui/impl-trait/issues/issue-86719.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait Bar {
|
||||
type E;
|
||||
}
|
||||
impl<S> Bar for S {
|
||||
type E = impl ; //~ ERROR at least one trait must be specified
|
||||
fn foo() -> Self::E { //~ ERROR `foo` is not a member
|
||||
|_| true //~ ERROR type annotations needed
|
||||
}
|
||||
}
|
||||
fn main() {}
|
||||
24
src/test/ui/impl-trait/issues/issue-86719.stderr
Normal file
24
src/test/ui/impl-trait/issues/issue-86719.stderr
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
error: at least one trait must be specified
|
||||
--> $DIR/issue-86719.rs:7:14
|
||||
|
|
||||
LL | type E = impl ;
|
||||
| ^^^^
|
||||
|
||||
error[E0407]: method `foo` is not a member of trait `Bar`
|
||||
--> $DIR/issue-86719.rs:8:5
|
||||
|
|
||||
LL | / fn foo() -> Self::E {
|
||||
LL | | |_| true
|
||||
LL | | }
|
||||
| |_____^ not a member of trait `Bar`
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/issue-86719.rs:9:10
|
||||
|
|
||||
LL | |_| true
|
||||
| ^ consider giving this closure parameter a type
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0407.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
48
src/test/ui/impl-trait/issues/issue-86800.rs
Normal file
48
src/test/ui/impl-trait/issues/issue-86800.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// edition:2021
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
struct Connection {
|
||||
}
|
||||
|
||||
trait Transaction {
|
||||
}
|
||||
|
||||
struct TestTransaction<'conn> {
|
||||
conn: &'conn Connection
|
||||
}
|
||||
|
||||
impl<'conn> Transaction for TestTransaction<'conn> {
|
||||
}
|
||||
|
||||
struct Context {
|
||||
}
|
||||
|
||||
type TransactionResult<O> = Result<O, ()>;
|
||||
|
||||
type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
|
||||
//~^ ERROR unconstrained opaque type
|
||||
|
||||
fn execute_transaction_fut<'f, F, O>(
|
||||
f: F,
|
||||
) -> impl FnOnce(&mut dyn Transaction) -> TransactionFuture<O>
|
||||
where
|
||||
F: FnOnce(&mut dyn Transaction) -> TransactionFuture<O> + 'f
|
||||
{
|
||||
f
|
||||
}
|
||||
|
||||
impl Context {
|
||||
async fn do_transaction<O>(
|
||||
&self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<O>
|
||||
) -> TransactionResult<O>
|
||||
{
|
||||
let mut conn = Connection {};
|
||||
let mut transaction = TestTransaction { conn: &mut conn };
|
||||
f(&mut transaction).await
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
10
src/test/ui/impl-trait/issues/issue-86800.stderr
Normal file
10
src/test/ui/impl-trait/issues/issue-86800.stderr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
error: unconstrained opaque type
|
||||
--> $DIR/issue-86800.rs:25:34
|
||||
|
|
||||
LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `TransactionFuture` must be used in combination with a concrete type within the same module
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
14
src/test/ui/impl-trait/issues/issue-87340.rs
Normal file
14
src/test/ui/impl-trait/issues/issue-87340.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait X {
|
||||
type I;
|
||||
fn f() -> Self::I;
|
||||
}
|
||||
|
||||
impl<T> X for () {
|
||||
//~^ ERROR `T` is not constrained by the impl trait, self type, or predicates
|
||||
type I = impl Sized;
|
||||
fn f() -> Self::I {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
9
src/test/ui/impl-trait/issues/issue-87340.stderr
Normal file
9
src/test/ui/impl-trait/issues/issue-87340.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/issue-87340.rs:8:6
|
||||
|
|
||||
LL | impl<T> X for () {
|
||||
| ^ unconstrained type parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0207`.
|
||||
51
src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr
Normal file
51
src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:17:5
|
||||
|
|
||||
LL | &()
|
||||
| ^^^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
|
||||
|
||||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:17:5
|
||||
|
|
||||
LL | &()
|
||||
| ^^^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
|
||||
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/issue-88236-2.rs:20:5
|
||||
|
|
||||
LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||
| -- lifetime `'b` defined here
|
||||
LL | x
|
||||
| ^ returning this value requires that `'b` must outlive `'static`
|
||||
|
|
||||
help: to allow this `impl Trait` to capture borrowed data with lifetime `'b`, add `'b` as a bound
|
||||
|
|
||||
LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> + 'b {
|
||||
| ++++
|
||||
|
||||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:20:5
|
||||
|
|
||||
LL | x
|
||||
| ^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
|
||||
|
||||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:20:5
|
||||
|
|
||||
LL | x
|
||||
| ^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
23
src/test/ui/impl-trait/issues/issue-88236-2.rs
Normal file
23
src/test/ui/impl-trait/issues/issue-88236-2.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// this used to cause stack overflows
|
||||
|
||||
trait Hrtb<'a> {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
impl<'a> Hrtb<'a> for () {
|
||||
type Assoc = ();
|
||||
}
|
||||
|
||||
impl<'a> Hrtb<'a> for &'a () {
|
||||
type Assoc = ();
|
||||
}
|
||||
|
||||
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||
fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||
&() //~^ ERROR implementation of `Hrtb` is not general enough
|
||||
}
|
||||
fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||
x //~^ ERROR implementation of `Hrtb` is not general enough
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
23
src/test/ui/impl-trait/issues/issue-88236-2.stderr
Normal file
23
src/test/ui/impl-trait/issues/issue-88236-2.stderr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:16:38
|
||||
|
|
||||
LL | fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `Hrtb<'0>` would have to be implemented for the type `&()`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'1>` is actually implemented for the type `&'1 ()`, for some specific lifetime `'1`
|
||||
|
||||
error: implementation of `Hrtb` is not general enough
|
||||
--> $DIR/issue-88236-2.rs:19:82
|
||||
|
|
||||
LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||
| __________________________________________________________________________________^
|
||||
LL | | x
|
||||
LL | | }
|
||||
| |_^ implementation of `Hrtb` is not general enough
|
||||
|
|
||||
= note: `&()` must implement `Hrtb<'0>`, for any lifetime `'0`...
|
||||
= note: ...but `Hrtb<'_>` is actually implemented for the type `&()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
19
src/test/ui/impl-trait/issues/issue-88236.rs
Normal file
19
src/test/ui/impl-trait/issues/issue-88236.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// check-pass
|
||||
|
||||
// this used to cause stack overflows
|
||||
|
||||
trait Hrtb<'a> {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
impl<'a> Hrtb<'a> for () {
|
||||
type Assoc = ();
|
||||
}
|
||||
|
||||
impl<'a> Hrtb<'a> for &'a () {
|
||||
type Assoc = ();
|
||||
}
|
||||
|
||||
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||
|
||||
fn main() {}
|
||||
24
src/test/ui/impl-trait/issues/issue-89312.rs
Normal file
24
src/test/ui/impl-trait/issues/issue-89312.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// check-pass
|
||||
|
||||
trait T { type Item; }
|
||||
|
||||
type Alias<'a> = impl T<Item = &'a ()>;
|
||||
|
||||
struct S;
|
||||
impl<'a> T for &'a S {
|
||||
type Item = &'a ();
|
||||
}
|
||||
|
||||
fn filter_positive<'a>() -> Alias<'a> {
|
||||
&S
|
||||
}
|
||||
|
||||
fn with_positive(fun: impl Fn(Alias<'_>)) {
|
||||
fun(filter_positive());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
with_positive(|_| ());
|
||||
}
|
||||
27
src/test/ui/impl-trait/issues/issue-93788.rs
Normal file
27
src/test/ui/impl-trait/issues/issue-93788.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// check-pass
|
||||
|
||||
struct D;
|
||||
|
||||
trait Tr {
|
||||
type It;
|
||||
fn foo(self) -> Option<Self::It>;
|
||||
}
|
||||
|
||||
impl<'a> Tr for &'a D {
|
||||
type It = ();
|
||||
fn foo(self) -> Option<()> { None }
|
||||
}
|
||||
|
||||
fn run<F>(f: F)
|
||||
where for<'a> &'a D: Tr,
|
||||
F: Fn(<&D as Tr>::It),
|
||||
{
|
||||
let d = &D;
|
||||
while let Some(i) = d.foo() {
|
||||
f(i);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
run(|_| {});
|
||||
}
|
||||
10
src/test/ui/impl-trait/lifetimes2.rs
Normal file
10
src/test/ui/impl-trait/lifetimes2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// check-pass
|
||||
|
||||
pub fn keys<'a>(x: &'a Result<u32, u32>) -> impl std::fmt::Debug + 'a {
|
||||
match x {
|
||||
Ok(map) => Ok(map),
|
||||
Err(map) => Err(map),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue