1
Fork 0

Reduce rightward drift

This commit is contained in:
Noah Lev 2022-02-15 20:05:24 -08:00
parent d915606d50
commit 80e57e223e

View file

@ -1255,42 +1255,41 @@ impl<'a> Parser<'a> {
); );
err.span_label(op_span, &format!("not a valid {} operator", kind.fixity)); err.span_label(op_span, &format!("not a valid {} operator", kind.fixity));
if let ExprKind::Path(_, path) = &base.kind { let help_base_case = |mut err: DiagnosticBuilder<'_>, base| {
if let [segment] = path.segments.as_slice() { err.help(&format!("use `{}= 1` instead", kind.op.chr()));
err.emit();
Ok(base)
};
let ExprKind::Path(_, path) = &base.kind
else { return help_base_case(err, base) };
let [segment] = path.segments.as_slice()
else { return help_base_case(err, base) };
let ident = segment.ident; let ident = segment.ident;
// (pre, post) // (pre, post)
let spans = match kind.fixity { let spans = match kind.fixity {
UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()), UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span), UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
}; };
if !ident.is_reserved() { if ident.is_reserved() {
return help_base_case(err, base);
}
if kind.standalone { if kind.standalone {
return self.inc_dec_standalone_recovery(base, err, kind, ident, spans); self.inc_dec_standalone_recovery(base, err, kind, ident, spans)
} else { } else {
match kind.fixity { match kind.fixity {
UnaryFixity::Pre => { UnaryFixity::Pre => {
return self.prefix_inc_dec_suggest_and_recover( self.prefix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
base, err, kind, ident, spans,
);
} }
UnaryFixity::Post => { UnaryFixity::Post => {
return self.postfix_inc_dec_suggest_and_recover( self.postfix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
base, err, kind, ident, spans,
);
} }
} }
} }
} }
}
}
// base case
err.help(&format!("use `{}= 1` instead", kind.op.chr()));
err.emit();
Ok(base)
}
fn prefix_inc_dec_suggest_and_recover( fn prefix_inc_dec_suggest_and_recover(
&mut self, &mut self,