Skip to content

Commit 98216fb

Browse files
committed
Implement other logics
1 parent 0d5693b commit 98216fb

File tree

29 files changed

+70
-10
lines changed

29 files changed

+70
-10
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ 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};
18-
use crate::attributes::codegen_attrs::{
19-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TrackCallerParser,
17+
use crate::attributes::allow_unstable::{
18+
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
2019
};
20+
use crate::attributes::codegen_attrs::{ColdParser, NakedParser, NoMangleParser, OptimizeParser};
2121
use crate::attributes::confusables::ConfusablesParser;
2222
use crate::attributes::deprecation::DeprecationParser;
2323
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -109,6 +109,7 @@ attribute_parsers!(
109109
Combine<AllowConstFnUnstableParser>,
110110
Combine<AllowInternalUnstableParser>,
111111
Combine<ReprParser>,
112+
Combine<UnstableFeatureBoundParser>,
112113
// tidy-alphabetical-end
113114

114115
// tidy-alphabetical-start

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
683683
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
684684
EncodeCrossCrate::Yes
685685
),
686+
ungated!(
687+
unstable_feature_bound, Normal, template!(Word, List: "feat1, feat2, ..."),
688+
DuplicatesOk, EncodeCrossCrate::No,
689+
),
686690
ungated!(
687691
rustc_const_unstable, Normal, template!(List: r#"feature = "name""#),
688692
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
@@ -2310,12 +2310,16 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23102310
let implied_obligations = traits::elaborate(tcx, predicates_with_span);
23112311

23122312
for (pred, obligation_span) in implied_obligations {
2313-
// We lower empty bounds like `Vec<dyn Copy>:` as
2314-
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2315-
// regular WF checking
2316-
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
2317-
continue;
2313+
match pred.kind().skip_binder() {
2314+
// We lower empty bounds like `Vec<dyn Copy>:` as
2315+
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2316+
// regular WF checking
2317+
ty::ClauseKind::WellFormed(..)
2318+
// Unstable feature goals cannot be proven in an empty environment so skip them
2319+
| ty::ClauseKind::UnstableFeature(..) => continue,
2320+
_ => {}
23182321
}
2322+
23192323
// Match the existing behavior.
23202324
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
23212325
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
@@ -1526,8 +1526,9 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15261526
ClauseKind::TypeOutlives(..) |
15271527
ClauseKind::RegionOutlives(..) => "lifetime",
15281528

1529+
ClauseKind::UnstableFeature(_)
15291530
// `ConstArgHasType` is never global as `ct` is always a param
1530-
ClauseKind::ConstArgHasType(..)
1531+
| ClauseKind::ConstArgHasType(..)
15311532
// Ignore projections, as they can only be global
15321533
// if the trait bound is global
15331534
| 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;
@@ -833,6 +834,13 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
833834
fn associated_const_equality(self) -> bool {
834835
self.associated_const_equality()
835836
}
837+
838+
fn feature_bound_holds_in_crate(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
839+
// We don't consider feature bounds to hold in the crate when `staged_api` feature is
840+
// enabled, even if it is enabled through `#[feature]`.
841+
// This is to prevent accidentally leaking unstable APIs to stable.
842+
!self.staged_api() && self.enabled(symbol)
843+
}
836844
}
837845

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

0 commit comments

Comments
 (0)