forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#63539 - Centril:2015.await, r=oli-obk
Suggest Rust 2018 on `<expr>.await` with no such field When type checking a field projection (`fn check_field`) to `<expr>.await` where `<expr>: τ` and `τ` is not a primitive type, suggest switching to Rust 2018. E.g. ``` error[E0609]: no field `await` on type `std::pin::Pin<&mut dyn std::future::Future<Output = ()>>` --> $DIR/suggest-switching-edition-on-await.rs:31:7 | LL | x.await; | ^^^^^ unknown field | = note: to `.await` a `Future`, switch to Rust 2018 = help: set `edition = "2018"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide ``` Fixes rust-lang#63533 This PR also performs some preparatory cleanups in `fn check_field`; the last 2 commits are where the suggestion is introduced and tested respectively. r? @varkor
- Loading branch information
Showing
3 changed files
with
256 additions
and
101 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
45 changes: 45 additions & 0 deletions
45
src/test/ui/async-await/suggest-switching-edition-on-await.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,45 @@ | ||
use std::pin::Pin; | ||
use std::future::Future; | ||
|
||
fn main() {} | ||
|
||
fn await_on_struct_missing() { | ||
struct S; | ||
let x = S; | ||
x.await; | ||
//~^ ERROR no field `await` on type | ||
//~| NOTE unknown field | ||
//~| NOTE to `.await` a `Future`, switch to Rust 2018 | ||
//~| HELP set `edition = "2018"` in `Cargo.toml` | ||
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide | ||
} | ||
|
||
fn await_on_struct_similar() { | ||
struct S { | ||
awai: u8, | ||
} | ||
let x = S { awai: 42 }; | ||
x.await; | ||
//~^ ERROR no field `await` on type | ||
//~| HELP a field with a similar name exists | ||
//~| NOTE to `.await` a `Future`, switch to Rust 2018 | ||
//~| HELP set `edition = "2018"` in `Cargo.toml` | ||
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide | ||
} | ||
|
||
fn await_on_63533(x: Pin<&mut dyn Future<Output = ()>>) { | ||
x.await; | ||
//~^ ERROR no field `await` on type | ||
//~| NOTE unknown field | ||
//~| NOTE to `.await` a `Future`, switch to Rust 2018 | ||
//~| HELP set `edition = "2018"` in `Cargo.toml` | ||
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide | ||
} | ||
|
||
fn await_on_apit(x: impl Future<Output = ()>) { | ||
x.await; | ||
//~^ ERROR no field `await` on type | ||
//~| NOTE to `.await` a `Future`, switch to Rust 2018 | ||
//~| HELP set `edition = "2018"` in `Cargo.toml` | ||
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/ui/async-await/suggest-switching-edition-on-await.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,43 @@ | ||
error[E0609]: no field `await` on type `await_on_struct_missing::S` | ||
--> $DIR/suggest-switching-edition-on-await.rs:9:7 | ||
| | ||
LL | x.await; | ||
| ^^^^^ unknown field | ||
| | ||
= note: to `.await` a `Future`, switch to Rust 2018 | ||
= help: set `edition = "2018"` in `Cargo.toml` | ||
= note: for more on editions, read https://doc.rust-lang.org/edition-guide | ||
|
||
error[E0609]: no field `await` on type `await_on_struct_similar::S` | ||
--> $DIR/suggest-switching-edition-on-await.rs:22:7 | ||
| | ||
LL | x.await; | ||
| ^^^^^ help: a field with a similar name exists: `awai` | ||
| | ||
= note: to `.await` a `Future`, switch to Rust 2018 | ||
= help: set `edition = "2018"` in `Cargo.toml` | ||
= note: for more on editions, read https://doc.rust-lang.org/edition-guide | ||
|
||
error[E0609]: no field `await` on type `std::pin::Pin<&mut dyn std::future::Future<Output = ()>>` | ||
--> $DIR/suggest-switching-edition-on-await.rs:31:7 | ||
| | ||
LL | x.await; | ||
| ^^^^^ unknown field | ||
| | ||
= note: to `.await` a `Future`, switch to Rust 2018 | ||
= help: set `edition = "2018"` in `Cargo.toml` | ||
= note: for more on editions, read https://doc.rust-lang.org/edition-guide | ||
|
||
error[E0609]: no field `await` on type `impl Future<Output = ()>` | ||
--> $DIR/suggest-switching-edition-on-await.rs:40:7 | ||
| | ||
LL | x.await; | ||
| ^^^^^ | ||
| | ||
= note: to `.await` a `Future`, switch to Rust 2018 | ||
= help: set `edition = "2018"` in `Cargo.toml` | ||
= note: for more on editions, read https://doc.rust-lang.org/edition-guide | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0609`. |