Rollup merge of #121044 - compiler-errors:mbe-async-trait-bounds, r=fmease
Support async trait bounds in macros r? fmease This is similar to your work on const trait bounds. This theoretically regresses `impl async $ident:ident` in macros, but I doubt this is occurring in practice.
This commit is contained in:
commit
082b97ad05
16 changed files with 229 additions and 31 deletions
|
@ -27,6 +27,8 @@ parse_async_bound_modifier_in_2015 = `async` trait bounds are only allowed in Ru
|
|||
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
|
||||
.label = to use `async fn`, switch to Rust 2018 or later
|
||||
|
||||
parse_async_impl = `async` trait implementations are unsupported
|
||||
|
||||
parse_async_move_block_in_2015 = `async move` blocks are only allowed in Rust 2018 or later
|
||||
|
||||
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect
|
||||
|
|
|
@ -2975,3 +2975,10 @@ pub(crate) struct ArrayIndexInOffsetOf(#[primary_span] pub Span);
|
|||
#[derive(Diagnostic)]
|
||||
#[diag(parse_invalid_offset_of)]
|
||||
pub(crate) struct InvalidOffsetOf(#[primary_span] pub Span);
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_async_impl)]
|
||||
pub(crate) struct AsyncImpl {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
|
|
@ -562,6 +562,15 @@ impl<'a> Parser<'a> {
|
|||
self.sess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
}
|
||||
|
||||
// Parse stray `impl async Trait`
|
||||
if (self.token.uninterpolated_span().at_least_rust_2018()
|
||||
&& self.token.is_keyword(kw::Async))
|
||||
|| self.is_kw_followed_by_ident(kw::Async)
|
||||
{
|
||||
self.bump();
|
||||
self.dcx().emit_err(errors::AsyncImpl { span: self.prev_token.span });
|
||||
}
|
||||
|
||||
let polarity = self.parse_polarity();
|
||||
|
||||
// Parse both types and traits as a type, then reinterpret if necessary.
|
||||
|
|
|
@ -778,9 +778,10 @@ impl<'a> Parser<'a> {
|
|||
|| self.check(&token::Not)
|
||||
|| self.check(&token::Question)
|
||||
|| self.check(&token::Tilde)
|
||||
|| self.check_keyword(kw::Const)
|
||||
|| self.check_keyword(kw::For)
|
||||
|| self.check(&token::OpenDelim(Delimiter::Parenthesis))
|
||||
|| self.check_keyword(kw::Const)
|
||||
|| self.check_keyword(kw::Async)
|
||||
}
|
||||
|
||||
/// Parses a bound according to the grammar:
|
||||
|
@ -882,11 +883,13 @@ impl<'a> Parser<'a> {
|
|||
BoundConstness::Never
|
||||
};
|
||||
|
||||
let asyncness = if self.token.span.at_least_rust_2018() && self.eat_keyword(kw::Async) {
|
||||
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018()
|
||||
&& self.eat_keyword(kw::Async)
|
||||
{
|
||||
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||
BoundAsyncness::Async(self.prev_token.span)
|
||||
} else if self.may_recover()
|
||||
&& self.token.span.is_rust_2015()
|
||||
&& self.token.uninterpolated_span().is_rust_2015()
|
||||
&& self.is_kw_followed_by_ident(kw::Async)
|
||||
{
|
||||
self.bump(); // eat `async`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue