mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Merge pull request #660 from mcarton/copies
Fix false positive for `ifs_same_cond` and `cfg!`
This commit is contained in:
commit
ed60e41917
2 changed files with 25 additions and 4 deletions
|
@ -4,6 +4,7 @@ use rustc_front::hir::*;
|
|||
use std::hash::{Hash, Hasher, SipHasher};
|
||||
use syntax::ast::Name;
|
||||
use syntax::ptr::P;
|
||||
use utils::differing_macro_contexts;
|
||||
|
||||
/// Type used to check whether two ast are the same. This is different from the operator
|
||||
/// `==` on ast types as this operator would compare true equality with ID and span.
|
||||
|
@ -53,6 +54,10 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
|||
// ok, it’s a big function, but mostly one big match with simples cases
|
||||
#[allow(cyclomatic_complexity)]
|
||||
pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
|
||||
if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let (Some(l), Some(r)) = (constant(self.cx, left), constant(self.cx, right)) {
|
||||
if l == r {
|
||||
return true;
|
||||
|
|
|
@ -12,7 +12,7 @@ fn foo() -> bool { unimplemented!() }
|
|||
|
||||
#[deny(if_same_then_else)]
|
||||
#[deny(match_same_arms)]
|
||||
fn if_same_then_else() -> &'static str {
|
||||
fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
if true {
|
||||
foo();
|
||||
}
|
||||
|
@ -129,17 +129,24 @@ fn if_same_then_else() -> &'static str {
|
|||
_ => (),
|
||||
}
|
||||
|
||||
if true {
|
||||
try!(Ok("foo"));
|
||||
}
|
||||
else { //~ERROR this `if` has identical blocks
|
||||
try!(Ok("foo"));
|
||||
}
|
||||
|
||||
if true {
|
||||
let foo = "";
|
||||
return &foo[0..];
|
||||
return Ok(&foo[0..]);
|
||||
}
|
||||
else if false {
|
||||
let foo = "bar";
|
||||
return &foo[0..];
|
||||
return Ok(&foo[0..]);
|
||||
}
|
||||
else { //~ERROR this `if` has identical blocks
|
||||
let foo = "";
|
||||
return &foo[0..];
|
||||
return Ok(&foo[0..]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,6 +175,15 @@ fn ifs_same_cond() {
|
|||
else if a == 1 {
|
||||
}
|
||||
|
||||
// See #659
|
||||
if cfg!(feature = "feature1-659") {
|
||||
1
|
||||
} else if cfg!(feature = "feature2-659") {
|
||||
2
|
||||
} else {
|
||||
3
|
||||
};
|
||||
|
||||
let mut v = vec![1];
|
||||
if v.pop() == None { // ok, functions
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue