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,41 +1255,40 @@ 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()));
let ident = segment.ident; err.emit();
// (pre, post) Ok(base)
let spans = match kind.fixity { };
UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
};
if !ident.is_reserved() { let ExprKind::Path(_, path) = &base.kind
if kind.standalone { else { return help_base_case(err, base) };
return self.inc_dec_standalone_recovery(base, err, kind, ident, spans); let [segment] = path.segments.as_slice()
} else { else { return help_base_case(err, base) };
match kind.fixity { let ident = segment.ident;
UnaryFixity::Pre => {
return self.prefix_inc_dec_suggest_and_recover( // (pre, post)
base, err, kind, ident, spans, let spans = match kind.fixity {
); UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
} UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
UnaryFixity::Post => { };
return self.postfix_inc_dec_suggest_and_recover(
base, err, kind, ident, spans, if ident.is_reserved() {
); return help_base_case(err, base);
} }
}
} if kind.standalone {
self.inc_dec_standalone_recovery(base, err, kind, ident, spans)
} else {
match kind.fixity {
UnaryFixity::Pre => {
self.prefix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
}
UnaryFixity::Post => {
self.postfix_inc_dec_suggest_and_recover(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(