mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 09:13:07 +03:00
fix: match_bool wrongly unmangled macros
This commit is contained in:
@@ -25,8 +25,9 @@ pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>]
|
||||
"`match` on a boolean expression",
|
||||
move |diag| {
|
||||
let mut app = Applicability::MachineApplicable;
|
||||
let ctxt = expr.span.ctxt();
|
||||
let test_sugg = if let PatKind::Expr(arm_bool) = arms[0].pat.kind {
|
||||
let test = Sugg::hir_with_applicability(cx, scrutinee, "_", &mut app);
|
||||
let test = Sugg::hir_with_context(cx, scrutinee, ctxt, "_", &mut app);
|
||||
if let PatExprKind::Lit { lit, .. } = arm_bool.kind {
|
||||
match &lit.node {
|
||||
LitKind::Bool(true) => Some(test),
|
||||
@@ -36,7 +37,7 @@ pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>]
|
||||
.map(|test| {
|
||||
if let Some(guard) = &arms[0]
|
||||
.guard
|
||||
.map(|g| Sugg::hir_with_applicability(cx, g, "_", &mut app))
|
||||
.map(|g| Sugg::hir_with_context(cx, g, ctxt, "_", &mut app))
|
||||
{
|
||||
test.and(guard)
|
||||
} else {
|
||||
|
||||
@@ -74,4 +74,15 @@ fn issue15351() {
|
||||
}
|
||||
}
|
||||
|
||||
fn wrongly_unmangled_macros() {
|
||||
macro_rules! test_expr {
|
||||
($val:expr) => {
|
||||
($val + 1) > 0
|
||||
};
|
||||
}
|
||||
|
||||
let x = 5;
|
||||
if test_expr!(x) { 1 } else { 0 };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -126,4 +126,19 @@ fn issue15351() {
|
||||
}
|
||||
}
|
||||
|
||||
fn wrongly_unmangled_macros() {
|
||||
macro_rules! test_expr {
|
||||
($val:expr) => {
|
||||
($val + 1) > 0
|
||||
};
|
||||
}
|
||||
|
||||
let x = 5;
|
||||
match test_expr!(x) {
|
||||
//~^ match_bool
|
||||
true => 1,
|
||||
false => 0,
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -183,5 +183,15 @@ LL + break 'a;
|
||||
LL + } }
|
||||
|
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: `match` on a boolean expression
|
||||
--> tests/ui/match_bool.rs:137:5
|
||||
|
|
||||
LL | / match test_expr!(x) {
|
||||
LL | |
|
||||
LL | | true => 1,
|
||||
LL | | false => 0,
|
||||
LL | | };
|
||||
| |_____^ help: consider using an `if`/`else` expression: `if test_expr!(x) { 1 } else { 0 }`
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user