Use lifetimes in walk_expr() to guarantee that child expr has same lifetime as parent expr

This commit is contained in:
Jussi Saurio 2025-05-28 10:49:32 +03:00
parent 7241e0503e
commit 51605ad2a4

View file

@ -2612,9 +2612,9 @@ pub fn unwrap_parens_owned(expr: ast::Expr) -> Result<(ast::Expr, usize)> {
}
/// Recursively walks an immutable expression, applying a function to each sub-expression.
pub fn walk_expr<F>(expr: &ast::Expr, func: &mut F) -> Result<()>
pub fn walk_expr<'a, F>(expr: &'a ast::Expr, func: &mut F) -> Result<()>
where
F: FnMut(&ast::Expr) -> Result<()>,
F: FnMut(&'a ast::Expr) -> Result<()>,
{
func(expr)?;
match expr {
@ -2788,9 +2788,9 @@ where
Ok(())
}
fn walk_expr_frame_bound<F>(bound: &ast::FrameBound, func: &mut F) -> Result<()>
fn walk_expr_frame_bound<'a, F>(bound: &'a ast::FrameBound, func: &mut F) -> Result<()>
where
F: FnMut(&ast::Expr) -> Result<()>,
F: FnMut(&'a ast::Expr) -> Result<()>,
{
match bound {
ast::FrameBound::Following(expr) | ast::FrameBound::Preceding(expr) => {