为何编译器接受可变参数的不可变引用?

时间:2019-03-18 09:28:13

标签: reference rust immutability mutability

看看这个锈功能:

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。为什么编译器不抱怨此代码?

0 个答案:

没有答案