Open
Description
This is strongly related to #98357.
The presence of a Mul
impl for both u8
and i32
introduces an ambiguity in main()
where the type of the literal 7
cannot be determined. #98357 goes into why this is an error since it can be fixed by assigning a type (Foo
) to prod
, but this issue is about a regression in rustc 1.62 which drops information about the ambiguity in the literal integer's type from the error message/notes as compared to 1.61 (which does not).
use core::ops::Mul;
#[derive(Debug)]
struct Foo(i32);
impl Mul<Foo> for i32 {
type Output = Foo;
fn mul(self, other: Foo) -> Self::Output {
Foo(self * other.0)
}
}
impl Mul<Foo> for u8 {
type Output = Foo;
fn mul(self, other: Foo) -> Self::Output {
Foo(self as i32 * other.0)
}
}
fn main() {
let prod = 7 * Foo(6);
assert_eq!(prod.0, 42);
}
The error message emitted by 1.61 (current stable):
error[[E0282]](https://doc.rust-lang.org/stable/error-index.html#E0282): type annotations needed
--> src/main.rs:24:16
|
23 | let prod = 7 * Foo(6);
| ---- consider giving `prod` a type
24 | assert_eq!(prod.0, 42);
| ^^^^ cannot infer type
|
= note: type must be known at this point
error[[E0283]](https://doc.rust-lang.org/stable/error-index.html#E0283): type annotations needed
--> src/main.rs:23:18
|
23 | let prod = 7 * Foo(6);
| ^ cannot infer type for type `{integer}`
|
note: multiple `impl`s satisfying `{integer}: Mul<Foo>` found
--> src/main.rs:6:1
|
6 | impl Mul<Foo> for i32 {
| ^^^^^^^^^^^^^^^^^^^^^
...
14 | impl Mul<Foo> for u8 {
| ^^^^^^^^^^^^^^^^^^^^
Some errors have detailed explanations: E0282, E0283.
For more information about an error, try `rustc --explain E0282`.
The error message emitted by 1.62 (2022-06-13 1bc802e) (the current beta):
error[[E0282]](https://doc.rust-lang.org/beta/error-index.html#E0282): type annotations needed
--> src/main.rs:24:16
|
23 | let prod = 7 * Foo(6);
| ---- consider giving `prod` a type
24 | assert_eq!(prod.0, 42);
| ^^^^ cannot infer type
|
= note: type must be known at this point
For more information about this error, try `rustc --explain E0282`.
Notice that while one perhaps valid resolution has been provided, the actual cause of the error is completely obscured.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
apiraino commentedon Jun 23, 2022
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
mqudsi commentedon Jul 15, 2022
@rustbot label +A-diagnostics
1 remaining item