|
1 | 1 | use std::assert_matches::assert_matches;
|
2 | 2 |
|
3 | 3 | use hir::Node;
|
| 4 | +use rustc_attr_data_structures::{AttributeKind, find_attr}; |
4 | 5 | use rustc_data_structures::fx::FxIndexSet;
|
5 | 6 | use rustc_hir as hir;
|
6 | 7 | use rustc_hir::def::DefKind;
|
@@ -333,6 +334,19 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
333 | 334 | predicates.extend(const_evaluatable_predicates_of(tcx, def_id, &predicates));
|
334 | 335 | }
|
335 | 336 |
|
| 337 | + let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id)); |
| 338 | + // FIXME(staged_api): We might want to look at the normal stability attributes too but |
| 339 | + // first we would need a way to let std/core use APIs with unstable feature bounds from |
| 340 | + // within stable APIs. |
| 341 | + let allow_unstable_feature_attr = |
| 342 | + find_attr!(attrs, AttributeKind::UnstableFeatureBound(i) => i) |
| 343 | + .map(|i| i.as_slice()) |
| 344 | + .unwrap_or_default(); |
| 345 | + |
| 346 | + for (feat_name, span) in allow_unstable_feature_attr { |
| 347 | + predicates.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span)); |
| 348 | + } |
| 349 | + |
336 | 350 | let mut predicates: Vec<_> = predicates.into_iter().collect();
|
337 | 351 |
|
338 | 352 | // Subtle: before we store the predicates into the tcx, we
|
@@ -764,6 +778,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
|
764 | 778 | ty::ClauseKind::RegionOutlives(_)
|
765 | 779 | | ty::ClauseKind::ConstArgHasType(_, _)
|
766 | 780 | | ty::ClauseKind::WellFormed(_)
|
| 781 | + | ty::ClauseKind::UnstableFeature(_) |
767 | 782 | | ty::ClauseKind::ConstEvaluatable(_) => {
|
768 | 783 | bug!(
|
769 | 784 | "unexpected non-`Self` predicate when computing \
|
@@ -791,6 +806,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
|
791 | 806 | | ty::ClauseKind::ConstArgHasType(_, _)
|
792 | 807 | | ty::ClauseKind::WellFormed(_)
|
793 | 808 | | ty::ClauseKind::ConstEvaluatable(_)
|
| 809 | + | ty::ClauseKind::UnstableFeature(_) |
794 | 810 | | ty::ClauseKind::HostEffect(..) => {
|
795 | 811 | bug!(
|
796 | 812 | "unexpected non-`Self` predicate when computing \
|
|
0 commit comments