@@ -147,7 +147,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
147147 // Propagate unstability. This can happen even for non-staged-api crates in case
148148 // -Zforce-unstable-if-unmarked is set.
149149 if let Some ( stab) = self . parent_stab {
150- if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
150+ if inherit_deprecation. yes ( ) && stab. is_unstable ( ) {
151151 self . index . stab_map . insert ( def_id, stab) ;
152152 }
153153 }
@@ -190,7 +190,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
190190 if const_stab. is_none ( ) {
191191 debug ! ( "annotate: const_stab not found, parent = {:?}" , self . parent_const_stab) ;
192192 if let Some ( parent) = self . parent_const_stab {
193- if parent. level . is_unstable ( ) {
193+ if parent. is_const_unstable ( ) {
194194 self . index . const_stab_map . insert ( def_id, parent) ;
195195 }
196196 }
@@ -272,9 +272,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
272272 if stab. is_none ( ) {
273273 debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
274274 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 ( ) {
278276 self . index . stab_map . insert ( def_id, stab) ;
279277 }
280278 }
@@ -532,7 +530,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
532530 return ;
533531 }
534532
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 ( ) ) ;
536535 let is_stable = self
537536 . tcx
538537 . lookup_stability ( def_id)
@@ -710,16 +709,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
710709 // For implementations of traits, check the stability of each item
711710 // individually as it's possible to have a stable trait with unstable
712711 // 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+
715724 // If this impl block has an #[unstable] attribute, give an
716725 // error if all involved types and traits are stable, because
717726 // it will have no effect.
718727 // 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 {
723729 let mut c = CheckTraitImplStable { tcx : self . tcx , fully_stable : true } ;
724730 c. visit_ty ( self_ty) ;
725731 c. visit_trait_ref ( t) ;
@@ -735,6 +741,19 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
735741 ) ;
736742 }
737743 }
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+ }
738757 }
739758
740759 for impl_item_ref in * items {
0 commit comments