fix: match_ok_err wrongly unmangled macros

This commit is contained in:
Linshu Yang
2026-01-02 23:20:24 +00:00
parent 9d08eb487b
commit 908860ed10
4 changed files with 37 additions and 2 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ fn apply_lint(cx: &LateContext<'_>, expr: &Expr<'_>, scrutinee: &Expr<'_>, is_ok
} else {
Applicability::MachineApplicable
};
let scrut = Sugg::hir_with_applicability(cx, scrutinee, "..", &mut app).maybe_paren();
let scrut = Sugg::hir_with_context(cx, scrutinee, expr.span.ctxt(), "..", &mut app).maybe_paren();
let scrutinee_ty = cx.typeck_results().expr_ty(scrutinee);
let (_, _, mutability) = peel_and_count_ty_refs(scrutinee_ty);
+10
View File
@@ -127,3 +127,13 @@ mod issue15051 {
result_with_ref_mut(x).as_mut().ok()
}
}
fn wrongly_unmangled_macros() {
macro_rules! test_expr {
($val:expr) => {
Ok::<i32, ()>($val)
};
}
let _ = test_expr!(42).ok();
}
+14
View File
@@ -177,3 +177,17 @@ fn from_fn_mut(x: &mut Container) -> Option<&mut bool> {
}
}
}
fn wrongly_unmangled_macros() {
macro_rules! test_expr {
($val:expr) => {
Ok::<i32, ()>($val)
};
}
let _ = match test_expr!(42) {
//~^ manual_ok_err
Ok(v) => Some(v),
Err(_) => None,
};
}
+12 -1
View File
@@ -141,5 +141,16 @@ LL | | Err(_) => None,
LL | | }
| |_________^ help: replace with: `result_with_ref_mut(x).as_mut().ok()`
error: aborting due to 12 previous errors
error: manual implementation of `ok`
--> tests/ui/manual_ok_err.rs:188:13
|
LL | let _ = match test_expr!(42) {
| _____________^
LL | |
LL | | Ok(v) => Some(v),
LL | | Err(_) => None,
LL | | };
| |_____^ help: replace with: `test_expr!(42).ok()`
error: aborting due to 13 previous errors