mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
parser: let
stmts & for
exprs: allow or-patterns.
This commit is contained in:
parent
92d66a1317
commit
95792b4d5a
@ -1284,7 +1284,7 @@ impl<'a> Parser<'a> {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let pat = self.parse_top_level_pat()?;
|
||||
let pat = self.parse_top_pat(true)?;
|
||||
if !self.eat_keyword(kw::In) {
|
||||
let in_span = self.prev_span.between(self.token.span);
|
||||
self.struct_span_err(in_span, "missing `in` in `for` loop")
|
||||
|
@ -45,12 +45,6 @@ impl<'a> Parser<'a> {
|
||||
self.parse_pat_with_or(None, gate_or, true)
|
||||
}
|
||||
|
||||
pub(super) fn parse_top_level_pat(&mut self) -> PResult<'a, P<Pat>> {
|
||||
let pat = self.parse_pat(None)?;
|
||||
self.maybe_recover_unexpected_comma(pat.span, true)?;
|
||||
Ok(pat)
|
||||
}
|
||||
|
||||
/// Parses a pattern, that may be a or-pattern (e.g. `Foo | Bar` in `Some(Foo | Bar)`).
|
||||
/// Corresponds to `pat<allow_top_alt>` in RFC 2535.
|
||||
fn parse_pat_with_or(
|
||||
|
@ -207,7 +207,7 @@ impl<'a> Parser<'a> {
|
||||
/// Parses a local variable declaration.
|
||||
fn parse_local(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Local>> {
|
||||
let lo = self.prev_span;
|
||||
let pat = self.parse_top_level_pat()?;
|
||||
let pat = self.parse_top_pat(true)?;
|
||||
|
||||
let (err, ty) = if self.eat(&token::Colon) {
|
||||
// Save the state of the parser before parsing type normally, in case there is a `:`
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
let isize x = 5; //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `x`
|
||||
let isize x = 5; //~ ERROR expected one of `:`, `;`, `=`, `@`, or `|`, found `x`
|
||||
match x;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `x`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `x`
|
||||
--> $DIR/bad-match.rs:2:13
|
||||
|
|
||||
LL | let isize x = 5;
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `.`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/bad-name.rs:4:8
|
||||
|
|
||||
LL | let x.y::<isize>.z foo;
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
let caller<F> = |f: F| //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `<`
|
||||
let caller<F> = |f: F| //~ ERROR expected one of `:`, `;`, `=`, `@`, or `|`, found `<`
|
||||
where F: Fn() -> i32
|
||||
{
|
||||
let x = f();
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `<`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `<`
|
||||
--> $DIR/issue-22647.rs:2:15
|
||||
|
|
||||
LL | let caller<F> = |f: F|
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -3,7 +3,7 @@ struct Foo<B> {
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
let Foo<Vec<u8>> //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `<`
|
||||
let Foo<Vec<u8>> //~ ERROR expected one of `:`, `;`, `=`, `@`, or `|`, found `<`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `<`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `<`
|
||||
--> $DIR/issue-22712.rs:6:12
|
||||
|
|
||||
LL | let Foo<Vec<u8>>
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
let buf[0] = 0; //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `[`
|
||||
let buf[0] = 0; //~ ERROR expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `[`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
--> $DIR/issue-24197.rs:2:12
|
||||
|
|
||||
LL | let buf[0] = 0;
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,5 +2,6 @@
|
||||
|
||||
pub fn main() {
|
||||
struct Foo { x: isize }
|
||||
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected one of `:`, `;`, `=`, or `@`, found `{`
|
||||
let mut Foo { x: x } = Foo { x: 3 };
|
||||
//~^ ERROR: expected one of `:`, `;`, `=`, `@`, or `|`, found `{`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `{`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `{`
|
||||
--> $DIR/mut-patterns.rs:5:17
|
||||
|
|
||||
LL | let mut Foo { x: x } = Foo { x: 3 };
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
let v[0] = v[1]; //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `[`
|
||||
let v[0] = v[1]; //~ ERROR expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, `=`, or `@`, found `[`
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
--> $DIR/pat-lt-bracket-5.rs:2:10
|
||||
|
|
||||
LL | let v[0] = v[1];
|
||||
| ^ expected one of `:`, `;`, `=`, or `@` here
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Parsing of range patterns
|
||||
|
||||
fn main() {
|
||||
let macropus!() ..= 11 = 12; //~ error: expected one of `:`, `;`, or `=`, found `..=`
|
||||
let macropus!() ..= 11 = 12; //~ error: expected one of `:`, `;`, `=`, or `|`, found `..=`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, or `=`, found `..=`
|
||||
error: expected one of `:`, `;`, `=`, or `|`, found `..=`
|
||||
--> $DIR/pat-ranges-1.rs:4:21
|
||||
|
|
||||
LL | let macropus!() ..= 11 = 12;
|
||||
| ^^^ expected one of `:`, `;`, or `=` here
|
||||
| ^^^ expected one of `:`, `;`, `=`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Parsing of range patterns
|
||||
|
||||
fn main() {
|
||||
let 10 ..= makropulos!() = 12; //~ error: expected one of `::`, `:`, `;`, or `=`, found `!`
|
||||
let 10 ..= makropulos!() = 12; //~ error: expected one of `::`, `:`, `;`, `=`, or `|`, found `!`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `::`, `:`, `;`, or `=`, found `!`
|
||||
error: expected one of `::`, `:`, `;`, `=`, or `|`, found `!`
|
||||
--> $DIR/pat-ranges-2.rs:4:26
|
||||
|
|
||||
LL | let 10 ..= makropulos!() = 12;
|
||||
| ^ expected one of `::`, `:`, `;`, or `=` here
|
||||
| ^ expected one of `::`, `:`, `;`, `=`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Parsing of range patterns
|
||||
|
||||
fn main() {
|
||||
let 10 ..= 10 + 3 = 12; //~ expected one of `:`, `;`, or `=`, found `+`
|
||||
let 10 ..= 10 + 3 = 12; //~ expected one of `:`, `;`, `=`, or `|`, found `+`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `:`, `;`, or `=`, found `+`
|
||||
error: expected one of `:`, `;`, `=`, or `|`, found `+`
|
||||
--> $DIR/pat-ranges-3.rs:4:19
|
||||
|
|
||||
LL | let 10 ..= 10 + 3 = 12;
|
||||
| ^ expected one of `:`, `;`, or `=` here
|
||||
| ^ expected one of `:`, `;`, `=`, or `|` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,5 +2,5 @@
|
||||
|
||||
fn main() {
|
||||
let 10 - 3 ..= 10 = 8;
|
||||
//~^ error: expected one of `...`, `..=`, `..`, `:`, `;`, or `=`, found `-`
|
||||
//~^ error: expected one of `...`, `..=`, `..`, `:`, `;`, `=`, or `|`, found `-`
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected one of `...`, `..=`, `..`, `:`, `;`, or `=`, found `-`
|
||||
error: expected one of `...`, `..=`, `..`, `:`, `;`, `=`, or `|`, found `-`
|
||||
--> $DIR/pat-ranges-4.rs:4:12
|
||||
|
|
||||
LL | let 10 - 3 ..= 10 = 8;
|
||||
| ^ expected one of `...`, `..=`, `..`, `:`, `;`, or `=` here
|
||||
| ^ expected one of 7 possible tokens here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user