cl-ast: Fix AddrOf misbehavior

This commit is contained in:
2025-01-29 03:31:24 -06:00
parent bc955c6409
commit 518fbe74a1
7 changed files with 24 additions and 28 deletions

View File

@@ -546,7 +546,6 @@ pub struct ArrayRep {
/// An address-of expression: `&` `mut`? [`Expr`]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AddrOf {
pub count: usize,
pub mutable: Mutability,
pub expr: Box<ExprKind>,
}

View File

@@ -616,11 +616,8 @@ mod display {
impl Display for AddrOf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { count, mutable, expr } = self;
for _ in 0..*count {
f.write_char('&')?;
}
write!(f, "{mutable}{expr}")
let Self { mutable, expr } = self;
write!(f, "&{mutable}{expr}")
}
}

View File

@@ -322,9 +322,8 @@ pub trait Fold {
}
}
fn fold_addrof(&mut self, a: AddrOf) -> AddrOf {
let AddrOf { count, mutable, expr } = a;
let AddrOf { mutable, expr } = a;
AddrOf {
count,
mutable: self.fold_mutability(mutable),
expr: Box::new(self.fold_expr_kind(*expr)),
}

View File

@@ -279,7 +279,7 @@ pub trait Visit<'a>: Sized {
self.visit_expr_kind(repeat);
}
fn visit_addrof(&mut self, a: &'a AddrOf) {
let AddrOf { count: _, mutable, expr } = a;
let AddrOf { mutable, expr } = a;
self.visit_mutability(mutable);
self.visit_expr_kind(expr);
}