File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -643,16 +643,38 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
643
643
if let Some ( node) = self . tcx . hir_get_if_local ( def_id)
644
644
&& let Node :: Item ( Item {
645
645
kind : ItemKind :: Const ( .., body_id) ,
646
+ owner_id,
646
647
..
647
648
} ) = node
648
- && let Node :: Expr ( Expr {
649
+ {
650
+ // check for `const C: _ = cfg!(foo);`
651
+ if let Node :: Expr ( Expr {
649
652
kind : ExprKind :: Lit ( _) ,
650
653
span,
651
654
..
652
655
} ) = self . tcx . hir_node ( body_id. hir_id )
653
- && is_direct_expn_of ( * span, sym:: cfg) . is_some ( )
654
- {
655
- return None ;
656
+ && is_direct_expn_of ( * span, sym:: cfg) . is_some ( )
657
+ {
658
+ return None ;
659
+ }
660
+
661
+ // check for:
662
+ // ```
663
+ // #[cfg(foo)]
664
+ // const C: _ = _;
665
+ // ```
666
+ //
667
+ // NOTE: it shouldn't be possible to have `#[cfg]` applied to the initializer, because e.g.
668
+ // something like this wouldn't work:
669
+ // const C: _ = {
670
+ // #[cfg(foo)]
671
+ // 1
672
+ // #[cfg(bar)]
673
+ // 2
674
+ // };
675
+ if self . tcx . has_attr ( owner_id. def_id , sym:: cfg_trace) {
676
+ return None ;
677
+ }
656
678
}
657
679
658
680
let args = self . typeck . node_args ( id) ;
Original file line number Diff line number Diff line change @@ -86,3 +86,15 @@ fn ineffective() {
86
86
x | 3 > 4 ; // not an error (yet), better written as x >= 4
87
87
x | 4 <= 19 ;
88
88
}
89
+
90
+ fn issue14167 ( ) {
91
+ #[ cfg( test) ]
92
+ const FORCE_DYNAMIC_DETECTION : u8 = 0b00010000 ;
93
+
94
+ #[ cfg( not( test) ) ]
95
+ const FORCE_DYNAMIC_DETECTION : u8 = 0b0000000 ;
96
+
97
+ const CAPS_STATIC : u8 = 0b00001111 ;
98
+
99
+ CAPS_STATIC & FORCE_DYNAMIC_DETECTION == 0 ;
100
+ }
You can’t perform that action at this time.
0 commit comments