Skip to content

Commit 6f5b1d2

Browse files
committed
Other logics
1 parent ff3985b commit 6f5b1d2

File tree

26 files changed

+60
-4
lines changed

26 files changed

+60
-4
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,9 +2370,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23702370
// We lower empty bounds like `Vec<dyn Copy>:` as
23712371
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
23722372
// regular WF checking
2373-
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
2374-
continue;
2373+
2374+
match pred.kind().skip_binder() {
2375+
ty::ClauseKind::WellFormed(..) | ty::ClauseKind::UnstableFeature(..) => continue,
2376+
_ => {}
23752377
}
2378+
23762379
// Match the existing behavior.
23772380
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
23782381
let pred = self.normalize(span, None, pred);

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ fn trait_specialization_kind<'tcx>(
499499
| ty::ClauseKind::ConstArgHasType(..)
500500
| ty::ClauseKind::WellFormed(_)
501501
| ty::ClauseKind::ConstEvaluatable(..)
502+
| ty::ClauseKind::UnstableFeature(_)
502503
| ty::ClauseKind::HostEffect(..) => None,
503504
}
504505
}

compiler/rustc_hir_analysis/src/outlives/explicit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5454
| ty::ClauseKind::ConstArgHasType(_, _)
5555
| ty::ClauseKind::WellFormed(_)
5656
| ty::ClauseKind::ConstEvaluatable(_)
57+
| ty::ClauseKind::UnstableFeature(_)
5758
| ty::ClauseKind::HostEffect(..) => {}
5859
}
5960
}

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5353
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
5454
| ty::PredicateKind::ConstEquate(..)
5555
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
56+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
5657
| ty::PredicateKind::Ambiguous => false,
5758
}
5859
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
926926
| ty::ClauseKind::ConstArgHasType(_, _)
927927
| ty::ClauseKind::WellFormed(_)
928928
| ty::ClauseKind::ConstEvaluatable(_)
929+
| ty::ClauseKind::UnstableFeature(_)
929930
| ty::ClauseKind::HostEffect(..) => None,
930931
}
931932
});

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,9 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15681568
ClauseKind::TypeOutlives(..) |
15691569
ClauseKind::RegionOutlives(..) => "lifetime",
15701570

1571+
ClauseKind::UnstableFeature(_)
15711572
// `ConstArgHasType` is never global as `ct` is always a param
1572-
ClauseKind::ConstArgHasType(..)
1573+
| ClauseKind::ConstArgHasType(..)
15731574
// Ignore projections, as they can only be global
15741575
// if the trait bound is global
15751576
| ClauseKind::Projection(..)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
132132
type FnInputTys = &'tcx [Ty<'tcx>];
133133
type ParamTy = ParamTy;
134134
type BoundTy = ty::BoundTy;
135+
type Symbol = Symbol;
135136

136137
type PlaceholderTy = ty::PlaceholderType;
137138
type ErrorGuaranteed = ErrorGuaranteed;
@@ -816,6 +817,14 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
816817
fn associated_const_equality(self) -> bool {
817818
self.associated_const_equality()
818819
}
820+
821+
fn impl_stability(self) -> bool {
822+
self.impl_stability()
823+
}
824+
825+
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
826+
self.enabled(symbol)
827+
}
819828
}
820829

821830
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl<'tcx> Predicate<'tcx> {
131131
| PredicateKind::Clause(ClauseKind::TypeOutlives(_))
132132
| PredicateKind::Clause(ClauseKind::Projection(_))
133133
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
134+
| PredicateKind::Clause(ClauseKind::UnstableFeature(_))
134135
| PredicateKind::DynCompatible(_)
135136
| PredicateKind::Subtype(_)
136137
| PredicateKind::Coerce(_)
@@ -649,6 +650,7 @@ impl<'tcx> Predicate<'tcx> {
649650
PredicateKind::Clause(ClauseKind::Projection(..))
650651
| PredicateKind::Clause(ClauseKind::HostEffect(..))
651652
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
653+
| PredicateKind::Clause(ClauseKind::UnstableFeature(_))
652654
| PredicateKind::NormalizesTo(..)
653655
| PredicateKind::AliasRelate(..)
654656
| PredicateKind::Subtype(..)
@@ -670,6 +672,7 @@ impl<'tcx> Predicate<'tcx> {
670672
PredicateKind::Clause(ClauseKind::Trait(..))
671673
| PredicateKind::Clause(ClauseKind::HostEffect(..))
672674
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
675+
| PredicateKind::Clause(ClauseKind::UnstableFeature(_))
673676
| PredicateKind::NormalizesTo(..)
674677
| PredicateKind::AliasRelate(..)
675678
| PredicateKind::Subtype(..)

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,7 @@ define_print! {
32503250
ty::ClauseKind::ConstEvaluatable(ct) => {
32513251
p!("the constant `", print(ct), "` can be evaluated")
32523252
}
3253+
ty::ClauseKind::UnstableFeature(symbol) => p!("unstable feature: ", write("`{}`", symbol)),
32533254
}
32543255
}
32553256

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ where
596596
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
597597
self.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })
598598
}
599+
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
600+
self.compute_unstable_feature_goal(param_env, symbol)
601+
}
599602
ty::PredicateKind::Subtype(predicate) => {
600603
self.compute_subtype_goal(Goal { param_env, predicate })
601604
}

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ where
156156
}
157157
ty::ClauseKind::ConstEvaluatable(ct) => ct.visit_with(self),
158158
ty::ClauseKind::WellFormed(term) => term.visit_with(self),
159+
ty::ClauseKind::UnstableFeature(_) => V::Result::output(),
159160
}
160161
}
161162

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
648648
ClauseKind::HostEffect(..) => {
649649
todo!()
650650
}
651+
ClauseKind::UnstableFeature(_) => {
652+
todo!()
653+
}
651654
}
652655
}
653656
}

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ symbols! {
11551155
ignore,
11561156
impl_header_lifetime_elision,
11571157
impl_lint_pass,
1158+
impl_stability,
11581159
impl_trait_in_assoc_type,
11591160
impl_trait_in_bindings,
11601161
impl_trait_in_fn_trait_return,
@@ -2246,6 +2247,7 @@ symbols! {
22462247
unsized_locals,
22472248
unsized_tuple_coercion,
22482249
unstable,
2250+
unstable_feature_bound,
22492251
unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
22502252
unstable location; did you mean to load this crate \
22512253
from crates.io via `Cargo.toml` instead?",

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
649649
| ty::PredicateKind::ConstEquate { .. }
650650
// Ambiguous predicates should never error
651651
| ty::PredicateKind::Ambiguous
652+
// We never return Err when proving UnstableFeature goal.
653+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature{ .. })
652654
| ty::PredicateKind::NormalizesTo { .. }
653655
| ty::PredicateKind::AliasRelate { .. }
654656
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType { .. }) => {

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
800800
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
801801
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
802802
| ty::PredicateKind::Coerce(..)
803+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
803804
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) => {}
804805
ty::PredicateKind::Ambiguous => return false,
805806
};

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ fn predicate_references_self<'tcx>(
238238
// FIXME(generic_const_exprs): this can mention `Self`
239239
| ty::ClauseKind::ConstEvaluatable(..)
240240
| ty::ClauseKind::HostEffect(..)
241+
| ty::ClauseKind::UnstableFeature(_)
241242
=> None,
242243
}
243244
}
@@ -278,6 +279,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
278279
| ty::ClauseKind::ConstArgHasType(_, _)
279280
| ty::ClauseKind::WellFormed(_)
280281
| ty::ClauseKind::ConstEvaluatable(_)
282+
| ty::ClauseKind::UnstableFeature(_)
281283
| ty::ClauseKind::HostEffect(..) => false,
282284
})
283285
}

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
110110
| ty::PredicateKind::ConstEquate(..)
111111
| ty::PredicateKind::Ambiguous
112112
| ty::PredicateKind::NormalizesTo(..)
113+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
113114
| ty::PredicateKind::AliasRelate(..) => {}
114115

115116
// We need to search through *all* WellFormed predicates

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub fn expand_trait_aliases<'tcx>(
7676
| ty::ClauseKind::ConstArgHasType(_, _)
7777
| ty::ClauseKind::WellFormed(_)
7878
| ty::ClauseKind::ConstEvaluatable(_)
79+
| ty::ClauseKind::UnstableFeature(_)
7980
| ty::ClauseKind::HostEffect(..) => {}
8081
}
8182
}

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub fn clause_obligations<'tcx>(
197197
ty::ClauseKind::ConstEvaluatable(ct) => {
198198
wf.add_wf_preds_for_term(ct.into());
199199
}
200+
ty::ClauseKind::UnstableFeature(_) => {}
200201
}
201202

202203
wf.normalize(infcx)
@@ -1087,6 +1088,7 @@ pub fn object_region_bounds<'tcx>(
10871088
| ty::ClauseKind::Projection(_)
10881089
| ty::ClauseKind::ConstArgHasType(_, _)
10891090
| ty::ClauseKind::WellFormed(_)
1091+
| ty::ClauseKind::UnstableFeature(_)
10901092
| ty::ClauseKind::ConstEvaluatable(_) => None,
10911093
}
10921094
})

compiler/rustc_traits/src/normalize_erasing_regions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
5757
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
5858
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
5959
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
60+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
6061
| ty::PredicateKind::NormalizesTo(..)
6162
| ty::PredicateKind::AliasRelate(..)
6263
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))

compiler/rustc_type_ir/src/elaborate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ impl<I: Interner, O: Elaboratable<I>> Elaborator<I, O> {
200200
ty::ClauseKind::ConstArgHasType(..) => {
201201
// Nothing to elaborate
202202
}
203+
ty::ClauseKind::UnstableFeature(_) => {
204+
// Nothing to elaborate
205+
}
203206
}
204207
}
205208
}

compiler/rustc_type_ir/src/flags.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ impl<I: Interner> FlagComputation<I> {
401401
self.add_const(expected);
402402
self.add_const(found);
403403
}
404-
ty::PredicateKind::Ambiguous => {}
405404
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term }) => {
406405
self.add_alias_term(alias);
407406
self.add_term(term);
@@ -410,6 +409,8 @@ impl<I: Interner> FlagComputation<I> {
410409
self.add_term(t1);
411410
self.add_term(t2);
412411
}
412+
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
413+
| ty::PredicateKind::Ambiguous => {}
413414
}
414415
}
415416

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ pub trait Features<I: Interner>: Copy {
583583
fn coroutine_clone(self) -> bool;
584584

585585
fn associated_const_equality(self) -> bool;
586+
587+
fn impl_stability(self) -> bool;
588+
589+
fn enabled(self, symbol: I::Symbol) -> bool;
586590
}
587591

588592
pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {

compiler/rustc_type_ir/src/interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub trait Interner:
103103
type ParamTy: Copy + Debug + Hash + Eq + ParamLike;
104104
type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
105105
type PlaceholderTy: PlaceholderLike;
106+
type Symbol: Copy + Hash + PartialEq + Eq + TypeFoldable<Self> + TypeVisitable<Self>;
106107

107108
// Things stored inside of tys
108109
type ErrorGuaranteed: Copy + Debug + Hash + Eq;

compiler/rustc_type_ir/src/predicate_kind.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub enum ClauseKind<I: Interner> {
4646
/// corresponding trait clause; this just enforces the *constness* of that
4747
/// implementation.
4848
HostEffect(ty::HostEffectPredicate<I>),
49+
50+
/// Support marking impl as unstable.
51+
UnstableFeature(I::Symbol),
4952
}
5053

5154
#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)]
@@ -134,6 +137,9 @@ impl<I: Interner> fmt::Debug for ClauseKind<I> {
134137
ClauseKind::ConstEvaluatable(ct) => {
135138
write!(f, "ConstEvaluatable({ct:?})")
136139
}
140+
ClauseKind::UnstableFeature(feature_name) => {
141+
write!(f, "UnstableFeature({feature_name:?})")
142+
}
137143
}
138144
}
139145
}

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ pub(crate) fn clean_predicate<'tcx>(
397397
ty::ClauseKind::ConstEvaluatable(..)
398398
| ty::ClauseKind::WellFormed(..)
399399
| ty::ClauseKind::ConstArgHasType(..)
400+
| ty::ClauseKind::UnstableFeature(..)
400401
// FIXME(const_trait_impl): We can probably use this `HostEffect` pred to render `~const`.
401402
| ty::ClauseKind::HostEffect(_) => None,
402403
}

0 commit comments

Comments
 (0)