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

Unrelated compiler errors affects inferring a type #95648

Closed
RaviKappiyoor opened this issue Apr 4, 2022 · 1 comment · Fixed by #95751
Closed

Unrelated compiler errors affects inferring a type #95648

RaviKappiyoor opened this issue Apr 4, 2022 · 1 comment · Fixed by #95751
Assignees
Labels
C-bug Category: This is a bug.

Comments

@RaviKappiyoor
Copy link

RaviKappiyoor commented Apr 4, 2022

When I run this code (via cargo run):

use rust_decimal::Decimal;

fn main() {
  let test = Decimal::from(42);
  println!("My number is {}", test);
}

I get the output I expected (i.e., a single line of output that says "My number is 42").

However, if I run this code (via the same cargo run with no other changes):

use rust_decimal::Decimal;

fn main() {
  foo(3);
  let test = Decimal::from(42);
  println!("My number is {}", test);
}

I get two compiler errors. The first error indicates that foo is not in scope - this makes sense, I have not defined foo anywhere. However, the second error indicates (provided below) does not make sense:

error[E0283]: type annotations needed
 --> src/main.rs:5:16
  |
5 |     let test = Decimal::from(42);
  |                ^^^^^^^^^^^^^ cannot infer type for type `{integer}`
  |
  = note: multiple `impl`s satisfying `Decimal: From<{integer}>` found in the `rust_decimal` crate:
          - impl From<i128> for Decimal;
          - impl From<i16> for Decimal;
          - impl From<i32> for Decimal;
          - impl From<i64> for Decimal;
          and 8 more

It appears that, when there are no other compiler issues, the compiler can infer a type for 42 just fine. However, as soon as any other compiler issue appears, it loses the ability to infer type. That doesn't make sense to me - the ability to infer type should be unrelated to any other compiler errors present.

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
@RaviKappiyoor RaviKappiyoor added the C-bug Category: This is a bug. label Apr 4, 2022
@compiler-errors
Copy link
Member

I partially fixed this for std:: and alloc:: in #93469, but not in general. I am dissatisfied with this error message. I'll look into fixing it.

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 7, 2022
Don't report numeric inference ambiguity when we have previous errors

Fixes rust-lang#95648
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 8, 2022
Don't report numeric inference ambiguity when we have previous errors

Fixes rust-lang#95648
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 8, 2022
Don't report numeric inference ambiguity when we have previous errors

Fixes rust-lang#95648
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 8, 2022
Don't report numeric inference ambiguity when we have previous errors

Fixes rust-lang#95648
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 9, 2022
Don't report numeric inference ambiguity when we have previous errors

Fixes rust-lang#95648
@bors bors closed this as completed in d4e0ddf Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants