Skip to content

Commit f59f0e1

Browse files
committed
fix equatable_if_let: FP in const context
1 parent 355e4ba commit f59f0e1

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clippy_lints/src/equatable_if_let.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::is_in_const_context;
23
use clippy_utils::source::snippet_with_context;
34
use clippy_utils::ty::implements_trait;
45
use rustc_errors::Applicability;
@@ -105,6 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality {
105106
if let ExprKind::Let(let_expr) = expr.kind
106107
&& unary_pattern(let_expr.pat)
107108
&& !expr.span.in_external_macro(cx.sess().source_map())
109+
&& !is_in_const_context(cx)
108110
{
109111
let exp_ty = cx.typeck_results().expr_ty(let_expr.init);
110112
let pat_ty = cx.typeck_results().pat_ty(let_expr.pat);

tests/ui/equatable_if_let.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,8 @@ mod issue8710 {
139139
}
140140
}
141141
}
142+
143+
fn issue15376() {
144+
// PartialEq is not stable in consts yet
145+
const _: u32 = if let Some(true) = None { 0 } else { 1 };
146+
}

tests/ui/equatable_if_let.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,8 @@ mod issue8710 {
139139
}
140140
}
141141
}
142+
143+
fn issue15376() {
144+
// PartialEq is not stable in consts yet
145+
const _: u32 = if let Some(true) = None { 0 } else { 1 };
146+
}

0 commit comments

Comments
 (0)