Skip to content

coherence incorrectly considers unnormalizable_projection: Trait to not hold even if it could #114061

Closed

Description

@lcnr
// crate dep
trait IsUnit {}
impl IsUnit for () {}


pub trait WithAssoc<'a> {
    type Assoc;
}

// The two impls of `Trait` overlap
pub trait Trait {}
impl<T> Trait for T
where
    T: 'static,
    for<'a> T: WithAssoc<'a>,
    for<'a> <T as WithAssoc<'a>>::Assoc: IsUnit,
{
}
impl<T> Trait for Box<T> {}
// root crate
use dep::*;

struct Local;
impl WithAssoc<'_> for Box<Local> {
    type Assoc = ();
}

fn impls_trait<T: Trait>() {}

fn main() {
    impls_trait::<Box<Local>>();
}

During coherence for<'a> <Box<T> as WithAssoc<'a>>::Assoc: IsUnit is considered to not hold.
This allows overlapping impls in coherence which is generally considered to be unsound™.

Coherence considers the impls to be disjoint because for<'a> <Box<T> as WithAssoc<'a>>::Assoc: IsUnit, does not hold. When trying to normalize <Box<T> as WithAssoc<'a>>::Assoc ends up ambiguous, we keep the projection around. Coherence then considers for<'a> <Box<T> as WithAssoc<'a>>::Assoc: IsUnit to not have any impl as IsUnit is a local trait.

cc rust-lang/trait-system-refactor-initiative#52

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 25, 2023
  2. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Jul 25, 2023
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 25, 2023
  4. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 25, 2023
  5. lcnr commented on Oct 2, 2023

    @lcnr
    Author
  6. lcnr commented on Oct 9, 2023

    @lcnr
    ContributorAuthor

    figure out why this detects overlap in the new solver, it is strongly related to #99554

  7. moved this to new solver in coherence in T-types unsound issueson Nov 15, 2023
  8. moved this from new solver in coherence to unblocked in T-types unsound issueson Nov 15, 2023
  9. 19 remaining items

  10. added a commit that references this issue on May 2, 2024
  11. added 3 commits that reference this issue on Aug 15, 2024
  12. added a commit that references this issue on Sep 6, 2024
  13. added a commit that references this issue on Sep 21, 2024
  14. added 3 commits that reference this issue on Oct 3, 2024
  15. moved this to Completed in T-types unsound issueson Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-coherenceArea: CoherenceC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions