@@ -5,7 +5,7 @@ use if_chain::if_chain;
5
5
use rustc_ast:: ast:: { self , LitFloatType , LitKind } ;
6
6
use rustc_data_structures:: sync:: Lrc ;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
8
- use rustc_hir:: { BinOp , BinOpKind , Block , Expr , ExprKind , HirId , QPath , UnOp } ;
8
+ use rustc_hir:: { BinOp , BinOpKind , Block , Expr , ExprKind , HirId , Item , ItemKind , Node , QPath , UnOp } ;
9
9
use rustc_lint:: LateContext ;
10
10
use rustc_middle:: mir:: interpret:: Scalar ;
11
11
use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
@@ -400,6 +400,22 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
400
400
let res = self . typeck_results . qpath_res ( qpath, id) ;
401
401
match res {
402
402
Res :: Def ( DefKind :: Const | DefKind :: AssocConst , def_id) => {
403
+ // Check if this constant is based on `cfg!(..)`,
404
+ // which is NOT constant for our purposes.
405
+ if let Some ( node) = self . lcx . tcx . hir ( ) . get_if_local ( def_id) &&
406
+ let Node :: Item ( & Item {
407
+ kind : ItemKind :: Const ( _, body_id) ,
408
+ ..
409
+ } ) = node &&
410
+ let Node :: Expr ( & Expr {
411
+ kind : ExprKind :: Lit ( _) ,
412
+ span,
413
+ ..
414
+ } ) = self . lcx . tcx . hir ( ) . get ( body_id. hir_id ) &&
415
+ is_direct_expn_of ( span, "cfg" ) . is_some ( ) {
416
+ return None ;
417
+ }
418
+
403
419
let substs = self . typeck_results . node_substs ( id) ;
404
420
let substs = if self . substs . is_empty ( ) {
405
421
substs
0 commit comments