Skip to content

Commit 2563910

Browse files
committed
Don't treat cfg!() as a constant.
1 parent 5f746a1 commit 2563910

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clippy_utils/src/consts.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::float_cmp)]
22

3-
use crate::{clip, sext, unsext};
3+
use crate::{clip, is_direct_expn_of, sext, unsext};
44
use if_chain::if_chain;
55
use rustc_ast::ast::{self, LitFloatType, LitKind};
66
use rustc_data_structures::sync::Lrc;
@@ -230,7 +230,13 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
230230
match e.kind {
231231
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)),
232232
ExprKind::Block(block, _) => self.block(block),
233-
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e))),
233+
ExprKind::Lit(ref lit) => {
234+
if is_direct_expn_of(e.span, "cfg").is_some() {
235+
None
236+
} else {
237+
Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
238+
}
239+
},
234240
ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),
235241
ExprKind::Tup(tup) => self.multi(tup).map(Constant::Tuple),
236242
ExprKind::Repeat(value, _) => {

0 commit comments

Comments
 (0)