mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Manage macros case + move to MaybeIncorrect when binding values
This commit is contained in:
parent
53094de08e
commit
00904cb100
1 changed files with 18 additions and 18 deletions
|
@ -285,7 +285,8 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// **Why is this bad?** Readability and needless complexity.
|
/// **Why is this bad?** Readability and needless complexity.
|
||||||
///
|
///
|
||||||
/// **Known problems:** None.
|
/// **Known problems:** Suggested replacements may be incorrect when `match`
|
||||||
|
/// is actually binding temporary value, bringing a 'dropped while borrowed' error.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -835,23 +836,22 @@ fn check_match_single_binding(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[A
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do we need to add ';' to suggestion ?
|
// Do we need to add ';' to suggestion ?
|
||||||
if_chain! {
|
match match_body.kind {
|
||||||
if let ExprKind::Block(block, _) = &arms[0].body.kind;
|
ExprKind::Block(block, _) => {
|
||||||
if block.stmts.len() == 1;
|
// macro + expr_ty(body) == ()
|
||||||
if let StmtKind::Semi(s) = block.stmts.get(0).unwrap().kind;
|
if block.span.from_expansion() && cx.tables.expr_ty(&match_body).is_unit() {
|
||||||
then {
|
snippet_body.push(';');
|
||||||
match s.kind {
|
|
||||||
ExprKind::Block(_, _) => (),
|
|
||||||
_ => {
|
|
||||||
// expr_ty(body) == ()
|
|
||||||
if cx.tables.expr_ty(&arms[0].body).is_unit() {
|
|
||||||
snippet_body.push(';');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
_ => {
|
||||||
|
// expr_ty(body) == ()
|
||||||
|
if cx.tables.expr_ty(&match_body).is_unit() {
|
||||||
|
snippet_body.push(';');
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut applicability = Applicability::MaybeIncorrect;
|
||||||
match arms[0].pat.kind {
|
match arms[0].pat.kind {
|
||||||
PatKind::Binding(..) | PatKind::Tuple(_, _) | PatKind::Struct(..) => {
|
PatKind::Binding(..) | PatKind::Tuple(_, _) | PatKind::Struct(..) => {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
|
@ -862,11 +862,11 @@ fn check_match_single_binding(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[A
|
||||||
"consider using `let` statement",
|
"consider using `let` statement",
|
||||||
format!(
|
format!(
|
||||||
"let {} = {};\n{}",
|
"let {} = {};\n{}",
|
||||||
snippet(cx, bind_names, ".."),
|
snippet_with_applicability(cx, bind_names, "..", &mut applicability),
|
||||||
snippet(cx, matched_vars, ".."),
|
snippet_with_applicability(cx, matched_vars, "..", &mut applicability),
|
||||||
snippet_body
|
snippet_body
|
||||||
),
|
),
|
||||||
Applicability::MachineApplicable,
|
applicability,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
PatKind::Wild => {
|
PatKind::Wild => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue