Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
770538e
Add fix suggestions for E0199, E0200, and E0569
nbarrios1337 Oct 20, 2022
641bf08
Don't merge inline doc comments for impl blocks
GuillaumeGomez Oct 25, 2022
a4279a1
Add regression test for inlined doc comment on impl block
GuillaumeGomez Oct 25, 2022
b205a5a
diagnostics: do not suggest static candidates as traits to import
notriddle Oct 25, 2022
8cf9ad6
diagnostics: add test case for issue 102354
notriddle Oct 25, 2022
dce44fa
Revert "Make ClosureOutlivesRequirement not rely on an unresolved type"
compiler-errors Oct 27, 2022
4e0c27b
Erase regions from CallArgument, add test + bless
compiler-errors Oct 27, 2022
97423d3
Add tests for static async functions in traits
bryangarza Oct 4, 2022
8a0ebca
Update static AFIT tests based on feedback
bryangarza Oct 4, 2022
11b1439
Update tests based on feedback
bryangarza Oct 7, 2022
9a05081
Add additional tests for static AFIT
bryangarza Oct 7, 2022
0b3b046
Update src/test/ui/async-await/in-trait/async-example.rs
bryangarza Oct 27, 2022
bfdefdb
Update tests based on feedback
bryangarza Oct 27, 2022
c404092
Rollup merge of #102642 - bryangarza:afit-tests, r=compiler-errors
matthiaskrgr Oct 28, 2022
270e0c5
Rollup merge of #103283 - nbarrios1337:unsafe-impl-suggestions, r=cjg…
matthiaskrgr Oct 28, 2022
2f02cf8
Rollup merge of #103523 - GuillaumeGomez:inline-doc-comment-impl-bloc…
matthiaskrgr Oct 28, 2022
f541ad9
Rollup merge of #103550 - notriddle:notriddle/no-suggest-static-candi…
matthiaskrgr Oct 28, 2022
84663ce
Rollup merge of #103641 - compiler-errors:issue-103624, r=cjgillot
matthiaskrgr Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for static async functions in traits
This patch adds test cases for AFIT, the majority of which are currently
expected to run as `check-fail`.
  • Loading branch information
bryangarza committed Oct 27, 2022
commit 97423d331f5dbed3bbbf474e3b6bd2d8b7bd9af2
24 changes: 24 additions & 0 deletions src/test/ui/async-await/in-trait/async-associated-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use std::fmt::Debug;

trait MyTrait<'a, 'b, T> where Self: 'a, T: Debug + Sized + 'b {
type MyAssoc;// = (&'a T, &'b U);

async fn foo(&'a self, key: &'b T) -> Self::MyAssoc;
}

impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
type MyAssoc = (&'a U, &'b T);

async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
(self, key)
}
}
//~^^^^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements

fn main() {}
57 changes: 57 additions & 0 deletions src/test/ui/async-await/in-trait/async-associated-types.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
--> $DIR/async-associated-types.rs:14:6
|
LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
| ^^
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `(&'a U, &'b T)`
found `(&U, &T)`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `MyTrait<'static, 'static, T>`
found `MyTrait<'_, '_, T>`

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
--> $DIR/async-associated-types.rs:14:10
|
LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
| ^^
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `(&'a U, &'b T)`
found `(&U, &T)`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `MyTrait<'static, 'static, T>`
found `MyTrait<'_, '_, T>`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use std::future::Future;

trait MyTrait {
type Fut<'a>: Future<Output = i32>
where
Self: 'a;

async fn foo(&self) -> Self::Fut<'a>;
//~^ ERROR use of undeclared lifetime name `'a`
//~| ERROR the parameter type `Self` may not live long enough
}

impl MyTrait for i32 {
type Fut<'a> = impl Future + 'a
where
Self: 'a;
//~^^^ ERROR `impl Trait` in type aliases is unstable

fn foo<'a>(&'a self) -> Self::Fut<'a> {
async {
*self
}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/async-associated-types2-desugared.rs:13:38
|
LL | async fn foo(&self) -> Self::Fut<'a>;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | async fn foo<'a>(&self) -> Self::Fut<'a>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | trait MyTrait<'a> {
| ++++

error[E0658]: `impl Trait` in type aliases is unstable
--> $DIR/async-associated-types2-desugared.rs:19:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0310]: the parameter type `Self` may not live long enough
--> $DIR/async-associated-types2-desugared.rs:13:28
|
LL | async fn foo(&self) -> Self::Fut<'a>;
| ^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `Self: 'static`...
= note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
--> $DIR/async-associated-types2-desugared.rs:11:15
|
LL | Self: 'a;
| ^^

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0261, E0310, E0658.
For more information about an error, try `rustc --explain E0261`.
32 changes: 32 additions & 0 deletions src/test/ui/async-await/in-trait/async-associated-types2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use std::future::Future;

trait MyTrait {
type Fut<'a>: Future<Output = i32>
where
Self: 'a;

fn foo(&self) -> Self::Fut<'a>;
//~^ ERROR use of undeclared lifetime name `'a`
}

impl MyTrait for i32 {
type Fut<'a> = impl Future + 'a
where
Self: 'a;
//~^^^ ERROR `impl Trait` in type aliases is unstable
//~| ERROR expected `<i32 as MyTrait>::Fut<'a>` to be a future that resolves to `i32`, but it resolves to `<<i32 as MyTrait>::Fut<'a> as Future>::Output`

fn foo<'a>(&'a self) -> Self::Fut<'a> {
//~^ ERROR `impl` item signature doesn't match `trait` item signature
async {
*self
}
}
}

fn main() {}
63 changes: 63 additions & 0 deletions src/test/ui/async-await/in-trait/async-associated-types2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/async-associated-types2.rs:13:32
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn foo<'a>(&self) -> Self::Fut<'a>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | trait MyTrait<'a> {
| ++++

error[E0658]: `impl Trait` in type aliases is unstable
--> $DIR/async-associated-types2.rs:18:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0271]: expected `<i32 as MyTrait>::Fut<'a>` to be a future that resolves to `i32`, but it resolves to `<<i32 as MyTrait>::Fut<'a> as Future>::Output`
--> $DIR/async-associated-types2.rs:18:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^ expected `i32`, found associated type
|
= note: expected type `i32`
found associated type `<<i32 as MyTrait>::Fut<'a> as Future>::Output`
note: required by a bound in `MyTrait::Fut`
--> $DIR/async-associated-types2.rs:9:26
|
LL | type Fut<'a>: Future<Output = i32>
| ^^^^^^^^^^^^ required by this bound in `MyTrait::Fut`
help: consider constraining the associated type `<<i32 as MyTrait>::Fut<'a> as Future>::Output` to `i32`
|
LL | type Fut<'a> = impl Future<Output = i32> + 'a
| ++++++++++++++

error: `impl` item signature doesn't match `trait` item signature
--> $DIR/async-associated-types2.rs:24:5
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ------------------------------- expected `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'static>`
...
LL | fn foo<'a>(&'a self) -> Self::Fut<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'1>`
|
= note: expected `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'static>`
found `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'1>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
--> $DIR/async-associated-types2.rs:13:22
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ^^^^ consider borrowing this type parameter in the trait

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0261, E0271, E0658.
For more information about an error, try `rustc --explain E0261`.
17 changes: 17 additions & 0 deletions src/test/ui/async-await/in-trait/async-example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-pass
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

trait MyTrait {
async fn foo(&self) -> i32;
}

impl MyTrait for i32 {
async fn foo(&self) -> i32 {
*self
}
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/async-await/in-trait/async-generics-and-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use std::fmt::Debug;
use std::hash::Hash;

trait MyTrait<T, U> {
async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
}
//~^^ ERROR the parameter type `U` may not live long enough
//~| ERROR the parameter type `T` may not live long enough

impl<T, U> MyTrait<T, U> for (T, U) {
async fn foo(&self) -> &(T, U) {
self
}
}

fn main() {}
37 changes: 37 additions & 0 deletions src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:10:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^

error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:10:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0311`.
18 changes: 18 additions & 0 deletions src/test/ui/async-await/in-trait/async-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

trait MyTrait<T, U> {
async fn foo(&self) -> &(T, U);
}
//~^^ ERROR the parameter type `U` may not live long enough
//~| ERROR the parameter type `T` may not live long enough

impl<T, U> MyTrait<T, U> for (T, U) {
async fn foo(&self) -> &(T, U) {
self
}
}

fn main() {}
37 changes: 37 additions & 0 deletions src/test/ui/async-await/in-trait/async-generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:7:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^

error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:7:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0311`.
Loading