Avoid unnecessary pattern parse errors on ref box
This commit is contained in:
parent
cb0863475f
commit
88453aaccf
@ -391,10 +391,10 @@ impl<'a> Parser<'a> {
|
|||||||
self.parse_pat_ident_mut(syntax_loc)?
|
self.parse_pat_ident_mut(syntax_loc)?
|
||||||
} else if self.eat_keyword(kw::Ref) {
|
} else if self.eat_keyword(kw::Ref) {
|
||||||
if self.check_keyword(kw::Box) {
|
if self.check_keyword(kw::Box) {
|
||||||
// Suggest `box ref` and quit parsing pattern to prevent series of
|
// Suggest `box ref`.
|
||||||
// misguided diagnostics from later stages of the compiler.
|
|
||||||
let span = self.prev_token.span.to(self.token.span);
|
let span = self.prev_token.span.to(self.token.span);
|
||||||
return Err(self.sess.create_err(SwitchRefBoxOrder { span }));
|
self.bump();
|
||||||
|
self.sess.emit_err(SwitchRefBoxOrder { span });
|
||||||
}
|
}
|
||||||
// Parse ref ident @ pat / ref mut ident @ pat
|
// Parse ref ident @ pat / ref mut ident @ pat
|
||||||
let mutbl = self.parse_mutability();
|
let mutbl = self.parse_mutability();
|
||||||
|
@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
fn foo(f: Option<Box<i32>>) {
|
fn foo(f: Option<Box<i32>>) {
|
||||||
match f {
|
match f {
|
||||||
Some(box ref, _i) => {},
|
Some(box ref _i) => {},
|
||||||
//~^ ERROR switch the order of `ref` and `box`
|
//~^ ERROR switch the order of `ref` and `box`
|
||||||
//~| ERROR expected one of `)`, `,`, or `|`, found `_i`
|
|
||||||
//~| ERROR this pattern has 2 fields, but the corresponding tuple variant has 1 field
|
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ fn foo(f: Option<Box<i32>>) {
|
|||||||
match f {
|
match f {
|
||||||
Some(ref box _i) => {},
|
Some(ref box _i) => {},
|
||||||
//~^ ERROR switch the order of `ref` and `box`
|
//~^ ERROR switch the order of `ref` and `box`
|
||||||
//~| ERROR expected one of `)`, `,`, or `|`, found `_i`
|
|
||||||
//~| ERROR this pattern has 2 fields, but the corresponding tuple variant has 1 field
|
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,23 +4,5 @@ error: switch the order of `ref` and `box`
|
|||||||
LL | Some(ref box _i) => {},
|
LL | Some(ref box _i) => {},
|
||||||
| ^^^^^^^ help: swap them: `box ref`
|
| ^^^^^^^ help: swap them: `box ref`
|
||||||
|
|
||||||
error: expected one of `)`, `,`, or `|`, found `_i`
|
error: aborting due to 1 previous error
|
||||||
--> $DIR/pattern-bad-ref-box-order.rs:8:22
|
|
||||||
|
|
|
||||||
LL | Some(ref box _i) => {},
|
|
||||||
| -^^ expected one of `)`, `,`, or `|`
|
|
||||||
| |
|
|
||||||
| help: missing `,`
|
|
||||||
|
|
||||||
error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
|
|
||||||
--> $DIR/pattern-bad-ref-box-order.rs:8:22
|
|
||||||
|
|
|
||||||
LL | Some(ref box _i) => {},
|
|
||||||
| ^^ expected 1 field, found 2
|
|
||||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
|
||||||
|
|
|
||||||
= note: tuple variant has 1 field
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0023`.
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user