-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle desugaring in impl trait bound suggestion
- Loading branch information
Showing
5 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/ui/suggestions/issue-79843-impl-trait-with-missing-bounds-on-async-fn.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Regression test: if we suggest replacing an `impl Trait` argument to an async | ||
// fn with a named type parameter in order to add bounds, the suggested function | ||
// signature should be well-formed. | ||
// | ||
// edition:2018 | ||
|
||
trait Foo { | ||
type Bar; | ||
fn bar(&self) -> Self::Bar; | ||
} | ||
|
||
async fn run(_: &(), foo: impl Foo) -> std::io::Result<()> { | ||
let bar = foo.bar(); | ||
assert_is_send(&bar); | ||
//~^ ERROR: `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
|
||
Ok(()) | ||
} | ||
|
||
// Test our handling of cases where there is a generic parameter list in the | ||
// source, but only synthetic generic parameters | ||
async fn run2< >(_: &(), foo: impl Foo) -> std::io::Result<()> { | ||
let bar = foo.bar(); | ||
assert_is_send(&bar); | ||
//~^ ERROR: `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
|
||
Ok(()) | ||
} | ||
|
||
fn assert_is_send<T: Send>(_: &T) {} | ||
|
||
fn main() {} |
33 changes: 33 additions & 0 deletions
33
src/test/ui/suggestions/issue-79843-impl-trait-with-missing-bounds-on-async-fn.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0277]: `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
--> $DIR/issue-79843-impl-trait-with-missing-bounds-on-async-fn.rs:14:20 | ||
| | ||
LL | assert_is_send(&bar); | ||
| ^^^^ `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
... | ||
LL | fn assert_is_send<T: Send>(_: &T) {} | ||
| ---- required by this bound in `assert_is_send` | ||
| | ||
= help: the trait `Send` is not implemented for `<impl Foo as Foo>::Bar` | ||
help: introduce a type parameter with a trait bound instead of using `impl Trait` | ||
| | ||
LL | async fn run<F: Foo>(_: &(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send { | ||
| ^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
--> $DIR/issue-79843-impl-trait-with-missing-bounds-on-async-fn.rs:24:20 | ||
| | ||
LL | assert_is_send(&bar); | ||
| ^^^^ `<impl Foo as Foo>::Bar` cannot be sent between threads safely | ||
... | ||
LL | fn assert_is_send<T: Send>(_: &T) {} | ||
| ---- required by this bound in `assert_is_send` | ||
| | ||
= help: the trait `Send` is not implemented for `<impl Foo as Foo>::Bar` | ||
help: introduce a type parameter with a trait bound instead of using `impl Trait` | ||
| | ||
LL | async fn run2<F: Foo>(_: &(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send { | ||
| ^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |