Skip to content

Commit 2e812c1

Browse files
committed
parser::pat: remove .fatal calls
1 parent 6fba125 commit 2e812c1

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/librustc_parse/parser/pat.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl<'a> Parser<'a> {
673673
let expected = expected.unwrap_or("pattern");
674674
let msg = format!("expected {}, found {}", expected, super::token_descr(&self.token));
675675

676-
let mut err = self.fatal(&msg);
676+
let mut err = self.struct_span_err(self.token.span, &msg);
677677
err.span_label(self.token.span, format!("expected {}", expected));
678678

679679
let sp = self.sess.source_map().start_point(self.token.span);
@@ -807,12 +807,8 @@ impl<'a> Parser<'a> {
807807
/// Parse a struct ("record") pattern (e.g. `Foo { ... }` or `Foo::Bar { ... }`).
808808
fn parse_pat_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> {
809809
if qself.is_some() {
810-
let msg = "unexpected `{` after qualified path";
811-
let mut err = self.fatal(msg);
812-
err.span_label(self.token.span, msg);
813-
return Err(err);
810+
return self.error_qpath_before_pat(&path, "{");
814811
}
815-
816812
self.bump();
817813
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
818814
e.emit();
@@ -826,15 +822,22 @@ impl<'a> Parser<'a> {
826822
/// Parse tuple struct or tuple variant pattern (e.g. `Foo(...)` or `Foo::Bar(...)`).
827823
fn parse_pat_tuple_struct(&mut self, qself: Option<QSelf>, path: Path) -> PResult<'a, PatKind> {
828824
if qself.is_some() {
829-
let msg = "unexpected `(` after qualified path";
830-
let mut err = self.fatal(msg);
831-
err.span_label(self.token.span, msg);
832-
return Err(err);
825+
return self.error_qpath_before_pat(&path, "(");
833826
}
834827
let (fields, _) = self.parse_paren_comma_seq(|p| p.parse_pat_with_or_inner())?;
835828
Ok(PatKind::TupleStruct(path, fields))
836829
}
837830

831+
/// Error when there's a qualified path, e.g. `<Foo as Bar>::Baz`
832+
/// as the path of e.g., a tuple or record struct pattern.
833+
fn error_qpath_before_pat(&mut self, path: &Path, token: &str) -> PResult<'a, PatKind> {
834+
let msg = &format!("unexpected `{}` after qualified path", token);
835+
let mut err = self.struct_span_err(self.token.span, msg);
836+
err.span_label(self.token.span, msg);
837+
err.span_label(path.span, "the qualified path");
838+
Err(err)
839+
}
840+
838841
/// Parses the fields of a struct-like pattern.
839842
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> {
840843
let mut fields = Vec::new();
@@ -877,7 +880,8 @@ impl<'a> Parser<'a> {
877880
break;
878881
}
879882
let token_str = super::token_descr(&self.token);
880-
let mut err = self.fatal(&format!("expected `}}`, found {}", token_str));
883+
let msg = &format!("expected `}}`, found {}", token_str);
884+
let mut err = self.struct_span_err(self.token.span, msg);
881885

882886
err.span_label(self.token.span, "expected `}`");
883887
let mut comma_sp = None;

src/test/ui/parser/brace-after-qualified-path-in-match.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: unexpected `{` after qualified path
22
--> $DIR/brace-after-qualified-path-in-match.rs:3:27
33
|
44
LL | <T as Trait>::Type{key: value} => (),
5-
| ^ unexpected `{` after qualified path
5+
| ------------------^ unexpected `{` after qualified path
6+
| |
7+
| the qualified path
68

79
error: aborting due to previous error
810

src/test/ui/parser/paren-after-qualified-path-in-match.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: unexpected `(` after qualified path
22
--> $DIR/paren-after-qualified-path-in-match.rs:3:27
33
|
44
LL | <T as Trait>::Type(2) => (),
5-
| ^ unexpected `(` after qualified path
5+
| ------------------^ unexpected `(` after qualified path
6+
| |
7+
| the qualified path
68

79
error: aborting due to previous error
810

src/test/ui/suggestions/vec-macro-in-pattern.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ LL | Some(vec![_x]) => (),
55
| ^^^^^^^^
66
| |
77
| unexpected `(` after qualified path
8+
| the qualified path
89
| in this macro invocation
910
| help: use a slice pattern here instead: `[_x]`
1011
|
1112
= help: for more information, see https://doc.rust-lang.org/edition-guide/rust-2018/slice-patterns.html
12-
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
13+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1314

1415
error: aborting due to previous error
1516

0 commit comments

Comments
 (0)