Skip to content

orphan check incorrectly handles projections #99554

Description

@lcnr

We consider projections to be foreign types during orphan check

| ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ..) => {
self.found_non_local_ty(ty)
}

but do not consider them to be parameters when checking for uncovered types

} else if let ty::Param(_) = input_ty.kind() {

This is more obvious after #99552

this means that the following impl passes the orphan check even though it shouldn't

// crate a
pub trait Foreign<T, U> {
    type Assoc;
}

// crate b
use a::Foreign;

trait Id {
    type Assoc;
}

impl<T> Id for T {
    type Assoc = T;
}

pub struct B;
impl<T> Foreign<B, T> for <T as Id>::Assoc {
    type Assoc = usize;
}

The impl in b overlaps with an impl impl<U> Foreign<T, LocalTy> for LocalTy in another crate c which passes the orphan check.

While I wasn't able to cause runtime UB with this, I was able to get an ICE during codegen_fulfill_obligation: https://github.com/lcnr/orphan-check-ub

cc @rust-lang/types

Activity

  1. added
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Jul 21, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 21, 2022
  3. added
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Jul 21, 2022
  4. lcnr commented on Jul 21, 2022

    @lcnr
    ContributorAuthor

    after #99552 has landed, we should be able to fix this by:

    • rename found_param_ty to found_uncovered_ty
    • also use that function for ty::Projection
    • add tests + update the error message to also make sense for projections
    • run crater
  5. apiraino commented on Jul 21, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-high

  6. 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}
    on Jul 21, 2022
  7. atsuzaki commented on Aug 3, 2022

    @atsuzaki
    Contributor

    @rustbot claim

  8. 4 remaining items

  9. added a commit that references this issue on Dec 7, 2023
    eb3956d
  10. added a commit that references this issue on Jan 18, 2024
    b24d9ff
  11. added a commit that references this issue on Feb 26, 2024
    575e416
  12. added a commit that references this issue on Apr 30, 2024
    f705de5
  13. moved this from unblocked to new solver everywhere in T-types unsound issueson Apr 30, 2024
  14. fmease commented on Apr 30, 2024

    @fmease
    Member

    Reopening because the soundness issue still exists. However, since #117164 we now emit a future-incompat dont-report-in-deps warn-by-default lint for it. Tracked separately in #124559.

  15. reopened this on Apr 30, 2024
  16. moved this from new solver everywhere to unblocked in T-types unsound issueson May 17, 2024
  17. moved this from unblocked to future compat lint in T-types unsound issueson May 17, 2024
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: CoherenceA-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityS-triggers-future-incompat-lintStatus: This bug triggers a future-incompatibility lintT-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