mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
fix no_effect lint
This commit is contained in:
parent
77ed899941
commit
bb69e60b30
2 changed files with 11 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::hir::def::{Def, PathResolution};
|
||||
use rustc::hir::{Expr, Expr_, Stmt, StmtSemi};
|
||||
use rustc::hir::{Expr, Expr_, Stmt, StmtSemi, BlockCheckMode, UnsafeSource};
|
||||
use utils::{in_macro, span_lint, snippet_opt, span_lint_and_then};
|
||||
use std::ops::Deref;
|
||||
|
||||
|
@ -140,11 +140,11 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Exp
|
|||
}
|
||||
Expr_::ExprBlock(ref block) => {
|
||||
if block.stmts.is_empty() {
|
||||
block.expr.as_ref().and_then(|e| if e.span == expr.span {
|
||||
block.expr.as_ref().and_then(|e| match block.rules {
|
||||
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None,
|
||||
BlockCheckMode::DefaultBlock => Some(vec![&**e]),
|
||||
// in case of compiler-inserted signaling blocks
|
||||
reduce_expression(cx, e)
|
||||
} else {
|
||||
Some(vec![e])
|
||||
_ => reduce_expression(cx, e),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -18,6 +18,8 @@ enum Enum {
|
|||
fn get_number() -> i32 { 0 }
|
||||
fn get_struct() -> Struct { Struct { field: 0 } }
|
||||
|
||||
unsafe fn unsafe_fn() -> i32 { 0 }
|
||||
|
||||
fn main() {
|
||||
let s = get_struct();
|
||||
let s2 = get_struct();
|
||||
|
@ -50,6 +52,7 @@ fn main() {
|
|||
|
||||
// Do not warn
|
||||
get_number();
|
||||
unsafe { unsafe_fn() };
|
||||
|
||||
Tuple(get_number()); //~ERROR statement can be reduced
|
||||
//~^HELP replace it with
|
||||
|
@ -105,4 +108,7 @@ fn main() {
|
|||
[42; 55][get_number() as usize]; //~ERROR statement can be reduced
|
||||
//~^HELP replace it with
|
||||
//~|SUGGESTION [42; 55];get_number() as usize;
|
||||
{get_number()}; //~ERROR statement can be reduced
|
||||
//~^HELP replace it with
|
||||
//~|SUGGESTION get_number();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue