mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-21 15:51:46 +00:00
Merge pull request #19251 from Veykril/push-tkmpqtzxynxk
Remove syntax editing from parenthesis computation
This commit is contained in:
commit
76567ee28d
6 changed files with 50 additions and 87 deletions
|
@ -41,6 +41,21 @@ pub enum ExprPrecedence {
|
|||
Unambiguous,
|
||||
}
|
||||
|
||||
impl ExprPrecedence {
|
||||
pub fn needs_parentheses_in(self, other: ExprPrecedence) -> bool {
|
||||
match other {
|
||||
ExprPrecedence::Unambiguous => false,
|
||||
// postfix ops have higher precedence than any other operator, so we need to wrap
|
||||
// any inner expression that is below
|
||||
ExprPrecedence::Postfix => self < ExprPrecedence::Postfix,
|
||||
// We need to wrap all binary like things, thats everything below prefix except for
|
||||
// jumps (as those are prefix operations as well)
|
||||
ExprPrecedence::Prefix => ExprPrecedence::Jump < self && self < ExprPrecedence::Prefix,
|
||||
parent => self <= parent,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Fixity {
|
||||
/// The operator is left-associative
|
||||
|
@ -137,7 +152,7 @@ impl Expr {
|
|||
// - https://github.com/rust-lang/rust/blob/b6852428a8ea9728369b64b9964cad8e258403d3/compiler/rustc_ast/src/util/parser.rs#L296
|
||||
|
||||
/// Returns `true` if `self` would need to be wrapped in parentheses given that its parent is `parent`.
|
||||
pub fn needs_parens_in(&self, parent: SyntaxNode) -> bool {
|
||||
pub fn needs_parens_in(&self, parent: &SyntaxNode) -> bool {
|
||||
match_ast! {
|
||||
match parent {
|
||||
ast::Expr(e) => self.needs_parens_in_expr(&e),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue