看看这个锈功能:
vue
如您所见,impl<'a> HeapVisitor<'a> {
fn visit<V: Visitor>(
&mut self,
mut ast: &'a Ast,
mut visitor: V,
) -> Result<V::Output, V::Err>
{
unimplemented!()
}
}
pub fn visit<V: Visitor>(ast: &Ast, visitor: V) -> Result<V::Output, V::Err> {
HeapVisitor::new().visit(ast, visitor)
}
对visit
进行了不可变的引用,并将其传递给Ast
,后者期望是可变的HeapVisitor.visit
。为什么编译器不抱怨此代码?