@@ -16,6 +16,7 @@ use rustc_middle::middle::stability::{DeprecationEntry, Index};
16
16
use rustc_middle:: ty:: query:: Providers ;
17
17
use rustc_middle:: ty:: TyCtxt ;
18
18
use rustc_session:: lint;
19
+ use rustc_session:: lint:: builtin:: INEFFECTIVE_UNSTABLE_TRAIT_IMPL ;
19
20
use rustc_session:: parse:: feature_err;
20
21
use rustc_session:: Session ;
21
22
use rustc_span:: symbol:: { sym, Symbol } ;
@@ -539,27 +540,33 @@ impl Visitor<'tcx> for Checker<'tcx> {
539
540
// individually as it's possible to have a stable trait with unstable
540
541
// items.
541
542
hir:: ItemKind :: Impl { of_trait : Some ( ref t) , self_ty, items, .. } => {
542
- // If this impl block has an #[unstable] attribute, give an
543
- // error if all involved types and traits are stable, because
544
- // it will have no effect.
545
- // See: https://github.com/rust-lang/rust/issues/55436
546
- if let ( Some ( Stability { level : attr:: Unstable { .. } , .. } ) , _) =
547
- attr:: find_stability ( & self . tcx . sess , & item. attrs , item. span )
548
- {
549
- let mut c = CheckTraitImplStable { tcx : self . tcx , fully_stable : true } ;
550
- c. visit_ty ( self_ty) ;
551
- c. visit_trait_ref ( t) ;
552
- if c. fully_stable {
553
- let span = item
554
- . attrs
555
- . iter ( )
556
- . find ( |a| a. has_name ( sym:: unstable) )
557
- . map_or ( item. span , |a| a. span ) ;
558
- self . tcx . sess . span_err (
559
- span,
560
- "An `#[unstable]` annotation here has no effect. \
561
- See issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information.",
562
- ) ;
543
+ if self . tcx . features ( ) . staged_api {
544
+ // If this impl block has an #[unstable] attribute, give an
545
+ // error if all involved types and traits are stable, because
546
+ // it will have no effect.
547
+ // See: https://github.com/rust-lang/rust/issues/55436
548
+ if let ( Some ( Stability { level : attr:: Unstable { .. } , .. } ) , _) =
549
+ attr:: find_stability ( & self . tcx . sess , & item. attrs , item. span )
550
+ {
551
+ let mut c = CheckTraitImplStable { tcx : self . tcx , fully_stable : true } ;
552
+ c. visit_ty ( self_ty) ;
553
+ c. visit_trait_ref ( t) ;
554
+ if c. fully_stable {
555
+ let span = item
556
+ . attrs
557
+ . iter ( )
558
+ . find ( |a| a. has_name ( sym:: unstable) )
559
+ . map_or ( item. span , |a| a. span ) ;
560
+ self . tcx . struct_span_lint_hir (
561
+ INEFFECTIVE_UNSTABLE_TRAIT_IMPL ,
562
+ item. hir_id ,
563
+ span,
564
+ |lint| lint. build (
565
+ "An `#[unstable]` annotation here has no effect. \
566
+ See issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information.",
567
+ ) . emit ( )
568
+ ) ;
569
+ }
563
570
}
564
571
}
565
572
0 commit comments