Skip to content

Commit 80e57e2

Browse files
committed
Reduce rightward drift
1 parent d915606 commit 80e57e2

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,41 +1255,40 @@ impl<'a> Parser<'a> {
12551255
);
12561256
err.span_label(op_span, &format!("not a valid {} operator", kind.fixity));
12571257

1258-
if let ExprKind::Path(_, path) = &base.kind {
1259-
if let [segment] = path.segments.as_slice() {
1260-
let ident = segment.ident;
1261-
// (pre, post)
1262-
let spans = match kind.fixity {
1263-
UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
1264-
UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
1265-
};
1258+
let help_base_case = |mut err: DiagnosticBuilder<'_>, base| {
1259+
err.help(&format!("use `{}= 1` instead", kind.op.chr()));
1260+
err.emit();
1261+
Ok(base)
1262+
};
12661263

1267-
if !ident.is_reserved() {
1268-
if kind.standalone {
1269-
return self.inc_dec_standalone_recovery(base, err, kind, ident, spans);
1270-
} else {
1271-
match kind.fixity {
1272-
UnaryFixity::Pre => {
1273-
return self.prefix_inc_dec_suggest_and_recover(
1274-
base, err, kind, ident, spans,
1275-
);
1276-
}
1277-
UnaryFixity::Post => {
1278-
return self.postfix_inc_dec_suggest_and_recover(
1279-
base, err, kind, ident, spans,
1280-
);
1281-
}
1282-
}
1283-
}
1264+
let ExprKind::Path(_, path) = &base.kind
1265+
else { return help_base_case(err, base) };
1266+
let [segment] = path.segments.as_slice()
1267+
else { return help_base_case(err, base) };
1268+
let ident = segment.ident;
1269+
1270+
// (pre, post)
1271+
let spans = match kind.fixity {
1272+
UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
1273+
UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
1274+
};
1275+
1276+
if ident.is_reserved() {
1277+
return help_base_case(err, base);
1278+
}
1279+
1280+
if kind.standalone {
1281+
self.inc_dec_standalone_recovery(base, err, kind, ident, spans)
1282+
} else {
1283+
match kind.fixity {
1284+
UnaryFixity::Pre => {
1285+
self.prefix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
1286+
}
1287+
UnaryFixity::Post => {
1288+
self.postfix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
12841289
}
12851290
}
12861291
}
1287-
1288-
// base case
1289-
err.help(&format!("use `{}= 1` instead", kind.op.chr()));
1290-
err.emit();
1291-
1292-
Ok(base)
12931292
}
12941293

12951294
fn prefix_inc_dec_suggest_and_recover(

0 commit comments

Comments
 (0)