Given the following code:
trait StringExt {
fn ext(&self);
}
impl StringExt for String {
fn ext(&self) {
<Self as str>::trim(self);
// str::trim(self); - this works
}
}
Playground
The current output is:
error[E0576]: cannot find method or associated constant `trim` in `str`
--> src/lib.rs:6:24
|
6 | <Self as str>::trim(self);
| ^^^^ not found in `str`
For more information about this error, try `rustc --explain E0576`.
However, str is not a trait, therefore the fully-qualified trait syntax should be simply invalid in this case - therefore, the error would better say the real problem ("str is not a trait"), probably with the help message suggesting the commented-out line.
Initially found in this SO question.
Given the following code:
Playground
The current output is:
However,
stris not a trait, therefore the fully-qualified trait syntax should be simply invalid in this case - therefore, the error would better say the real problem ("stris not a trait"), probably with the help message suggesting the commented-out line.Initially found in this SO question.