rust-lang / rust-lang/rust

Nightly shows confusing diagnostics mentioning `ZeroablePrimitive` without apparent reason

Open
#161,882 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage P-medium regression-from-stable-to-nightly WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproducer in src/lib.rs and investigate its behavior under Rust's new trait solver on the reported nightly version. Compare the diagnostic with the 1.98.0 behavior and trace why ZeroablePrimitive appears. Done means the compiler reports only relevant trait errors without the unrelated ZeroablePrimitive diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.