Skip to content

Commit 0017822

Browse files
Do not eagerly recover for bad impl-trait in macros
1 parent bd39bbb commit 0017822

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)