When trying to return Self instead of self from a method with a self or mut self parameter the suggestion is most likely misleading. I expected the compiler to tell me to change Self to self because in my eyes its more likely that the user wants to return the same instance that they took instead of allocating a new one but instead i get this:
error: the `Self` constructor can only be used with tuple or unit structs
--> builders.rs:13:7
|
13 | Self
| ^^^^ help: use curly brackets: `Self { /* fields */ }`
error: aborting due to previous error
here is a reproducer:
fn main() {
}
struct Builder {
setting: bool,
}
impl Builder {
fn setting(mut self) -> Self {
self.setting = true;
Self
}
}
here is the expected output:
error: `Self` is a constructor and thus can't be returned itself
--> builders.rs:13:7
|
13 | Self
| ^^^^ help: try replacing `Self` with `self`
error: aborting due to previous error
When trying to return
Selfinstead ofselffrom a method with aselformut selfparameter the suggestion is most likely misleading. I expected the compiler to tell me to changeSelftoselfbecause in my eyes its more likely that the user wants to return the same instance that they took instead of allocating a new one but instead i get this:here is a reproducer:
here is the expected output: