Method lookup doubt

⚓ Rust    📅 2026-03-07    👤 surdeus    👁️ 2      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Method lookup doubt

I was going through the Rust Reference for the Method Call expression section here Method Call Expr

And I wanted to ask about this part specifically
Then, for each candidate T, add &T and &mut T to the list immediately after T.

For instance, if the receiver has type Box<[i32;2]>, then the candidate types will be Box<[i32;2]>, &Box<[i32;2]>, &mut Box<[i32;2]>, [i32; 2] (by dereferencing), &[i32; 2], &mut [i32; 2], [i32] (by unsized coercion), &[i32], and finally &mut [i32].

Shouldn’t the dereferencing produce &[i32;2] instead if [i32;2]?

Also another question, if I have a function on some type T that takes &self and I have the same function on &T that takes self, which one gets priority in the lookup

2 posts - 2 participants

Read full topic

🏷️ Rust_feed