@@ -147,7 +147,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
147
147
// Propagate unstability. This can happen even for non-staged-api crates in case
148
148
// -Zforce-unstable-if-unmarked is set.
149
149
if let Some ( stab) = self . parent_stab {
150
- if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
150
+ if inherit_deprecation. yes ( ) && stab. is_unstable ( ) {
151
151
self . index . stab_map . insert ( def_id, stab) ;
152
152
}
153
153
}
@@ -190,7 +190,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
190
190
if const_stab. is_none ( ) {
191
191
debug ! ( "annotate: const_stab not found, parent = {:?}" , self . parent_const_stab) ;
192
192
if let Some ( parent) = self . parent_const_stab {
193
- if parent. level . is_unstable ( ) {
193
+ if parent. is_const_unstable ( ) {
194
194
self . index . const_stab_map . insert ( def_id, parent) ;
195
195
}
196
196
}
@@ -272,9 +272,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
272
272
if stab. is_none ( ) {
273
273
debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
274
274
if let Some ( stab) = self . parent_stab {
275
- if inherit_deprecation. yes ( ) && stab. level . is_unstable ( )
276
- || inherit_from_parent. yes ( )
277
- {
275
+ if inherit_deprecation. yes ( ) && stab. is_unstable ( ) || inherit_from_parent. yes ( ) {
278
276
self . index . stab_map . insert ( def_id, stab) ;
279
277
}
280
278
}
@@ -532,7 +530,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
532
530
return ;
533
531
}
534
532
535
- let is_const = self . tcx . is_const_fn ( def_id. to_def_id ( ) ) ;
533
+ let is_const = self . tcx . is_const_fn ( def_id. to_def_id ( ) )
534
+ || self . tcx . is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ;
536
535
let is_stable = self
537
536
. tcx
538
537
. lookup_stability ( def_id)
@@ -710,16 +709,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
710
709
// For implementations of traits, check the stability of each item
711
710
// individually as it's possible to have a stable trait with unstable
712
711
// items.
713
- hir:: ItemKind :: Impl ( hir:: Impl { of_trait : Some ( ref t) , self_ty, items, .. } ) => {
714
- if self . tcx . features ( ) . staged_api {
712
+ hir:: ItemKind :: Impl ( hir:: Impl {
713
+ of_trait : Some ( ref t) ,
714
+ self_ty,
715
+ items,
716
+ constness,
717
+ ..
718
+ } ) => {
719
+ let features = self . tcx . features ( ) ;
720
+ if features. staged_api {
721
+ let attrs = self . tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
722
+ let ( stab, const_stab) = attr:: find_stability ( & self . tcx . sess , attrs, item. span ) ;
723
+
715
724
// If this impl block has an #[unstable] attribute, give an
716
725
// error if all involved types and traits are stable, because
717
726
// it will have no effect.
718
727
// See: https://github.com/rust-lang/rust/issues/55436
719
- let attrs = self . tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
720
- if let ( Some ( ( Stability { level : attr:: Unstable { .. } , .. } , span) ) , _) =
721
- attr:: find_stability ( & self . tcx . sess , attrs, item. span )
722
- {
728
+ if let Some ( ( Stability { level : attr:: Unstable { .. } , .. } , span) ) = stab {
723
729
let mut c = CheckTraitImplStable { tcx : self . tcx , fully_stable : true } ;
724
730
c. visit_ty ( self_ty) ;
725
731
c. visit_trait_ref ( t) ;
@@ -735,6 +741,19 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
735
741
) ;
736
742
}
737
743
}
744
+
745
+ // `#![feature(const_trait_impl)]` is unstable, so any impl declared stable
746
+ // needs to have an error emitted.
747
+ if features. const_trait_impl
748
+ && * constness == hir:: Constness :: Const
749
+ && const_stab. map_or ( false , |( stab, _) | stab. is_const_stable ( ) )
750
+ {
751
+ self . tcx
752
+ . sess
753
+ . struct_span_err ( item. span , "trait implementations cannot be const stable yet" )
754
+ . note ( "see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information" )
755
+ . emit ( ) ;
756
+ }
738
757
}
739
758
740
759
for impl_item_ref in * items {
0 commit comments