Closed
Description
Code
I tried this code:
pub trait FieldElement {
type Integer: TryFrom<usize, Error = std::num::TryFromIntError>;
fn valid_integer_try_from<N>(i: N) -> Result<Self::Integer, ()>
where
Self::Integer: TryFrom<N>,
{
Self::Integer::try_from(i).map_err(|_| ())
}
}
I expected to see this happen: Successful compilation.
Instead, this happened: I now get the following compiler error.
error[E0308]: mismatched types
--> src/lib.rs:8:33
|
4 | fn valid_integer_try_from<N>(i: N) -> Result<Self::Integer, ()>
| - this type parameter
...
8 | Self::Integer::try_from(i).map_err(|_| ())
| ----------------------- ^ expected `usize`, found type parameter `N`
| |
| arguments to this function are incorrect
|
= note: expected type `usize`
found type parameter `N`
note: associated function defined here
--> /home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:478:8
|
478 | fn try_from(value: T) -> Result<Self, Self::Error>;
| ^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `nightly-prio-regression` due to previous error
Version it worked on
It most recently worked on: stable channel Rust 1.63.0, and nightly-2022-08-17.
Version with regression
searched nightlies: from nightly-2022-08-11 to nightly-2022-08-26
regressed nightly: nightly-2022-08-18
searched commit range: 86c6ebe...9c20b2a
regressed commit: 9c20b2a
bisected with cargo-bisect-rustc v0.6.4
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
While reducing this example, I noticed that the following changes to the code will make the error go away:
- Replacing the function call with
N::try_into(i)
- Deleting the specification of
Error
in the associated type's trait bound - Adding the same
Error
specification in the where clause's trait bound