I tried to convince the compiler to accept my use of ? operator via basically trait MaybeFallible where MyError: From<Self>, which I now suspect is impossible. Trying the new trait solver, I got weird errors about ZeroablePrimitive which I have never mentioned in the code nor did I mention NonZero anywhere. This may be related to the new solver, so cc #160895 but I'm not sure.
Code
I tried this code:
use std::convert::Infallible;
trait MaybeFallible {
type Error: MaybeError;
fn try_do_it(&self) -> Result<(), Self::Error>;
}
trait MaybeError: Sized + From<Infallible> + Into2<MyError> + where MyError: From<Self> /* ensures ? works */ {
type ComposeWithOther<Other: MaybeError>: MaybeError + From<Self> + From<Other> where MyError: From<Other>, MyError: From<Self>;
}
impl MaybeError for Infallible {
type ComposeWithOther<Other: MaybeError> = Other where MyError: From<Other>, MyError: From<Self>;
}
impl MaybeError for MyError {
type ComposeWithOther<Other: MaybeError> = MyError where MyError: From<Other>, MyError: From<Self>;
}
fn compose<A: MaybeFallible, B: MaybeFallible>(a: A, b: B) -> Result<(), <A::Error as MaybeError>::ComposeWithOther<B::Error>> where <A::Error as MaybeError>::ComposeWithOther<B::Error>: From<B::Error> {
a.try_do_it()?;
b.try_do_it()?;
Ok(())
}
struct MyError;
impl From<Infallible> for MyError {
fn from(x: Infallible) -> Self {
match x {}
}
}
trait Into2<T: Sized + From<Self>>: Sized {}
impl<T, U: From<T>> Into2<U> for T {}
I expected to see this happen: no mentions of unrelated traits such as ZeroablePrimitive; any errors are only related to what I wrote.
Instead, this happened:
error[E0277]: the trait bound `MyError: ZeroablePrimitive` is not satisfied
--> src/lib.rs:20:188
|
20 | ... as MaybeError>::ComposeWithOther<B::Error>: From<B::Error> {
| ^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the nightly-only, unstable trait `ZeroablePrimitive` is not implemented for `MyError`
--> src/lib.rs:26:1
Version it worked on
It most recently worked on: 1.98.0
Version with regression
rustc --version --verbose:
1.100.0-nightly
(2026-08-26 bff8e12ff5e6bcd53dfb)
These are the versions currently on playground.
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
I tried to convince the compiler to accept my use of
?operator via basicallytrait MaybeFallible where MyError: From<Self>, which I now suspect is impossible. Trying the new trait solver, I got weird errors aboutZeroablePrimitivewhich I have never mentioned in the code nor did I mentionNonZeroanywhere. This may be related to the new solver, so cc #160895 but I'm not sure.Code
I tried this code:
I expected to see this happen: no mentions of unrelated traits such as
ZeroablePrimitive; any errors are only related to what I wrote.Instead, this happened:
Version it worked on
It most recently worked on: 1.98.0
Version with regression
rustc --version --verbose:These are the versions currently on playground.
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged