diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-08 17:56:04 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-02-08 17:56:08 +0000 |
| commit | 0017822b708d2dde46fa603592d322951dc7ba0a (patch) | |
| tree | b0a162296095fe129cf1f9ee59797805a0c68a9f | |
| parent | bd39bbb4bb92df439bf6d85470e296cc6a47ffbd (diff) | |
| download | rust-0017822b708d2dde46fa603592d322951dc7ba0a.tar.gz rust-0017822b708d2dde46fa603592d322951dc7ba0a.zip | |
Do not eagerly recover for bad impl-trait in macros
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 5 | ||||
| -rw-r--r-- | tests/ui/parser/bad-recover-kw-after-impl.rs | 15 | ||||
| -rw-r--r-- | tests/ui/parser/bad-recover-ty-after-impl.rs | 17 |
3 files changed, 35 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index a19ea04fa5e..5b92563fc35 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -694,8 +694,9 @@ impl<'a> Parser<'a> { // `where`, so stop if it's it. // We also continue if we find types (not traits), again for error recovery. while self.can_begin_bound() - || self.token.can_begin_type() - || (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where)) + || (self.may_recover() + && (self.token.can_begin_type() + || (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where)))) { if self.token.is_keyword(kw::Dyn) { // Account for `&dyn Trait + dyn Other`. diff --git a/tests/ui/parser/bad-recover-kw-after-impl.rs b/tests/ui/parser/bad-recover-kw-after-impl.rs new file mode 100644 index 00000000000..218cd767859 --- /dev/null +++ b/tests/ui/parser/bad-recover-kw-after-impl.rs @@ -0,0 +1,15 @@ +// check-pass + +// edition:2021 +// for the `impl` + keyword test + +macro_rules! impl_primitive { + ($ty:ty) => { + compile_error!("whoops"); + }; + (impl async) => {}; +} + +impl_primitive!(impl async); + +fn main() {} diff --git a/tests/ui/parser/bad-recover-ty-after-impl.rs b/tests/ui/parser/bad-recover-ty-after-impl.rs new file mode 100644 index 00000000000..510e08ba091 --- /dev/null +++ b/tests/ui/parser/bad-recover-ty-after-impl.rs @@ -0,0 +1,17 @@ +// check-pass + +macro_rules! impl_primitive { + ($ty:ty) => { impl_primitive!(impl $ty); }; + (impl $ty:ty) => { fn a(_: $ty) {} } +} + +impl_primitive! { u8 } + +macro_rules! test { + ($ty:ty) => { compile_error!("oh no"); }; + (impl &) => {}; +} + +test!(impl &); + +fn main() {} |
