Better error message in ed 2015
This commit is contained in:
parent
cd2fd34ca6
commit
54db272cc9
@ -22,6 +22,8 @@ parse_associated_static_item_not_allowed = associated `static` items are not all
|
|||||||
|
|
||||||
parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or later
|
parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or later
|
||||||
|
|
||||||
|
parse_async_bound_modifier_in_2015 = `async` trait bounds are only allowed in Rust 2018 or later
|
||||||
|
|
||||||
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
|
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
|
||||||
.label = to use `async fn`, switch to Rust 2018 or later
|
.label = to use `async fn`, switch to Rust 2018 or later
|
||||||
|
|
||||||
|
@ -1588,6 +1588,15 @@ pub(crate) struct AsyncMoveBlockIn2015 {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(parse_async_bound_modifier_in_2015)]
|
||||||
|
pub(crate) struct AsyncBoundModifierIn2015 {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub help: HelpUseLatestEdition,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(parse_self_argument_pointer)]
|
#[diag(parse_self_argument_pointer)]
|
||||||
pub(crate) struct SelfArgumentPointer {
|
pub(crate) struct SelfArgumentPointer {
|
||||||
|
@ -3,8 +3,8 @@ use super::{Parser, PathStyle, TokenType};
|
|||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
|
self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
|
||||||
FnPointerCannotBeAsync, FnPointerCannotBeConst, FnPtrWithGenerics, FnPtrWithGenericsSugg,
|
FnPointerCannotBeAsync, FnPointerCannotBeConst, FnPtrWithGenerics, FnPtrWithGenericsSugg,
|
||||||
InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime, NestedCVariadicType,
|
HelpUseLatestEdition, InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime,
|
||||||
ReturnTypesUseThinArrow,
|
NestedCVariadicType, ReturnTypesUseThinArrow,
|
||||||
};
|
};
|
||||||
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||||
|
|
||||||
@ -882,6 +882,17 @@ impl<'a> Parser<'a> {
|
|||||||
let asyncness = if self.token.span.at_least_rust_2018() && self.eat_keyword(kw::Async) {
|
let asyncness = if self.token.span.at_least_rust_2018() && self.eat_keyword(kw::Async) {
|
||||||
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||||
BoundAsyncness::Async(self.prev_token.span)
|
BoundAsyncness::Async(self.prev_token.span)
|
||||||
|
} else if self.may_recover()
|
||||||
|
&& self.token.span.is_rust_2015()
|
||||||
|
&& self.is_kw_followed_by_ident(kw::Async)
|
||||||
|
{
|
||||||
|
self.bump(); // eat `async`
|
||||||
|
self.dcx().emit_err(errors::AsyncBoundModifierIn2015 {
|
||||||
|
span: self.prev_token.span,
|
||||||
|
help: HelpUseLatestEdition::new(),
|
||||||
|
});
|
||||||
|
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||||
|
BoundAsyncness::Async(self.prev_token.span)
|
||||||
} else {
|
} else {
|
||||||
BoundAsyncness::Normal
|
BoundAsyncness::Normal
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
// check-pass
|
||||||
|
// Make sure that we don't eagerly recover `async ::Bound` in edition 2015.
|
||||||
|
|
||||||
|
mod async {
|
||||||
|
pub trait Foo {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(x: impl async ::Foo) {}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -1,8 +1,7 @@
|
|||||||
// FIXME(async_closures): This error message could be made better.
|
fn foo(x: impl async Fn()) -> impl async Fn() { x }
|
||||||
|
//~^ ERROR `async` trait bounds are only allowed in Rust 2018 or later
|
||||||
fn foo(x: impl async Fn()) -> impl async Fn() {}
|
//~| ERROR `async` trait bounds are only allowed in Rust 2018 or later
|
||||||
//~^ ERROR expected
|
//~| ERROR async closures are unstable
|
||||||
//~| ERROR expected
|
//~| ERROR async closures are unstable
|
||||||
//~| ERROR expected
|
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,22 +1,43 @@
|
|||||||
error: expected one of `:` or `|`, found `)`
|
error: `async` trait bounds are only allowed in Rust 2018 or later
|
||||||
--> $DIR/edition-2015.rs:3:26
|
--> $DIR/edition-2015.rs:1:16
|
||||||
|
|
|
|
||||||
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
|
||||||
| ^ expected one of `:` or `|`
|
| ^^^^^
|
||||||
|
|
||||||
error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `Fn`
|
|
||||||
--> $DIR/edition-2015.rs:3:22
|
|
||||||
|
|
|
|
||||||
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
|
= help: pass `--edition 2021` to `rustc`
|
||||||
| -^^ expected one of `(`, `)`, `+`, `,`, `::`, or `<`
|
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
|
||||||
| |
|
|
||||||
| help: missing `,`
|
|
||||||
|
|
||||||
error: expected one of `(`, `+`, `::`, `<`, `where`, or `{`, found `Fn`
|
error: `async` trait bounds are only allowed in Rust 2018 or later
|
||||||
--> $DIR/edition-2015.rs:3:42
|
--> $DIR/edition-2015.rs:1:36
|
||||||
|
|
|
|
||||||
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
|
||||||
| ^^ expected one of `(`, `+`, `::`, `<`, `where`, or `{`
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= help: pass `--edition 2021` to `rustc`
|
||||||
|
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error[E0658]: async closures are unstable
|
||||||
|
--> $DIR/edition-2015.rs:1:16
|
||||||
|
|
|
||||||
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
|
||||||
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
|
||||||
|
= help: add `#![feature(async_closure)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
= help: to use an async block, remove the `||`: `async {`
|
||||||
|
|
||||||
|
error[E0658]: async closures are unstable
|
||||||
|
--> $DIR/edition-2015.rs:1:36
|
||||||
|
|
|
||||||
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
|
||||||
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
|
||||||
|
= help: add `#![feature(async_closure)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
= help: to use an async block, remove the `||`: `async {`
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user