Skip to content

Commit 9c6bbf1

Browse files
committed
extract error_unexpected_after_dot and de-fatalize
1 parent ff5762b commit 9c6bbf1

File tree

7 files changed

+40
-27
lines changed

7 files changed

+40
-27
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,7 @@ impl<'a> Parser<'a> {
715715
err?
716716
}
717717
}
718-
_ => {
719-
// FIXME Could factor this out into non_fatal_unexpected or something.
720-
let actual = self.this_token_to_string();
721-
self.span_err(self.token.span, &format!("unexpected token: `{}`", actual));
722-
}
718+
_ => self.error_unexpected_after_dot(),
723719
}
724720
continue;
725721
}
@@ -735,6 +731,12 @@ impl<'a> Parser<'a> {
735731
return Ok(e);
736732
}
737733

734+
fn error_unexpected_after_dot(&self) {
735+
// FIXME Could factor this out into non_fatal_unexpected or something.
736+
let actual = self.this_token_to_string();
737+
self.struct_span_err(self.token.span, &format!("unexpected token: `{}`", actual)).emit();
738+
}
739+
738740
fn recover_field_access_by_float_lit(
739741
&mut self,
740742
lo: Span,

src/test/ui/parser/attr-stmt-expr-attr-bad-2.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/test/ui/parser/attr-stmt-expr-attr-bad-2.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/parser/attr-stmt-expr-attr-bad-3.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/test/ui/parser/attr-stmt-expr-attr-bad-3.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/parser/attr-stmt-expr-attr-bad.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ fn main() {}
101101
//~^ ERROR `X..=` range patterns are not supported
102102
//~| ERROR expected one of `=>`, `if`, or `|`, found `#`
103103

104+
#[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
105+
//~^ ERROR unexpected token: `#`
106+
//~| ERROR expected one of `.`
107+
#[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
108+
//~^ ERROR unexpected token: `#`
109+
//~| ERROR expected one of `.`
110+
104111
// make sure we don't catch this bug again...
105112
#[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } }
106113
//~^ ERROR expected statement after outer attribute

src/test/ui/parser/attr-stmt-expr-attr-bad.stderr

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,35 @@ error: expected one of `=>`, `if`, or `|`, found `#`
380380
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
381381
| ^ expected one of `=>`, `if`, or `|`
382382

383+
error: unexpected token: `#`
384+
--> $DIR/attr-stmt-expr-attr-bad.rs:104:34
385+
|
386+
LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
387+
| ^
388+
389+
error: expected one of `.`, `;`, `?`, or an operator, found `#`
390+
--> $DIR/attr-stmt-expr-attr-bad.rs:104:34
391+
|
392+
LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
393+
| ^ expected one of `.`, `;`, `?`, or an operator
394+
395+
error: unexpected token: `#`
396+
--> $DIR/attr-stmt-expr-attr-bad.rs:106:34
397+
|
398+
LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
399+
| ^
400+
401+
error: expected one of `.`, `;`, `?`, or an operator, found `#`
402+
--> $DIR/attr-stmt-expr-attr-bad.rs:106:34
403+
|
404+
LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
405+
| ^ expected one of `.`, `;`, `?`, or an operator
406+
383407
error: expected statement after outer attribute
384-
--> $DIR/attr-stmt-expr-attr-bad.rs:105:44
408+
--> $DIR/attr-stmt-expr-attr-bad.rs:110:44
385409
|
386410
LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } }
387411
| ^
388412

389-
error: aborting due to 52 previous errors
413+
error: aborting due to 56 previous errors
390414

0 commit comments

Comments
 (0)