Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operands of "non-regular" versions of arithmetic ops don't infer whereas regular ops operands do #72526

Closed
DustinByfuglien opened this issue May 24, 2020 · 1 comment

Comments

@DustinByfuglien
Copy link

DustinByfuglien commented May 24, 2020

For programmer point of view there is no visible reason that operands of "non-regular" versions of arithmetic operators (saturating, overflowing, ...) can't be inferred in some situations when "regular" do it.

fn main() {
    let mut sum = 0;
    sum = sum + 1_usize;                // Ok
    let mut sum = 0;
    sum = sum.saturating_add(1_usize);  // Error
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0689]: can't call method `saturating_add` on ambiguous numeric type `{integer}`
 --> src/main.rs:5:15
  |
5 |     sum = sum.saturating_add(1_usize);  // Error
  |               ^^^^^^^^^^^^^^
  |
help: you must specify a type for this binding, like `i32`
  |
4 |     let mut sum: i32 = 0;
  |         ^^^^^^^^^^^^

It could be nice if saturating version of sum can be inferred to usize too.

@bluss
Copy link
Member

bluss commented May 24, 2020

Duplicate of #24124

@bluss bluss closed this as completed May 24, 2020
@bluss bluss marked this as a duplicate of #24124 May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants