Operator impl causes compilation error for an expression involving the operator with a different pair of types #80542
Labels
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
fixed-by-next-solver
Fixed by the next-generation trait solver, `-Znext-solver`.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
The existence of an implementation for
Add<Container<A>> for X where X: Add<A>
causes a compiler error under certain circumstances for expressions of the formX + X
. Here's an example:(playground)
I expected this to compile without errors. Instead, I receive the following error message (abbreviated below):
Observe that even though the addition is between two
f32
literals, the error message indicates that the compiler is trying to apply the impl involvingContainer
.Note that it still fails to compile if I replace
f32
with a custom struct.To help diagnose the issue, it's helpful to note that replacing the
doesnt_compile
function with any of the following similar functions causes the example to compile without errors:We first observed the issue in a more complicated case in the
ndarray
crate. (See the discussion here.) This bug report is a simplified example. Edit: Interestingly, in the more complicated case, we observed differing error messages between different platforms.Meta
Stable (1.48.0), Beta (1.50.0-beta.1, 2020-12-29), and Nightly (1.51.0-nightly, 2020-12-29) all produce a compilation error (tested with the Rust Playground).
On my machine,
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: