Skip to content

Commit 94960c4

Browse files
committed
hir_analysis: specialisation w/ host effect preds
There are some uses of `min_specialization` in the standard library which now see `HostEffectPredicate` - this shouldn't prevent specialization for the sizedness marker traits that are now const.
1 parent e12805e commit 94960c4

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ fn check_specialization_on<'tcx>(
436436
// Global predicates are either always true or always false, so we
437437
// are fine to specialize on.
438438
_ if clause.is_global() => Ok(()),
439-
// We allow specializing on explicitly marked traits with no associated
439+
// We allow specializing on explicitly marked traits (and host effects) with no associated
440440
// items.
441-
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity: _ }) => {
441+
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity: _ })
442+
| ty::ClauseKind::HostEffect(ty::HostEffectPredicate { trait_ref, constness: _ }) => {
442443
if matches!(
443444
trait_specialization_kind(tcx, clause),
444445
Some(TraitSpecializationKind::Marker)
@@ -487,15 +488,15 @@ fn trait_specialization_kind<'tcx>(
487488
clause: ty::Clause<'tcx>,
488489
) -> Option<TraitSpecializationKind> {
489490
match clause.kind().skip_binder() {
490-
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity: _ }) => {
491+
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity: _ })
492+
| ty::ClauseKind::HostEffect(ty::HostEffectPredicate { trait_ref, constness: _ }) => {
491493
Some(tcx.trait_def(trait_ref.def_id).specialization_kind)
492494
}
493495
ty::ClauseKind::RegionOutlives(_)
494496
| ty::ClauseKind::TypeOutlives(_)
495497
| ty::ClauseKind::Projection(_)
496498
| ty::ClauseKind::ConstArgHasType(..)
497499
| ty::ClauseKind::WellFormed(_)
498-
| ty::ClauseKind::ConstEvaluatable(..)
499-
| ty::ClauseKind::HostEffect(..) => None,
500+
| ty::ClauseKind::ConstEvaluatable(..) => None,
500501
}
501502
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@ check-pass
2+
//@ compile-flags: --crate-type=lib
3+
#![no_std]
4+
#![allow(internal_features)]
5+
#![feature(rustc_attrs, min_specialization)]
6+
7+
// Confirm that specialisation w/ sizedness host effect predicates works.
8+
9+
pub trait Iterator {
10+
type Item;
11+
}
12+
13+
#[rustc_unsafe_specialization_marker]
14+
pub trait MoreSpecificThanIterator: Iterator {}
15+
16+
pub trait Tr {
17+
fn foo();
18+
}
19+
20+
impl<A, Iter> Tr for Iter
21+
where
22+
Iter: Iterator<Item = A>,
23+
{
24+
default fn foo() {}
25+
}
26+
27+
impl<A, Iter> Tr for Iter
28+
where
29+
Iter: MoreSpecificThanIterator<Item = A>,
30+
{
31+
fn foo() {}
32+
}

0 commit comments

Comments
 (0)