Do not eagerly recover for bad impl-trait in macros

This commit is contained in:
Michael Goulet
2023-02-08 17:56:04 +00:00
committed by Mark Rousskov
parent a6d8057f09
commit 792a9a2eb3
3 changed files with 35 additions and 2 deletions
+3 -2
View File
@@ -733,8 +733,9 @@ fn parse_generic_bounds_common(
// `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`.
@@ -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() {}
@@ -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() {}