pow inference is not great
Open
Nobody has claimed this yet.
A-inference
C-discussion
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
fn do_pow(n: i32) -> f64 {
0.95.powi(n)
}
error[E0689]: can't call method `powi` on ambiguous numeric type `{float}`
--> mail/mail-common/src/mailbox/attachments.rs:335:18
|
335 | 0.95.powi(n)
| ^^^^
|
help: you must specify a concrete type for this numeric value, like `f32`
|
335 | 0.95_f32.powi(n)
| ~~~~~~~~
Why can't the compiler infer that if it's being expected to produce a f64 the type should be an f64?
I can't think of any other cases outside of pow where the inference fails.
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 with the minimal do_pow reproducer and the example at mail/mail-common/src/mailbox/attachments.rs:335. Read the compiler's numeric type inference and method-resolution behavior around powi, then determine whether the expected f64 result can constrain the receiver; done means a documented resolution or an accepted compiler change with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100