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
    A-trait-system
    I-unsound
    C-bug
    T-types
    on Jul 21, 2022
  2. added
    I-prioritize
    on Jul 21, 2022
  3. added
    E-mentor
    E-medium
    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-high
    and removed
    I-prioritize
    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
  18. added
    S-triggers-future-incompat-lint
    on Sep 14, 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-itemsA-coherenceA-trait-systemC-bugE-mediumE-mentorI-unsoundP-highS-triggers-future-incompat-lintT-types

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions