Skip to content

Commit c8292c9

Browse files
Rollup merge of rust-lang#107813 - compiler-errors:bad-impl-trait-in-macro-is-ok, r=estebank
Do not eagerly recover for bad `impl Trait` types in macros Fixes rust-lang#107796 cc rust-lang#106712, `@estebank` and `@Ezrashaw` please make sure to use [`Parser::may_recover`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/parser/struct.Parser.html#method.may_recover) for all eager-token-consuming parser recoveries. This also fixes a separate regression from rust-lang#99915, that was introduced before we added `may_recover` though.
2 parents dae598a + 0017822 commit c8292c9

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

compiler/rustc_parse/src/parser/ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,9 @@ impl<'a> Parser<'a> {
694694
// `where`, so stop if it's it.
695695
// We also continue if we find types (not traits), again for error recovery.
696696
while self.can_begin_bound()
697-
|| self.token.can_begin_type()
698-
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
697+
|| (self.may_recover()
698+
&& (self.token.can_begin_type()
699+
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))))
699700
{
700701
if self.token.is_keyword(kw::Dyn) {
701702
// Account for `&dyn Trait + dyn Other`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
// edition:2021
4+
// for the `impl` + keyword test
5+
6+
macro_rules! impl_primitive {
7+
($ty:ty) => {
8+
compile_error!("whoops");
9+
};
10+
(impl async) => {};
11+
}
12+
13+
impl_primitive!(impl async);
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
macro_rules! impl_primitive {
4+
($ty:ty) => { impl_primitive!(impl $ty); };
5+
(impl $ty:ty) => { fn a(_: $ty) {} }
6+
}
7+
8+
impl_primitive! { u8 }
9+
10+
macro_rules! test {
11+
($ty:ty) => { compile_error!("oh no"); };
12+
(impl &) => {};
13+
}
14+
15+
test!(impl &);
16+
17+
fn main() {}

0 commit comments

Comments
 (0)