Skip to content

Commit a28329a

Browse files
committed
Implement other logics
1 parent 723f09b commit a28329a

File tree

29 files changed

+70
-8
lines changed

29 files changed

+70
-8
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, HirI
1414
use rustc_session::Session;
1515
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

17-
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
17+
use crate::attributes::allow_unstable::{
18+
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
19+
};
1820
use crate::attributes::codegen_attrs::{ColdParser, NakedParser, NoMangleParser, OptimizeParser};
1921
use crate::attributes::confusables::ConfusablesParser;
2022
use crate::attributes::deprecation::DeprecationParser;
@@ -106,6 +108,7 @@ attribute_parsers!(
106108
Combine<AllowConstFnUnstableParser>,
107109
Combine<AllowInternalUnstableParser>,
108110
Combine<ReprParser>,
111+
Combine<UnstableFeatureBoundParser>,
109112
// tidy-alphabetical-end
110113

111114
// tidy-alphabetical-start

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
675675
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
676676
EncodeCrossCrate::Yes
677677
),
678+
ungated!(
679+
unstable_feature_bound, Normal, template!(Word, List: "feat1, feat2, ..."),
680+
DuplicatesOk, EncodeCrossCrate::No,
681+
),
678682
ungated!(
679683
rustc_const_unstable, Normal, template!(List: r#"feature = "name""#),
680684
DuplicatesOk, EncodeCrossCrate::Yes

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,12 +2304,16 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23042304
let implied_obligations = traits::elaborate(tcx, predicates_with_span);
23052305

23062306
for (pred, obligation_span) in implied_obligations {
2307-
// We lower empty bounds like `Vec<dyn Copy>:` as
2308-
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2309-
// regular WF checking
2310-
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
2311-
continue;
2307+
match pred.kind().skip_binder() {
2308+
// We lower empty bounds like `Vec<dyn Copy>:` as
2309+
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2310+
// regular WF checking
2311+
ty::ClauseKind::WellFormed(..)
2312+
// Unstable feature goals cannot be proven in an empty environment so skip them
2313+
| ty::ClauseKind::UnstableFeature(..) => continue,
2314+
_ => {}
23122315
}
2316+
23132317
// Match the existing behavior.
23142318
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
23152319
let pred = self.normalize(span, None, pred);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
776776
ty::ClauseKind::RegionOutlives(_)
777777
| ty::ClauseKind::ConstArgHasType(_, _)
778778
| ty::ClauseKind::WellFormed(_)
779+
| ty::ClauseKind::UnstableFeature(_)
779780
| ty::ClauseKind::ConstEvaluatable(_) => {
780781
bug!(
781782
"unexpected non-`Self` predicate when computing \
@@ -803,6 +804,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
803804
| ty::ClauseKind::ConstArgHasType(_, _)
804805
| ty::ClauseKind::WellFormed(_)
805806
| ty::ClauseKind::ConstEvaluatable(_)
807+
| ty::ClauseKind::UnstableFeature(_)
806808
| ty::ClauseKind::HostEffect(..) => {
807809
bug!(
808810
"unexpected non-`Self` predicate when computing \

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
@@ -54,6 +54,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5454
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
5555
| ty::PredicateKind::ConstEquate(..)
5656
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
57+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
5758
| ty::PredicateKind::Ambiguous => false,
5859
}
5960
}

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
@@ -1524,8 +1524,9 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15241524
ClauseKind::TypeOutlives(..) |
15251525
ClauseKind::RegionOutlives(..) => "lifetime",
15261526

1527+
ClauseKind::UnstableFeature(_)
15271528
// `ConstArgHasType` is never global as `ct` is always a param
1528-
ClauseKind::ConstArgHasType(..)
1529+
| ClauseKind::ConstArgHasType(..)
15291530
// Ignore projections, as they can only be global
15301531
// if the trait bound is global
15311532
| ClauseKind::Projection(..)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
137137
type FnInputTys = &'tcx [Ty<'tcx>];
138138
type ParamTy = ParamTy;
139139
type BoundTy = ty::BoundTy;
140+
type Symbol = Symbol;
140141

141142
type PlaceholderTy = ty::PlaceholderType;
142143
type ErrorGuaranteed = ErrorGuaranteed;
@@ -834,6 +835,13 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
834835
fn associated_const_equality(self) -> bool {
835836
self.associated_const_equality()
836837
}
838+
839+
fn feature_bound_holds_in_crate(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
840+
// We don't consider feature bounds to hold in the crate when `staged_api` feature is
841+
// enabled, even if it is enabled through `#[feature]`.
842+
// This is to prevent accidentally leaking unstable APIs to stable.
843+
!self.staged_api() && self.enabled(symbol)
844+
}
837845
}
838846

839847
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
@@ -3276,6 +3276,7 @@ define_print! {
32763276
ty::ClauseKind::ConstEvaluatable(ct) => {
32773277
p!("the constant `", print(ct), "` can be evaluated")
32783278
}
3279+
ty::ClauseKind::UnstableFeature(symbol) => p!("unstable feature: ", write("`{}`", symbol)),
32793280
}
32803281
}
32813282

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
@@ -605,6 +605,9 @@ where
605605
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
606606
self.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })
607607
}
608+
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
609+
self.compute_unstable_feature_goal(param_env, symbol)
610+
}
608611
ty::PredicateKind::Subtype(predicate) => {
609612
self.compute_subtype_goal(Goal { param_env, predicate })
610613
}

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,7 @@ symbols! {
22792279
unsized_locals,
22802280
unsized_tuple_coercion,
22812281
unstable,
2282+
unstable_feature_bound,
22822283
unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
22832284
unstable location; did you mean to load this crate \
22842285
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
@@ -647,6 +647,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
647647
| ty::PredicateKind::ConstEquate { .. }
648648
// Ambiguous predicates should never error
649649
| ty::PredicateKind::Ambiguous
650+
// We never return Err when proving UnstableFeature goal.
651+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature{ .. })
650652
| ty::PredicateKind::NormalizesTo { .. }
651653
| ty::PredicateKind::AliasRelate { .. }
652654
| 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
@@ -80,6 +80,7 @@ pub fn expand_trait_aliases<'tcx>(
8080
| ty::ClauseKind::ConstArgHasType(_, _)
8181
| ty::ClauseKind::WellFormed(_)
8282
| ty::ClauseKind::ConstEvaluatable(_)
83+
| ty::ClauseKind::UnstableFeature(_)
8384
| ty::ClauseKind::HostEffect(..) => {}
8485
}
8586
}

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)
@@ -1095,6 +1096,7 @@ pub fn object_region_bounds<'tcx>(
10951096
| ty::ClauseKind::Projection(_)
10961097
| ty::ClauseKind::ConstArgHasType(_, _)
10971098
| ty::ClauseKind::WellFormed(_)
1099+
| ty::ClauseKind::UnstableFeature(_)
10981100
| ty::ClauseKind::ConstEvaluatable(_) => None,
10991101
}
11001102
})

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
@@ -234,6 +234,9 @@ impl<I: Interner, O: Elaboratable<I>> Elaborator<I, O> {
234234
ty::ClauseKind::ConstArgHasType(..) => {
235235
// Nothing to elaborate
236236
}
237+
ty::ClauseKind::UnstableFeature(_) => {
238+
// Nothing to elaborate
239+
}
237240
}
238241
}
239242
}

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(_sym)) => {}
413+
ty::PredicateKind::Ambiguous => {}
413414
}
414415
}
415416

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ pub trait Features<I: Interner>: Copy {
592592
fn coroutine_clone(self) -> bool;
593593

594594
fn associated_const_equality(self) -> bool;
595+
596+
fn feature_bound_holds_in_crate(self, symbol: I::Symbol) -> bool;
595597
}
596598

597599
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
@@ -106,6 +106,7 @@ pub trait Interner:
106106
type ParamTy: ParamLike;
107107
type BoundTy: BoundVarLike<Self>;
108108
type PlaceholderTy: PlaceholderLike<Self, Bound = Self::BoundTy>;
109+
type Symbol: Copy + Hash + PartialEq + Eq + TypeFoldable<Self> + TypeVisitable<Self>;
109110

110111
// Things stored inside of tys
111112
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
@@ -395,6 +395,7 @@ pub(crate) fn clean_predicate<'tcx>(
395395
ty::ClauseKind::ConstEvaluatable(..)
396396
| ty::ClauseKind::WellFormed(..)
397397
| ty::ClauseKind::ConstArgHasType(..)
398+
| ty::ClauseKind::UnstableFeature(..)
398399
// FIXME(const_trait_impl): We can probably use this `HostEffect` pred to render `~const`.
399400
| ty::ClauseKind::HostEffect(_) => None,
400401
}

0 commit comments

Comments
 (0)