parent
e217f94917
commit
831f4549cd
12 changed files with 544 additions and 64 deletions
|
@ -2020,6 +2020,22 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks if the specified expression needs parentheses for prefix
|
||||
/// or postfix suggestions to be valid.
|
||||
/// For example, `a + b` requires parentheses to suggest `&(a + b)`,
|
||||
/// but just `a` does not.
|
||||
/// Similarly, `(a + b).c()` also requires parentheses.
|
||||
/// This should not be used for other types of suggestions.
|
||||
pub fn expr_needs_parens(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
// parenthesize if needed (Issue #46756)
|
||||
ExprKind::Cast(_, _) | ExprKind::Binary(_, _, _) => true,
|
||||
// parenthesize borrows of range literals (Issue #54505)
|
||||
_ if is_range_literal(expr) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub enum ExprKind<'hir> {
|
||||
/// Allow anonymous constants from an inline `const` block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue