diff options
| author | Yiming Lei <yiming.lei@futurewei.com> | 2022-11-30 12:01:00 -0800 |
|---|---|---|
| committer | Yiming Lei <yiming.lei@futurewei.com> | 2022-12-01 22:48:52 -0800 |
| commit | 0e19fb92e1eb7f91aa5570b2ac782c9a42a6e329 (patch) | |
| tree | a6e9ba82c5cf00782bba66ac2677e052ff9747c5 /compiler/rustc_parse/src | |
| parent | 90711a86e5bdd4b0b65d293f0c2c48fd2db761b3 (diff) | |
| download | rust-0e19fb92e1eb7f91aa5570b2ac782c9a42a6e329.tar.gz rust-0e19fb92e1eb7f91aa5570b2ac782c9a42a6e329.zip | |
While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case #103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix #103869
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 767fb9378be..7ce89b5c359 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1414,7 +1414,10 @@ impl<'a> Parser<'a> { Ok((Some(vr), TrailingToken::MaybeComma)) }, - ) + ).map_err(|mut err|{ + err.help("enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`"); + err + }) } /// Parses `struct Foo { ... }`. diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 4d8bff28b05..bebb012660a 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -943,6 +943,10 @@ impl<'a> Parser<'a> { Err(e) => { // Parsing failed, therefore it must be something more serious // than just a missing separator. + for xx in &e.children { + // propagate the help message from sub error 'e' to main error 'expect_err; + expect_err.children.push(xx.clone()); + } expect_err.emit(); e.cancel(); |
