Repository navigation
orphan check incorrectly handles projections #99554
Copy link
Copy link
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-coherenceArea: CoherenceArea: CoherenceA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call 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.Call 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/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityS-triggers-future-incompat-lintStatus: This bug triggers a future-incompatibility lintStatus: This bug triggers a future-incompatibility lintT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
We consider projections to be foreign types during orphan check
rust/compiler/rustc_trait_selection/src/traits/coherence.rs
Lines 780 to 782 in 7ed044c
| | 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-coherenceArea: CoherenceArea: CoherenceA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call 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.Call 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/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityS-triggers-future-incompat-lintStatus: This bug triggers a future-incompatibility lintStatus: This bug triggers a future-incompatibility lintT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Projects
- StatusShow more project fieldsfuture compat lint
Activity
lcnr commentedon Jul 21, 2022
after #99552 has landed, we should be able to fix this by:
found_param_tytofound_uncovered_tyty::Projectionapiraino commentedon Jul 21, 2022
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-high
atsuzaki commentedon Aug 3, 2022
@rustbot claim
4 remaining items
Auto merge of rust-lang#117164 - fmease:orphan-norm, r=<try>
Auto merge of rust-lang#117164 - fmease:orphan-norm, r=<try>
Auto merge of rust-lang#117164 - fmease:orphan-norm, r=<try>
Auto merge of rust-lang#117164 - fmease:orphan-norm, r=lcnr
fmease commentedon Apr 30, 2024
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.