Skip to content

orphan check incorrectly handles projections #99554

@lcnr

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

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

Status

future compat lint

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions