Skip to content

Feature DFV makes addition of trait impls breaking (apart from 1IR) since we don't reject trivially unsatisfiable clauses on ADTs with DFVs #165152

Open

Description

@fmease

A sequel to #146496. "Trivially unsatisfiable clauses" aka "trivial bounds" aka "impossible bounds" aka "false global bounds" were briefly alluded to by [@]lcnr in #t-types/nominated > #146496: The way `default_field_values` deals with in-scope… @ 💬 and they were also a topic brought up separately by [@]BoxyUwU in the context of GCI (feature generic_const_items), see #142293 (comment).

Reproducer

Upstream crate upstream:

pub trait Trait { const THING: (); }

// NOTE: Adding this innocuous-looking impl breaks downstream.
//impl Trait for () { const THING: () = (); }

Downstream crate downstream:

#![feature(default_field_values)]

struct Type
where
    for<'_delay> (): upstream::Trait,
{
    field: () = {
        let _ = <() as upstream::Trait>::THING;
        panic!() // NOTE: Panics if upstream adds the impl.
    },
}

Here, we const_eval_poly the default of Type.field which bails out early without error (probably with ErrorHandled::TooGeneric) once it encounters the const projection since the type doesn't really implement the trait, it's only an assumption in the environment.


We try to avoid introducing features that make adding trait impls1 (more) breaking. "More" breaking because 1IR (the "one-impl rule") is the main offender already. A semi-offender would be const blocks in a function with trivially unsatisfiable bounds ("semi" because it can "only" lead to post-mono breakages).

Footnotes

  1. We're ignoring pathological impls here that contain associated consts or const fns that unconditionally diverge, etc. It gets blurry really fast because the RHS of non-type-system const exprs is not really considered part of the public API... ↩

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Oct 29, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 29, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 29, 2026
  4. changed the title [-]DFV: Addition of trait impl is breaking (apart from 1IR) since we don't reject trivially unsatisfiable (modulo regions) clauses on ADTs with DFVs[/-] [+]DFV: Addition of trait impl is breaking (apart from 1IR) since we don't reject trivially unsatisfiable clauses on ADTs with DFVs[/+] on Oct 29, 2026
  5. fmease commented on Oct 29, 2026

    @fmease
    MemberAuthor

    In the title I once stated "trivially unsatisfiable (modulo regions)" because bounds that reference early-bound regions (e.g., <'a> &'a (): upstream::Trait are also iffy and "confuse" const eval but I couldn't come up with a similar reproducer...

  6. fmease commented on Oct 29, 2026

    @fmease
    MemberAuthor

    One solution Boxy once suggested for GCI was to flat out reject trivial bounds in cases like this (CC #142293 (comment)) (edit: Now tracked in #165153).

  7. changed the title [-]DFV: Addition of trait impl is breaking (apart from 1IR) since we don't reject trivially unsatisfiable clauses on ADTs with DFVs[/-] [+]Feature DFV makes addition of trait impls breaking (apart from 1IR) since we don't reject trivially unsatisfiable clauses on ADTs with DFVs[/+] on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-default_field_values`#![feature(default_field_values)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions