Suggest wrapping mac args in parens rather than the whole expression
This commit is contained in:
parent
c1c7707238
commit
ec263df5e4
5 changed files with 45 additions and 23 deletions
|
@ -1844,7 +1844,7 @@ impl<'a> Parser<'a> {
|
|||
let lexpr = self.parse_expr_labeled(label, true)?;
|
||||
self.dcx().emit_err(errors::LabeledLoopInBreak {
|
||||
span: lexpr.span,
|
||||
sub: errors::WrapExpressionInParentheses {
|
||||
sub: errors::WrapInParentheses::Expression {
|
||||
left: lexpr.span.shrink_to_lo(),
|
||||
right: lexpr.span.shrink_to_hi(),
|
||||
},
|
||||
|
|
|
@ -389,7 +389,7 @@ impl<'a> Parser<'a> {
|
|||
self.dcx().emit_err(errors::InvalidExpressionInLetElse {
|
||||
span: init.span,
|
||||
operator: op.node.as_str(),
|
||||
sugg: errors::WrapExpressionInParentheses {
|
||||
sugg: errors::WrapInParentheses::Expression {
|
||||
left: init.span.shrink_to_lo(),
|
||||
right: init.span.shrink_to_hi(),
|
||||
},
|
||||
|
@ -400,12 +400,19 @@ impl<'a> Parser<'a> {
|
|||
|
||||
fn check_let_else_init_trailing_brace(&self, init: &ast::Expr) {
|
||||
if let Some(trailing) = classify::expr_trailing_brace(init) {
|
||||
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
|
||||
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
|
||||
sugg: errors::WrapExpressionInParentheses {
|
||||
let sugg = match &trailing.kind {
|
||||
ExprKind::MacCall(mac) => errors::WrapInParentheses::MacroArgs {
|
||||
left: mac.args.dspan.open,
|
||||
right: mac.args.dspan.close,
|
||||
},
|
||||
_ => errors::WrapInParentheses::Expression {
|
||||
left: trailing.span.shrink_to_lo(),
|
||||
right: trailing.span.shrink_to_hi(),
|
||||
},
|
||||
};
|
||||
self.dcx().emit_err(errors::InvalidCurlyInLetElse {
|
||||
span: trailing.span.with_lo(trailing.span.hi() - BytePos(1)),
|
||||
sugg,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue