zlacker

[parent] [thread] 4 comments
1. comex+(OP)[view] [source] 2024-02-24 07:20:16
Indeed. Though, Rust does have a way to mark a function such that any caller that implicitly discards its return value gets a compiler warning. This feature largely solves the problem you’re talking about. But it’s orthogonal to Rust’s borrowing system or mutable versus immutable distinction.

That said, I’d also point out that, while you can more or less replicate the Go example with Rust slices, in Rust it would be more idiomatic to pass around a Vec (or a mutable reference to a Vec) if a callee needs to do something like change the length. And you can’t resize a Vec if there are other references to its contents.

replies(1): >>Releas+b1
2. Releas+b1[view] [source] 2024-02-24 07:35:36
>>comex+(OP)
`#[must_use]`. I really don't know why Rust made that error.
replies(1): >>lifthr+o2
◧◩
3. lifthr+o2[view] [source] [discussion] 2024-02-24 07:56:40
>>Releas+b1
I think it is notable that both `try!` (`?` today) and `#[must_use]` (originally restricted to `Result`, then made available in general later) appeared in the same release (0.10). In the other words, `#[must_use]` was strongly tied to `Result` back then. While we can put `#[must_use]` to any type now, the set of types that absolutely have to be `#[must_use]` remains relatively small, with a major addition being iterators and futures. Once they have been covered, any additional value from adding `#[must_use]` is not large enough to make it default, I think.
replies(1): >>kibwen+Hu
◧◩◪
4. kibwen+Hu[view] [source] [discussion] 2024-02-24 14:28:44
>>lifthr+o2
> While we can put `#[must_use]` to any type now, the set of types that absolutely have to be `#[must_use]` remains relatively small

Agreed, although conversely if we could start Rust development all over again I'd probably argue that must_use on functions (as opposed to on types) should probably be the default behavior. (These days it basically is the default behavior for functions in the standard library.) Though Rust didn't gain the ability to annotate functions with must_use until 1.27. Switching the default could perhaps be a good candidate for an Edition.

replies(1): >>tialar+tS
◧◩◪◨
5. tialar+tS[view] [source] [discussion] 2024-02-24 17:11:54
>>kibwen+Hu
It's too late to propose new features for Edition 2024, and you would first need to get some attribute agreed which has the opposite effect, then write up how your proposal works and see if it's generally agreed. I doubt that but you should certainly try.
[go to top]