Integer method earlier than function with known type is called
Open
Nobody has claimed this yet.
A-inference
C-bug
needs-triage
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
fn show(n: u8) {
println!("{n}")
}
fn main() {
let mut n = 0;
n = n.wrapping_add(1);
show(n)
}
If show() is called later, compiler can't see the type for wrapping_add(). But if show() is earlier than wrapping_add():
fn show(n: u8) {
println!("{n}")
}
fn main() {
let mut n = 0;
show(n);
n = n.wrapping_add(1)
}
Compiler sees the type.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the two minimal Rust programs in the issue and comparing their diagnostics. Investigate how the compiler infers the integer type for wrapping_add and how the later call to show affects that inference. Done means equivalent code ordering no longer changes whether the method call receives a known type.
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