Closed
Description
The book states:
Methods take a special first parameter, of which there are three variants:
self
,&self
, and&mut self
.
The reference uses typed self in a few places, but doesn't explain the exact rules.
The compiler also prints redundant and misleading diagnostics:
struct S;
impl S {
fn f(self: Vec<Self>) {}
}
gives:
<anon>:6:10: 6:28 error: mismatched self type: expected `S`: expected struct `S`, found struct `collections::vec::Vec` [E0211]
<anon>:6 fn f(self: Vec<Self>) {}
^~~~~~~~~~~~~~~~~~
Since replacing Vec<Self>
with Box<Self>
makes the code compile, "expected struct S
" isn't quite correct.