@@ -5,7 +5,7 @@ use if_chain::if_chain;
55use rustc_ast:: ast:: { self , LitFloatType , LitKind } ;
66use rustc_data_structures:: sync:: Lrc ;
77use 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 } ;
99use rustc_lint:: LateContext ;
1010use rustc_middle:: mir:: interpret:: Scalar ;
1111use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
@@ -400,6 +400,22 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
400400 let res = self . typeck_results . qpath_res ( qpath, id) ;
401401 match res {
402402 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+
403419 let substs = self . typeck_results . node_substs ( id) ;
404420 let substs = if self . substs . is_empty ( ) {
405421 substs
0 commit comments