3 ms·
I don't believe you can mark trait methods with #[must_use] - it has to be on the implementation. Not near a compiler to check at the moment. In the case of e.
by junon 10mo ago
I don't believe you can mark trait methods with #[must_use] - it has to be on the implementation. Not near a compiler to check at the moment.
In the case of e.g. Vec, it returns a reference, which by itself is side-effect free, so the compiler will always optimize it. I do agree that it should still be marked as such though. I'd be curious the reasons why it's not.
- the_mitsuhiko 10mo agoBut it's also not marked at the implementation for HashMap's Index impl for instance.
- tialaramex 10mo agoThis didn't seem like a footgun to me, hats["Jim"]; will panic if, in fact "Jim" isn't one of the keys, but what did the hypothetical author expect to happen when they write this? HashMap doesn't implement IndexMut so hats["Jim"] = 26; won't even compile.
- deleted 10mo ago[deleted]
- steveklabnik 10mo agoThis is just my take, but I think historically the Rust team was hesitant to over-mark things #[must_use] because they didn't want to introduce warning fatigue. I think there's a reasonable position to take that it was/is too conservative, and also one that it's fine.