Skip to content

Commit

Permalink
Fix parser ICE when recovering dyn/impl after for<...>
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Dec 4, 2023
1 parent c9808f8 commit bf51067
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
17 changes: 15 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,23 @@ impl<'a> Parser<'a> {
kw: kw.as_str(),
},
});
let path = self.parse_path(PathStyle::Type)?;
let path = match self.parse_path(PathStyle::Type) {
Ok(path) => path,
Err(perr) => {
err.cancel();
return Err(perr);
}
};
let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus();
let kind =
self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)?;
match self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)
{
Ok(kind) => kind,
Err(perr) => {
err.cancel();
return Err(perr);
}
};
// Take the parsed bare trait object and turn it either
// into a `dyn` object or an `impl Trait`.
let kind = match (kind, kw) {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/parser/recover-hrtb-before-dyn-impl-kw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ fn test(_: &for<'a> dyn Trait) {}
fn test2(_: for<'a> impl Trait) {}
//~^ ERROR `for<...>` expected after `impl`, not before

// Issue #118564
type A2 = dyn<for<> dyn>;
//~^ ERROR expected identifier, found `>`

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/parser/recover-hrtb-before-dyn-impl-kw.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ LL - fn test2(_: for<'a> impl Trait) {}
LL + fn test2(_: impl for<'a> Trait) {}
|

error: aborting due to 2 previous errors
error: expected identifier, found `>`
--> $DIR/recover-hrtb-before-dyn-impl-kw.rs:10:24
|
LL | type A2 = dyn<for<> dyn>;
| ^ expected identifier

error: aborting due to 3 previous errors

0 comments on commit bf51067

Please sign in to comment.