Array::map annotate with #[must_use]

Swift again, for comparison:

Really wish Rust had a syntax for "call that method but return the value it was called on".

4 Likes

Before doing such a change, we should probably figure a way to mark these things as transitive across Option/Result. Consider HashMap::remove:

some_hash_map.remove(some_key).expect("Key should be in hashmap");

This will trigger the warning/error because even if HashMap::remove is marked with #[may_ignore] - that applies to the Option, not to the Option::expect.

&mut Self seems like a return type that could be excluded from default must_use, since it's a common builder pattern and not so easy to return otherwise (a linked list builder?)

1 Like

well do i have the rfc for you

2 Likes

It seems for the most part that there some purists who want everything to be annotated with #[must_use], and that's certainly another discussion and an option for those people is to just turn on a lint for every unused result, but doesn't seem to be tackling the question of whether this specific function should be tagged with #[must_use].

I don't see any good arguments why it shouldn't be marked as #[must_use], unless the map function is performing a side effect, but that is not the intended purpose of map, and likely that case is fine to ignore.

Given the replies thus far, I'll just submit a PR.

5 Likes