Skip to content

Commit

Permalink
Do not eagerly recover for bad impl-trait in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 8, 2023
1 parent bd39bbb commit 0017822
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/parser/bad-recover-kw-after-impl.rs
Original file line number Diff line number Diff line change
@@ -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() {}
17 changes: 17 additions & 0 deletions tests/ui/parser/bad-recover-ty-after-impl.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 0017822

Please sign in to comment.