diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-01 10:36:29 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-13 10:39:24 +0100 |
| commit | cdbbc25cc31080e189a98c010a0b39a9074d0c50 (patch) | |
| tree | 7250ff1fb02bc400e2824b960a3a6f453e1f7d22 /src | |
| parent | 04253791952d85a4da5d19d228cbac92e37ee2b9 (diff) | |
parser: move `ban_async_in_2015` to `fn` parsing & improve it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 12 | ||||
| -rw-r--r-- | src/librustc_parse/parser/mod.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/async-await/edition-deny-async-fns-2015.stderr | 36 |
3 files changed, 48 insertions, 13 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 8ba957c6b3b..a851ec2124f 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1717,6 +1717,18 @@ impl<'a> Parser<'a> { Ok(FnHeader { constness, unsafety, asyncness, ext }) } + /// We are parsing `async fn`. If we are on Rust 2015, emit an error. + fn ban_async_in_2015(&self, span: Span) { + if span.rust_2015() { + let diag = self.diagnostic(); + struct_span_err!(diag, span, E0670, "`async fn` is not permitted in the 2015 edition") + .note("to use `async fn`, switch to Rust 2018") + .help("set `edition = \"2018\"` in `Cargo.toml`") + .note("for more on editions, read https://doc.rust-lang.org/edition-guide") + .emit(); + } + } + /// Parses the parameter list and result type of a function declaration. pub(super) fn parse_fn_decl( &mut self, diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 2f2f2f8f176..4716d722778 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -1273,19 +1273,6 @@ impl<'a> Parser<'a> { } } - /// We are parsing `async fn`. If we are on Rust 2015, emit an error. - fn ban_async_in_2015(&self, async_span: Span) { - if async_span.rust_2015() { - struct_span_err!( - self.diagnostic(), - async_span, - E0670, - "`async fn` is not permitted in the 2015 edition", - ) - .emit(); - } - } - fn collect_tokens<R>( &mut self, f: impl FnOnce(&mut Self) -> PResult<'a, R>, diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr index e6859a3cd93..4afb0430a72 100644 --- a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr +++ b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr @@ -3,54 +3,90 @@ error[E0670]: `async fn` is not permitted in the 2015 edition | LL | async fn foo() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:5:12 | LL | fn baz() { async fn foo() {} } | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:7:1 | LL | async fn async_baz() { | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:8:5 | LL | async fn bar() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:14:5 | LL | async fn foo() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:18:5 | LL | async fn foo() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:36:9 | LL | async fn bar() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:26:9 | LL | async fn foo() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0670]: `async fn` is not permitted in the 2015 edition --> $DIR/edition-deny-async-fns-2015.rs:31:13 | LL | async fn bar() {} | ^^^^^ + | + = note: to use `async fn`, 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[E0706]: trait fns cannot be declared `async` --> $DIR/edition-deny-async-fns-2015.rs:18:5 |
