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

Type inference does not propagate back to {float} associated functions #102401

Open
jruderman opened this issue Sep 28, 2022 · 0 comments
Open

Type inference does not propagate back to {float} associated functions #102401

jruderman opened this issue Sep 28, 2022 · 0 comments
Labels
A-inference Area: Type inference C-enhancement Category: An issue proposing an enhancement or a PR with one. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

I tried this code (playground):

fn main() {
    let r = 1.0;
    let _ = r.sqrt();
    let _ = r == 0_f32;
}

I expected rustc to infer the type of r as f32 based on the last line.

Instead, rustc failed to compile my program:

error[E0689]: can't call method `sqrt` on ambiguous numeric type `{float}`
 --> src/main.rs:3:15
  |
3 |     let _ = r.sqrt();
  |               ^^^^
  |
help: you must specify a type for this binding, like `f32`
  |
2 |     let r: f32 = 1.0;
  |          +++++

In most cases, type inference works both forwards and backwards, so why didn't it work here?

This is similar to #24124, but with an even stronger reason to feel the code should work. #99405 may also be related.

@jruderman jruderman added the C-bug Category: This is a bug. label Sep 28, 2022
@fmease fmease added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-inference Area: Type inference T-types Relevant to the types team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage-legacy labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-enhancement Category: An issue proposing an enhancement or a PR with one. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants