The following program works fine:
pub fn foo(_v: &str) -> bool {
false
}
fn main() {
let f = "hello world";
println!("{}", foo(&&&&f)); // note the number of & here
}
In fact it works on passing any number of &
. How should I interpret what is going on ?
My rust version:
$ rustc --version
rustc 1.32.0-nightly (13dab66a6 2018-11-05)
When the Deref trait is defined for the types involved, Rust will analyze the types and use Deref::deref as many times as necessary to get a reference to match the parameter’s type.
– halfelfDeref
coercion (which can happen at any coercion site). – trentclautoderef
applies also in thefunction(&&&&&x)
case, not only in the context of methods receivers. In this case I could agree with tagging this question as duplicate, but @trentcl expresses another point of view. Some more consideration for helping to clarify? – attdona