parser::pat: remove .fatal calls

This commit is contained in:
Mazdak Farrokhzad 2019-12-31 03:36:45 +01:00
parent 6fba125912
commit 2e812c1c5f
4 changed files with 23 additions and 14 deletions

View File

@ -673,7 +673,7 @@ impl<'a> Parser<'a> {
let expected = expected.unwrap_or("pattern"); let expected = expected.unwrap_or("pattern");
let msg = format!("expected {}, found {}", expected, super::token_descr(&self.token)); let msg = format!("expected {}, found {}", expected, super::token_descr(&self.token));
let mut err = self.fatal(&msg); let mut err = self.struct_span_err(self.token.span, &msg);
err.span_label(self.token.span, format!("expected {}", expected)); err.span_label(self.token.span, format!("expected {}", expected));
let sp = self.sess.source_map().start_point(self.token.span); let sp = self.sess.source_map().start_point(self.token.span);
@ -807,12 +807,8 @@ impl<'a> Parser<'a> {
/// Parse a struct ("record") pattern (e.g. `Foo { ... }` or `Foo::Bar { ... }`). /// Parse a struct ("record") pattern (e.g. `Foo { ... }` or `Foo::Bar { ... }`).
fn parse_pat_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> { fn parse_pat_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> {
if qself.is_some() { if qself.is_some() {
let msg = "unexpected `{` after qualified path"; return self.error_qpath_before_pat(&path, "{");
let mut err = self.fatal(msg);
err.span_label(self.token.span, msg);
return Err(err);
} }
self.bump(); self.bump();
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| { let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
e.emit(); e.emit();
@ -826,15 +822,22 @@ impl<'a> Parser<'a> {
/// Parse tuple struct or tuple variant pattern (e.g. `Foo(...)` or `Foo::Bar(...)`). /// Parse tuple struct or tuple variant pattern (e.g. `Foo(...)` or `Foo::Bar(...)`).
fn parse_pat_tuple_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> { fn parse_pat_tuple_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> {
if qself.is_some() { if qself.is_some() {
let msg = "unexpected `(` after qualified path"; return self.error_qpath_before_pat(&path, "(");
let mut err = self.fatal(msg);
err.span_label(self.token.span, msg);
return Err(err);
} }
let (fields, _) = self.parse_paren_comma_seq(|p| p.parse_pat_with_or_inner())?; let (fields, _) = self.parse_paren_comma_seq(|p| p.parse_pat_with_or_inner())?;
Ok(PatKind::TupleStruct(path, fields)) Ok(PatKind::TupleStruct(path, fields))
} }
/// Error when there's a qualified path, e.g. `<Foo as Bar>::Baz`
/// as the path of e.g., a tuple or record struct pattern.
fn error_qpath_before_pat(&mut self, path: &Path, token: &str) -> PResult<'a, PatKind> {
let msg = &format!("unexpected `{}` after qualified path", token);
let mut err = self.struct_span_err(self.token.span, msg);
err.span_label(self.token.span, msg);
err.span_label(path.span, "the qualified path");
Err(err)
}
/// Parses the fields of a struct-like pattern. /// Parses the fields of a struct-like pattern.
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> { fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> {
let mut fields = Vec::new(); let mut fields = Vec::new();
@ -877,7 +880,8 @@ impl<'a> Parser<'a> {
break; break;
} }
let token_str = super::token_descr(&self.token); let token_str = super::token_descr(&self.token);
let mut err = self.fatal(&format!("expected `}}`, found {}", token_str)); let msg = &format!("expected `}}`, found {}", token_str);
let mut err = self.struct_span_err(self.token.span, msg);
err.span_label(self.token.span, "expected `}`"); err.span_label(self.token.span, "expected `}`");
let mut comma_sp = None; let mut comma_sp = None;

View File

@ -2,7 +2,9 @@ error: unexpected `{` after qualified path
--> $DIR/brace-after-qualified-path-in-match.rs:3:27 --> $DIR/brace-after-qualified-path-in-match.rs:3:27
| |
LL | <T as Trait>::Type{key: value} => (), LL | <T as Trait>::Type{key: value} => (),
| ^ unexpected `{` after qualified path | ------------------^ unexpected `{` after qualified path
| |
| the qualified path
error: aborting due to previous error error: aborting due to previous error

View File

@ -2,7 +2,9 @@ error: unexpected `(` after qualified path
--> $DIR/paren-after-qualified-path-in-match.rs:3:27 --> $DIR/paren-after-qualified-path-in-match.rs:3:27
| |
LL | <T as Trait>::Type(2) => (), LL | <T as Trait>::Type(2) => (),
| ^ unexpected `(` after qualified path | ------------------^ unexpected `(` after qualified path
| |
| the qualified path
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,11 +5,12 @@ LL | Some(vec![_x]) => (),
| ^^^^^^^^ | ^^^^^^^^
| | | |
| unexpected `(` after qualified path | unexpected `(` after qualified path
| the qualified path
| in this macro invocation | in this macro invocation
| help: use a slice pattern here instead: `[_x]` | help: use a slice pattern here instead: `[_x]`
| |
= help: for more information, see https://doc.rust-lang.org/edition-guide/rust-2018/slice-patterns.html = help: for more information, see https://doc.rust-lang.org/edition-guide/rust-2018/slice-patterns.html
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error error: aborting due to previous error