Inline ExprPrecedence::order into Expr::precedence
This commit is contained in:
parent
23e7ecb349
commit
e5f1555000
16 changed files with 146 additions and 225 deletions
|
@ -1,11 +1,12 @@
|
|||
use rustc_ast::mut_visit::{self, MutVisitor};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, BinOpToken, Delimiter, IdentIsRaw, Token};
|
||||
use rustc_ast::util::parser::AssocOp;
|
||||
use rustc_ast::visit::{self, Visitor};
|
||||
use rustc_ast::{
|
||||
self as ast, Arm, AttrVec, BinOpKind, BindingMode, ByRef, Expr, ExprKind, ExprPrecedence,
|
||||
LocalKind, MacCall, Mutability, Pat, PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd,
|
||||
RangeSyntax, Stmt, StmtKind,
|
||||
self as ast, Arm, AttrVec, BinOpKind, BindingMode, ByRef, Expr, ExprKind, LocalKind, MacCall,
|
||||
Mutability, Pat, PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, Stmt,
|
||||
StmtKind,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{Applicability, Diag, DiagArgValue, PResult, StashKey};
|
||||
|
@ -458,7 +459,7 @@ impl<'a> Parser<'a> {
|
|||
.create_err(UnexpectedExpressionInPattern {
|
||||
span,
|
||||
is_bound,
|
||||
expr_precedence: expr.precedence().order(),
|
||||
expr_precedence: expr.precedence(),
|
||||
})
|
||||
.stash(span, StashKey::ExprInPat)
|
||||
.unwrap(),
|
||||
|
@ -545,7 +546,8 @@ impl<'a> Parser<'a> {
|
|||
let expr = match &err.args["expr_precedence"] {
|
||||
DiagArgValue::Number(expr_precedence) => {
|
||||
if *expr_precedence
|
||||
<= ExprPrecedence::Binary(BinOpKind::Eq).order() as i32
|
||||
<= AssocOp::from_ast_binop(BinOpKind::Eq).precedence()
|
||||
as i32
|
||||
{
|
||||
format!("({expr})")
|
||||
} else {
|
||||
|
@ -568,8 +570,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
Some(guard) => {
|
||||
// Are parentheses required around the old guard?
|
||||
let wrap_guard = guard.precedence().order()
|
||||
<= ExprPrecedence::Binary(BinOpKind::And).order();
|
||||
let wrap_guard = guard.precedence()
|
||||
<= AssocOp::from_ast_binop(BinOpKind::And).precedence()
|
||||
as i8;
|
||||
|
||||
err.subdiagnostic(
|
||||
UnexpectedExpressionInPatternSugg::UpdateGuard {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue