handle only postfix decrement

This commit is contained in:
nx2k3 2023-02-27 16:54:38 +00:00
parent 0883973d2a
commit a4830266b0
3 changed files with 4 additions and 82 deletions

View File

@ -1354,16 +1354,6 @@ impl<'a> Parser<'a> {
};
self.recover_from_inc_dec(operand_expr, kind, op_span)
}
pub(super) fn recover_from_prefix_decrement(
&mut self,
operand_expr: P<Expr>,
op_span: Span,
start_stmt: bool,
) -> PResult<'a, P<Expr>> {
let standalone = if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr };
let kind = IncDecRecovery { standalone, op: IncOrDec::Dec, fixity: UnaryFixity::Pre };
self.recover_from_inc_dec(operand_expr, kind, op_span)
}
pub(super) fn recover_from_postfix_decrement(
&mut self,

View File

@ -561,10 +561,10 @@ impl<'a> Parser<'a> {
token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)),
// `~expr`
token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)),
// // `-expr`
// token::BinOp(token::Minus) => {
// make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg))
// }
// `-expr`
token::BinOp(token::Minus) => {
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg))
}
// `*expr`
token::BinOp(token::Star) => {
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref))
@ -606,27 +606,7 @@ impl<'a> Parser<'a> {
let operand_expr = this.parse_dot_or_call_expr(Default::default())?;
this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt)
}
// Recover from `--x`:
token::BinOp(token::Minus)
if this.look_ahead(1, |t| *t == token::BinOp(token::Minus))
&& !this.token.can_begin_expr() =>
{
let starts_stmt = this.prev_token == token::Semi
|| this.prev_token == token::CloseDelim(Delimiter::Brace);
let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span));
// if !this.token.can_begin_expr() {
// Eat both `-`s.
this.bump();
this.bump();
let operand_expr = this.parse_dot_or_call_expr(Default::default())?;
this.recover_from_prefix_decrement(operand_expr, pre_span, starts_stmt)
// }
}
// `-expr`
token::BinOp(token::Minus) => {
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg))
}
token::Ident(..) if this.token.is_keyword(kw::Box) => {
make_it!(this, attrs, |this, _| this.parse_box_expr(lo))
}

View File

@ -1,48 +0,0 @@
// run-pass
fn test1() {
let i = 0;
let c = i + --i;
println!("{c}");
}
fn test2() {
let i = 9;
let c = -- i + --i;
println!("{c}");
}
fn test3(){
let i=10;
println!("{}",i--i);
}
fn test4(){
let i=10;
println!("{}",--i);
}
struct Foo {
bar: Bar,
}
struct Bar {
qux: i32,
}
fn test5() {
let foo = Foo { bar: Bar { qux: 0 } };
let c=--foo.bar.qux;
println!("{c}");
}
fn test6(){
let x=2;
let y=--x;
println!("{y}");
}
fn main(){
test1();
test2();
test3();
test4();
test5();
test6();
}