Skip to content

Commit d8280fa

Browse files
authored
Rollup merge of rust-lang#62293 - Centril:remove-await-macro, r=cramertj
Unsupport the `await!(future)` macro Unsupport the `await!(future)` "macro" and recognize it in error recovery instead. The `future.await` syntax has been on nightly since 2019-05-08. This was 55 days ago which is 1.31 releases ago. Closes rust-lang#60610. r? @cramertj
2 parents f690098 + b21f0a3 commit d8280fa

21 files changed

+164
-353
lines changed

src/librustc/error_codes.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2088,11 +2088,11 @@ generator can be constructed.
20882088
Erroneous code example:
20892089
20902090
```edition2018,compile-fail,E0698
2091-
#![feature(futures_api, async_await, await_macro)]
2091+
#![feature(async_await)]
20922092
async fn bar<T>() -> () {}
20932093
20942094
async fn foo() {
2095-
await!(bar()); // error: cannot infer type for `T`
2095+
bar().await; // error: cannot infer type for `T`
20962096
}
20972097
```
20982098
@@ -2101,12 +2101,12 @@ To fix this you must bind `T` to a concrete type such as `String`
21012101
so that a generator can then be constructed:
21022102
21032103
```edition2018
2104-
#![feature(futures_api, async_await, await_macro)]
2104+
#![feature(async_await)]
21052105
async fn bar<T>() -> () {}
21062106
21072107
async fn foo() {
2108-
await!(bar::<String>());
2109-
// ^^^^^^^^ specify type explicitly
2108+
bar::<String>().await;
2109+
// ^^^^^^^^ specify type explicitly
21102110
}
21112111
```
21122112
"##,

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4685,7 +4685,7 @@ impl<'a> LoweringContext<'a> {
46854685
})
46864686
})
46874687
}
4688-
ExprKind::Await(_origin, ref expr) => self.lower_await(e.span, expr),
4688+
ExprKind::Await(ref expr) => self.lower_await(e.span, expr),
46894689
ExprKind::Closure(
46904690
capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
46914691
) => {

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ pub enum ExprKind {
11781178
/// preexisting defs.
11791179
Async(CaptureBy, NodeId, P<Block>),
11801180
/// An await expression (`my_future.await`).
1181-
Await(AwaitOrigin, P<Expr>),
1181+
Await(P<Expr>),
11821182

11831183
/// A try block (`try { ... }`).
11841184
TryBlock(P<Block>),

src/libsyntax/feature_gate.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ declare_features! (
468468
// Allows async and await syntax.
469469
(active, async_await, "1.28.0", Some(50547), None),
470470

471-
// Allows await! macro-like syntax.
472-
// This will likely be removed prior to stabilization of async/await.
473-
(active, await_macro, "1.28.0", Some(50547), None),
474-
475471
// Allows reinterpretation of the bits of a value of one type as another type during const eval.
476472
(active, const_transmute, "1.29.0", Some(53605), None),
477473

@@ -627,6 +623,8 @@ declare_features! (
627623
(removed, quote, "1.33.0", Some(29601), None, None),
628624
// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
629625
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
626+
(removed, await_macro, "1.38.0", Some(50547), None,
627+
Some("subsumed by `.await` syntax")),
630628

631629
// -------------------------------------------------------------------------
632630
// feature-group-end: removed features
@@ -2109,19 +2107,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21092107
ast::ExprKind::Async(..) => {
21102108
gate_feature_post!(&self, async_await, e.span, "async blocks are unstable");
21112109
}
2112-
ast::ExprKind::Await(origin, _) => {
2113-
match origin {
2114-
ast::AwaitOrigin::FieldLike =>
2115-
gate_feature_post!(&self, async_await, e.span, "async/await is unstable"),
2116-
ast::AwaitOrigin::MacroLike =>
2117-
gate_feature_post!(
2118-
&self,
2119-
await_macro,
2120-
e.span,
2121-
"`await!(<expr>)` macro syntax is unstable, and will soon be removed \
2122-
in favor of `<expr>.await` syntax."
2123-
),
2124-
}
2110+
ast::ExprKind::Await(_) => {
2111+
gate_feature_post!(&self, async_await, e.span, "async/await is unstable");
21252112
}
21262113
_ => {}
21272114
}

src/libsyntax/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { node, id, span, attrs }: &mut Expr,
11391139
vis.visit_id(node_id);
11401140
vis.visit_block(body);
11411141
}
1142-
ExprKind::Await(_origin, expr) => vis.visit_expr(expr),
1142+
ExprKind::Await(expr) => vis.visit_expr(expr),
11431143
ExprKind::Assign(el, er) => {
11441144
vis.visit_expr(el);
11451145
vis.visit_expr(er);

src/libsyntax/parse/diagnostics.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -869,13 +869,23 @@ impl<'a> Parser<'a> {
869869
Ok(())
870870
}
871871

872-
/// Consume alternative await syntaxes like `await <expr>`, `await? <expr>`, `await(<expr>)`
873-
/// and `await { <expr> }`.
872+
/// Consume alternative await syntaxes like `await!(<expr>)`, `await <expr>`,
873+
/// `await? <expr>`, `await(<expr>)`, and `await { <expr> }`.
874874
crate fn parse_incorrect_await_syntax(
875875
&mut self,
876876
lo: Span,
877877
await_sp: Span,
878878
) -> PResult<'a, (Span, ExprKind)> {
879+
if self.token == token::Not {
880+
// Handle `await!(<expr>)`.
881+
self.expect(&token::Not)?;
882+
self.expect(&token::OpenDelim(token::Paren))?;
883+
let expr = self.parse_expr()?;
884+
self.expect(&token::CloseDelim(token::Paren))?;
885+
let sp = self.error_on_incorrect_await(lo, self.prev_span, &expr, false);
886+
return Ok((sp, ExprKind::Await(expr)))
887+
}
888+
879889
let is_question = self.eat(&token::Question); // Handle `await? <expr>`.
880890
let expr = if self.token == token::OpenDelim(token::Brace) {
881891
// Handle `await { <expr> }`.
@@ -893,18 +903,23 @@ impl<'a> Parser<'a> {
893903
err.span_label(await_sp, "while parsing this incorrect await expression");
894904
err
895905
})?;
906+
let sp = self.error_on_incorrect_await(lo, expr.span, &expr, is_question);
907+
Ok((sp, ExprKind::Await(expr)))
908+
}
909+
910+
fn error_on_incorrect_await(&self, lo: Span, hi: Span, expr: &Expr, is_question: bool) -> Span {
896911
let expr_str = self.span_to_snippet(expr.span)
897912
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
898913
let suggestion = format!("{}.await{}", expr_str, if is_question { "?" } else { "" });
899-
let sp = lo.to(expr.span);
914+
let sp = lo.to(hi);
900915
let app = match expr.node {
901916
ExprKind::Try(_) => Applicability::MaybeIncorrect, // `await <expr>?`
902917
_ => Applicability::MachineApplicable,
903918
};
904919
self.struct_span_err(sp, "incorrect use of `await`")
905920
.span_suggestion(sp, "`await` is a postfix operation", suggestion, app)
906921
.emit();
907-
Ok((sp, ExprKind::Await(ast::AwaitOrigin::FieldLike, expr)))
922+
sp
908923
}
909924

910925
/// If encountering `future.await()`, consume and emit error.

src/libsyntax/parse/parser.rs

+11-35
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ impl<'a> Parser<'a> {
22342234
} else if self.eat_keyword(kw::Let) {
22352235
return self.parse_let_expr(attrs);
22362236
} else if is_span_rust_2018 && self.eat_keyword(kw::Await) {
2237-
let (await_hi, e_kind) = self.parse_await_macro_or_alt(lo, self.prev_span)?;
2237+
let (await_hi, e_kind) = self.parse_incorrect_await_syntax(lo, self.prev_span)?;
22382238
hi = await_hi;
22392239
ex = e_kind;
22402240
} else if self.token.is_path_start() {
@@ -2282,31 +2282,6 @@ impl<'a> Parser<'a> {
22822282
self.maybe_recover_from_bad_qpath(expr, true)
22832283
}
22842284

2285-
/// Parse `await!(<expr>)` calls, or alternatively recover from incorrect but reasonable
2286-
/// alternative syntaxes `await <expr>`, `await? <expr>`, `await(<expr>)` and
2287-
/// `await { <expr> }`.
2288-
fn parse_await_macro_or_alt(
2289-
&mut self,
2290-
lo: Span,
2291-
await_sp: Span,
2292-
) -> PResult<'a, (Span, ExprKind)> {
2293-
if self.token == token::Not {
2294-
// Handle correct `await!(<expr>)`.
2295-
// FIXME: make this an error when `await!` is no longer supported
2296-
// https://github.com/rust-lang/rust/issues/60610
2297-
self.expect(&token::Not)?;
2298-
self.expect(&token::OpenDelim(token::Paren))?;
2299-
let expr = self.parse_expr().map_err(|mut err| {
2300-
err.span_label(await_sp, "while parsing this await macro call");
2301-
err
2302-
})?;
2303-
self.expect(&token::CloseDelim(token::Paren))?;
2304-
Ok((self.prev_span, ExprKind::Await(ast::AwaitOrigin::MacroLike, expr)))
2305-
} else { // Handle `await <expr>`.
2306-
self.parse_incorrect_await_syntax(lo, await_sp)
2307-
}
2308-
}
2309-
23102285
fn maybe_parse_struct_expr(
23112286
&mut self,
23122287
lo: Span,
@@ -2509,18 +2484,19 @@ impl<'a> Parser<'a> {
25092484
)
25102485
}
25112486

2512-
// Assuming we have just parsed `.`, continue parsing into an expression.
2487+
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
2488+
let span = lo.to(self.prev_span);
2489+
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), ThinVec::new());
2490+
self.recover_from_await_method_call();
2491+
Ok(await_expr)
2492+
}
2493+
2494+
/// Assuming we have just parsed `.`, continue parsing into an expression.
25132495
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
25142496
if self.token.span.rust_2018() && self.eat_keyword(kw::Await) {
2515-
let span = lo.to(self.prev_span);
2516-
let await_expr = self.mk_expr(
2517-
span,
2518-
ExprKind::Await(ast::AwaitOrigin::FieldLike, self_arg),
2519-
ThinVec::new(),
2520-
);
2521-
self.recover_from_await_method_call();
2522-
return Ok(await_expr);
2497+
return self.mk_await_expr(self_arg, lo);
25232498
}
2499+
25242500
let segment = self.parse_path_segment(PathStyle::Expr)?;
25252501
self.check_trailing_angle_brackets(&segment, token::OpenDelim(token::Paren));
25262502

src/libsyntax/print/pprust.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -2120,17 +2120,9 @@ impl<'a> State<'a> {
21202120
self.ibox(0);
21212121
self.print_block_with_attrs(blk, attrs);
21222122
}
2123-
ast::ExprKind::Await(origin, ref expr) => {
2124-
match origin {
2125-
ast::AwaitOrigin::MacroLike => {
2126-
self.s.word("await!");
2127-
self.print_expr_maybe_paren(expr, parser::PREC_FORCE_PAREN);
2128-
}
2129-
ast::AwaitOrigin::FieldLike => {
2130-
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
2131-
self.s.word(".await");
2132-
}
2133-
}
2123+
ast::ExprKind::Await(ref expr) => {
2124+
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
2125+
self.s.word(".await");
21342126
}
21352127
ast::ExprKind::Assign(ref lhs, ref rhs) => {
21362128
let prec = AssocOp::Assign.precedence() as i8;

src/libsyntax/util/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
382382
// X { y: 1 } + X { y: 2 }
383383
contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
384384
}
385-
ast::ExprKind::Await(_, ref x) |
385+
ast::ExprKind::Await(ref x) |
386386
ast::ExprKind::Unary(_, ref x) |
387387
ast::ExprKind::Cast(ref x, _) |
388388
ast::ExprKind::Type(ref x, _) |

src/libsyntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
757757
ExprKind::Async(_, _, ref body) => {
758758
visitor.visit_block(body);
759759
}
760-
ExprKind::Await(_, ref expr) => visitor.visit_expr(expr),
760+
ExprKind::Await(ref expr) => visitor.visit_expr(expr),
761761
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
762762
visitor.visit_expr(left_hand_expression);
763763
visitor.visit_expr(right_hand_expression);

src/test/ui/async-await/await-keyword/2015-edition-error-in-non-macro-position.rs renamed to src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(async_await, await_macro)]
1+
#![feature(async_await)]
22
#![allow(non_camel_case_types)]
33
#![deny(keyword_idents)]
44

@@ -29,6 +29,9 @@ macro_rules! await {
2929
}
3030

3131
fn main() {
32+
await!(); //~ ERROR `await` is a keyword in the 2018 edition
33+
//~^ WARN this was previously accepted by the compiler
34+
3235
match await { await => {} } //~ ERROR `await` is a keyword in the 2018 edition
3336
//~^ ERROR `await` is a keyword in the 2018 edition
3437
//~^^ WARN this was previously accepted by the compiler
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: `await` is a keyword in the 2018 edition
2-
--> $DIR/2015-edition-error-in-non-macro-position.rs:6:13
2+
--> $DIR/2015-edition-error-various-positions.rs:6:13
33
|
44
LL | pub mod await {
55
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
66
|
77
note: lint level defined here
8-
--> $DIR/2015-edition-error-in-non-macro-position.rs:3:9
8+
--> $DIR/2015-edition-error-various-positions.rs:3:9
99
|
1010
LL | #![deny(keyword_idents)]
1111
| ^^^^^^^^^^^^^^
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
1313
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
1414

1515
error: `await` is a keyword in the 2018 edition
16-
--> $DIR/2015-edition-error-in-non-macro-position.rs:8:20
16+
--> $DIR/2015-edition-error-various-positions.rs:8:20
1717
|
1818
LL | pub struct await;
1919
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -22,7 +22,7 @@ LL | pub struct await;
2222
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
2323

2424
error: `await` is a keyword in the 2018 edition
25-
--> $DIR/2015-edition-error-in-non-macro-position.rs:12:16
25+
--> $DIR/2015-edition-error-various-positions.rs:12:16
2626
|
2727
LL | use outer_mod::await::await;
2828
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -31,7 +31,7 @@ LL | use outer_mod::await::await;
3131
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
3232

3333
error: `await` is a keyword in the 2018 edition
34-
--> $DIR/2015-edition-error-in-non-macro-position.rs:12:23
34+
--> $DIR/2015-edition-error-various-positions.rs:12:23
3535
|
3636
LL | use outer_mod::await::await;
3737
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -40,7 +40,7 @@ LL | use outer_mod::await::await;
4040
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
4141

4242
error: `await` is a keyword in the 2018 edition
43-
--> $DIR/2015-edition-error-in-non-macro-position.rs:17:14
43+
--> $DIR/2015-edition-error-various-positions.rs:17:14
4444
|
4545
LL | struct Foo { await: () }
4646
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -49,7 +49,7 @@ LL | struct Foo { await: () }
4949
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
5050

5151
error: `await` is a keyword in the 2018 edition
52-
--> $DIR/2015-edition-error-in-non-macro-position.rs:21:15
52+
--> $DIR/2015-edition-error-various-positions.rs:21:15
5353
|
5454
LL | impl Foo { fn await() {} }
5555
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -58,7 +58,7 @@ LL | impl Foo { fn await() {} }
5858
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
5959

6060
error: `await` is a keyword in the 2018 edition
61-
--> $DIR/2015-edition-error-in-non-macro-position.rs:25:14
61+
--> $DIR/2015-edition-error-various-positions.rs:25:14
6262
|
6363
LL | macro_rules! await {
6464
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -67,7 +67,16 @@ LL | macro_rules! await {
6767
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
6868

6969
error: `await` is a keyword in the 2018 edition
70-
--> $DIR/2015-edition-error-in-non-macro-position.rs:32:11
70+
--> $DIR/2015-edition-error-various-positions.rs:32:5
71+
|
72+
LL | await!();
73+
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
74+
|
75+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
76+
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
77+
78+
error: `await` is a keyword in the 2018 edition
79+
--> $DIR/2015-edition-error-various-positions.rs:35:11
7180
|
7281
LL | match await { await => {} }
7382
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
@@ -76,13 +85,13 @@ LL | match await { await => {} }
7685
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
7786

7887
error: `await` is a keyword in the 2018 edition
79-
--> $DIR/2015-edition-error-in-non-macro-position.rs:32:19
88+
--> $DIR/2015-edition-error-various-positions.rs:35:19
8089
|
8190
LL | match await { await => {} }
8291
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
8392
|
8493
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
8594
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
8695

87-
error: aborting due to 9 previous errors
96+
error: aborting due to 10 previous errors
8897

src/test/ui/async-await/await-keyword/2018-edition-error.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ mod outer_mod {
99
use self::outer_mod::await::await; //~ ERROR expected identifier
1010
//~^ ERROR expected identifier, found reserved keyword `await`
1111

12-
fn main() {}
12+
macro_rules! await { () => {}; } //~ ERROR expected identifier, found reserved keyword `await`
13+
14+
fn main() {
15+
await!(); //~ ERROR expected expression, found `)`
16+
}

0 commit comments

Comments
 (0)