rust-lang / rust-lang/rust

checked_add() can't infer type from its argument

Open
#160,910 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

fn main() {
 let mut n = Some(0);
 match n {
  Some(s) => n = s.checked_add(1u8),
  None => println!("None"),
 }
}

Compiler can't infer type for n. Although (1u8) specifies type u8, but compiler can't infer type from (1u8).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the minimal Rust example in the issue and inspecting the type-inference diagnostic. Trace the compiler's handling of the checked_add call and the u8 argument; done when the example infers n's type consistently with the argument and the relevant compiler tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.