mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 01:05:39 +03:00
fix: match_ok_err wrongly unmangled macros
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user