Skip to content

Commit bf51067

Browse files
committedDec 4, 2023
Fix parser ICE when recovering dyn/impl after for<...>
1 parent c9808f8 commit bf51067

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
 

Diff for: ‎compiler/rustc_parse/src/parser/ty.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,23 @@ impl<'a> Parser<'a> {
314314
kw: kw.as_str(),
315315
},
316316
});
317-
let path = self.parse_path(PathStyle::Type)?;
317+
let path = match self.parse_path(PathStyle::Type) {
318+
Ok(path) => path,
319+
Err(perr) => {
320+
err.cancel();
321+
return Err(perr);
322+
}
323+
};
318324
let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus();
319325
let kind =
320-
self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)?;
326+
match self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)
327+
{
328+
Ok(kind) => kind,
329+
Err(perr) => {
330+
err.cancel();
331+
return Err(perr);
332+
}
333+
};
321334
// Take the parsed bare trait object and turn it either
322335
// into a `dyn` object or an `impl Trait`.
323336
let kind = match (kind, kw) {

Diff for: ‎tests/ui/parser/recover-hrtb-before-dyn-impl-kw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ fn test(_: &for<'a> dyn Trait) {}
66
fn test2(_: for<'a> impl Trait) {}
77
//~^ ERROR `for<...>` expected after `impl`, not before
88

9+
// Issue #118564
10+
type A2 = dyn<for<> dyn>;
11+
//~^ ERROR expected identifier, found `>`
12+
913
fn main() {}

Diff for: ‎tests/ui/parser/recover-hrtb-before-dyn-impl-kw.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ LL - fn test2(_: for<'a> impl Trait) {}
2222
LL + fn test2(_: impl for<'a> Trait) {}
2323
|
2424

25-
error: aborting due to 2 previous errors
25+
error: expected identifier, found `>`
26+
--> $DIR/recover-hrtb-before-dyn-impl-kw.rs:10:24
27+
|
28+
LL | type A2 = dyn<for<> dyn>;
29+
| ^ expected identifier
30+
31+
error: aborting due to 3 previous errors
2632

0 commit comments

Comments
 (0)