All HIR attributes are outer

This commit is contained in:
David Tolnay
2025-06-19 23:56:23 -07:00
parent 715e02ff3c
commit 6729b667ce
10 changed files with 140 additions and 156 deletions

View File

@@ -855,14 +855,15 @@ impl<'tcx> LateContext<'tcx> {
/// rendering diagnostic. This is not the same as the precedence that would
/// be used for pretty-printing HIR by rustc_hir_pretty.
pub fn precedence(&self, expr: &hir::Expr<'_>) -> ExprPrecedence {
let for_each_attr = |id: hir::HirId, callback: &mut dyn FnMut(&hir::Attribute)| {
let has_attr = |id: hir::HirId| -> bool {
for attr in self.tcx.hir_attrs(id) {
if attr.span().desugaring_kind().is_none() {
callback(attr);
return true;
}
}
false
};
expr.precedence(&for_each_attr)
expr.precedence(&has_attr)
}
/// If the given expression is a local binding, find the initializer expression.