Skip to content

Commit 58f8b56

Browse files
committed
Lower the attribute to UnstableFeature predicate
1 parent 0bc5160 commit 58f8b56

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::assert_matches::assert_matches;
22

33
use hir::Node;
4+
use rustc_attr_data_structures::{AttributeKind, find_attr};
45
use rustc_data_structures::fx::FxIndexSet;
56
use rustc_hir as hir;
67
use rustc_hir::def::DefKind;
@@ -318,6 +319,16 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
318319
predicates.extend(const_evaluatable_predicates_of(tcx, def_id, &predicates));
319320
}
320321

322+
let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
323+
let allow_unstable_feature_attr =
324+
find_attr!(attrs, AttributeKind::AllowUnstableFeature(i) => i)
325+
.map(|i| i.as_slice())
326+
.unwrap_or_default();
327+
328+
for (feat_name, span) in allow_unstable_feature_attr {
329+
predicates.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span));
330+
}
331+
321332
let mut predicates: Vec<_> = predicates.into_iter().collect();
322333

323334
// Subtle: before we store the predicates into the tcx, we
@@ -747,6 +758,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
747758
ty::ClauseKind::RegionOutlives(_)
748759
| ty::ClauseKind::ConstArgHasType(_, _)
749760
| ty::ClauseKind::WellFormed(_)
761+
| ty::ClauseKind::UnstableFeature(_)
750762
| ty::ClauseKind::ConstEvaluatable(_) => {
751763
bug!(
752764
"unexpected non-`Self` predicate when computing \
@@ -774,6 +786,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
774786
| ty::ClauseKind::ConstArgHasType(_, _)
775787
| ty::ClauseKind::WellFormed(_)
776788
| ty::ClauseKind::ConstEvaluatable(_)
789+
| ty::ClauseKind::UnstableFeature(_)
777790
| ty::ClauseKind::HostEffect(..) => {
778791
bug!(
779792
"unexpected non-`Self` predicate when computing \

0 commit comments

Comments
 (0)