Skip to content

Commit cdbbc25

Browse files
committed
parser: move ban_async_in_2015 to fn parsing & improve it.
1 parent 0425379 commit cdbbc25

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,18 @@ impl<'a> Parser<'a> {
17171717
Ok(FnHeader { constness, unsafety, asyncness, ext })
17181718
}
17191719

1720+
/// We are parsing `async fn`. If we are on Rust 2015, emit an error.
1721+
fn ban_async_in_2015(&self, span: Span) {
1722+
if span.rust_2015() {
1723+
let diag = self.diagnostic();
1724+
struct_span_err!(diag, span, E0670, "`async fn` is not permitted in the 2015 edition")
1725+
.note("to use `async fn`, switch to Rust 2018")
1726+
.help("set `edition = \"2018\"` in `Cargo.toml`")
1727+
.note("for more on editions, read https://doc.rust-lang.org/edition-guide")
1728+
.emit();
1729+
}
1730+
}
1731+
17201732
/// Parses the parameter list and result type of a function declaration.
17211733
pub(super) fn parse_fn_decl(
17221734
&mut self,

src/librustc_parse/parser/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,19 +1273,6 @@ impl<'a> Parser<'a> {
12731273
}
12741274
}
12751275

1276-
/// We are parsing `async fn`. If we are on Rust 2015, emit an error.
1277-
fn ban_async_in_2015(&self, async_span: Span) {
1278-
if async_span.rust_2015() {
1279-
struct_span_err!(
1280-
self.diagnostic(),
1281-
async_span,
1282-
E0670,
1283-
"`async fn` is not permitted in the 2015 edition",
1284-
)
1285-
.emit();
1286-
}
1287-
}
1288-
12891276
fn collect_tokens<R>(
12901277
&mut self,
12911278
f: impl FnOnce(&mut Self) -> PResult<'a, R>,

src/test/ui/async-await/edition-deny-async-fns-2015.stderr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,90 @@ error[E0670]: `async fn` is not permitted in the 2015 edition
33
|
44
LL | async fn foo() {}
55
| ^^^^^
6+
|
7+
= note: to use `async fn`, switch to Rust 2018
8+
= help: set `edition = "2018"` in `Cargo.toml`
9+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
610

711
error[E0670]: `async fn` is not permitted in the 2015 edition
812
--> $DIR/edition-deny-async-fns-2015.rs:5:12
913
|
1014
LL | fn baz() { async fn foo() {} }
1115
| ^^^^^
16+
|
17+
= note: to use `async fn`, switch to Rust 2018
18+
= help: set `edition = "2018"` in `Cargo.toml`
19+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1220

1321
error[E0670]: `async fn` is not permitted in the 2015 edition
1422
--> $DIR/edition-deny-async-fns-2015.rs:7:1
1523
|
1624
LL | async fn async_baz() {
1725
| ^^^^^
26+
|
27+
= note: to use `async fn`, switch to Rust 2018
28+
= help: set `edition = "2018"` in `Cargo.toml`
29+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1830

1931
error[E0670]: `async fn` is not permitted in the 2015 edition
2032
--> $DIR/edition-deny-async-fns-2015.rs:8:5
2133
|
2234
LL | async fn bar() {}
2335
| ^^^^^
36+
|
37+
= note: to use `async fn`, switch to Rust 2018
38+
= help: set `edition = "2018"` in `Cargo.toml`
39+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
2440

2541
error[E0670]: `async fn` is not permitted in the 2015 edition
2642
--> $DIR/edition-deny-async-fns-2015.rs:14:5
2743
|
2844
LL | async fn foo() {}
2945
| ^^^^^
46+
|
47+
= note: to use `async fn`, switch to Rust 2018
48+
= help: set `edition = "2018"` in `Cargo.toml`
49+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
3050

3151
error[E0670]: `async fn` is not permitted in the 2015 edition
3252
--> $DIR/edition-deny-async-fns-2015.rs:18:5
3353
|
3454
LL | async fn foo() {}
3555
| ^^^^^
56+
|
57+
= note: to use `async fn`, switch to Rust 2018
58+
= help: set `edition = "2018"` in `Cargo.toml`
59+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
3660

3761
error[E0670]: `async fn` is not permitted in the 2015 edition
3862
--> $DIR/edition-deny-async-fns-2015.rs:36:9
3963
|
4064
LL | async fn bar() {}
4165
| ^^^^^
66+
|
67+
= note: to use `async fn`, switch to Rust 2018
68+
= help: set `edition = "2018"` in `Cargo.toml`
69+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
4270

4371
error[E0670]: `async fn` is not permitted in the 2015 edition
4472
--> $DIR/edition-deny-async-fns-2015.rs:26:9
4573
|
4674
LL | async fn foo() {}
4775
| ^^^^^
76+
|
77+
= note: to use `async fn`, switch to Rust 2018
78+
= help: set `edition = "2018"` in `Cargo.toml`
79+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
4880

4981
error[E0670]: `async fn` is not permitted in the 2015 edition
5082
--> $DIR/edition-deny-async-fns-2015.rs:31:13
5183
|
5284
LL | async fn bar() {}
5385
| ^^^^^
86+
|
87+
= note: to use `async fn`, switch to Rust 2018
88+
= help: set `edition = "2018"` in `Cargo.toml`
89+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
5490

5591
error[E0706]: trait fns cannot be declared `async`
5692
--> $DIR/edition-deny-async-fns-2015.rs:18:5

0 commit comments

Comments
 (0)