You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible regression on use of Self in generics ("mismatched types") #69611
The following code (also on playground) compiles fine on Stable and Beta rustc, but has started no longer compiling on latest nightly (2020-02-28, 2020-02-29 both have this issue).
I would expect this code snippet to compile with no errors as it currently does in stable and beta Rust.
Instead, on recent nightlies (02-28 and 02-29 were tested), an error is produced:
--> src/lib.rs:10:14
|
3 | impl<T, V> core::ops::Mul<T> for Container<V>
| - - expected type parameter
| |
| found type parameter
...
10 | Self(scalar * self.0.into())
| ^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `V`, found type parameter `T`
|
= note: expected type parameter `V`
found type parameter `T`
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
I believe this is because rustc is erroneously picking Self to be Container<V> (the type for which the impl is being specified) instead of using Container and inferring the (formerly correct) output type of Container<T>.
Yeah, this was caused by a bug fix to type checking of Self paths, which would previously wrongly introduce inference variables for type parameters in the impl. Using Self should always refer to the Self type, just as using Self {...} would. In other words, your code should never have compiled.
Activity
rye commentedon Mar 1, 2020
Sure enough, this seems related to #69306, which was marked resolved by PR #69340. I guess I'm one of the lucky people affected by those changes. 😄
Centril commentedon Mar 1, 2020
Yeah, this was caused by a bug fix to type checking of
Selfpaths, which would previously wrongly introduce inference variables for type parameters in the impl. UsingSelfshould always refer to theSelftype, just as usingSelf {...}would. In other words, your code should never have compiled.Centril commentedon Mar 18, 2020
Closing as expected breakage and "wontfix".
Fix use of Self