Skip to content

wrapping_$op() and saturating_$op() should be #[must_use] #59787

Closed
@tormol

Description

@tormol

I just had a bug due to a wrapping_add() having no effect because the return value was ignored:

let mut foo = foo();
foo.x.wrapping_add(bar); // should be foo.x = foo.x.wrapping_add(bar);
foo.y = baz; // so no warning about foo not needing to be mutable

It's an easy mistake to make when rewriting foo.x += bar to handle overflow.

EDIT: (I didn't do enough searching before opening this issue)

On one hand this is a subset of #48926, and covers a lot of methods so RFC #2450 would be better. On the other hand this issue is a v2 of #50124 for the parts of it not covered by #50149.

Meta

rustc 1.35.0-nightly (f8673e0ad 2019-04-03)
binary: rustc
commit-hash: f8673e0ad85e98997faa76fa7edc99c5825f46ee
commit-date: 2019-04-03
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions