mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-12 09:57:43 +00:00
Fix false positive for ifs_same_cond
and cfg!
This commit is contained in:
parent
1e176cae5d
commit
49e2501c63
@ -4,6 +4,7 @@ use rustc_front::hir::*;
|
|||||||
use std::hash::{Hash, Hasher, SipHasher};
|
use std::hash::{Hash, Hasher, SipHasher};
|
||||||
use syntax::ast::Name;
|
use syntax::ast::Name;
|
||||||
use syntax::ptr::P;
|
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
|
/// 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.
|
/// `==` 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
|
// ok, it’s a big function, but mostly one big match with simples cases
|
||||||
#[allow(cyclomatic_complexity)]
|
#[allow(cyclomatic_complexity)]
|
||||||
pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
|
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 let (Some(l), Some(r)) = (constant(self.cx, left), constant(self.cx, right)) {
|
||||||
if l == r {
|
if l == r {
|
||||||
return true;
|
return true;
|
||||||
|
@ -12,7 +12,7 @@ fn foo() -> bool { unimplemented!() }
|
|||||||
|
|
||||||
#[deny(if_same_then_else)]
|
#[deny(if_same_then_else)]
|
||||||
#[deny(match_same_arms)]
|
#[deny(match_same_arms)]
|
||||||
fn if_same_then_else() -> &'static str {
|
fn if_same_then_else() -> Result<&'static str, ()> {
|
||||||
if true {
|
if true {
|
||||||
foo();
|
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 {
|
if true {
|
||||||
let foo = "";
|
let foo = "";
|
||||||
return &foo[0..];
|
return Ok(&foo[0..]);
|
||||||
}
|
}
|
||||||
else if false {
|
else if false {
|
||||||
let foo = "bar";
|
let foo = "bar";
|
||||||
return &foo[0..];
|
return Ok(&foo[0..]);
|
||||||
}
|
}
|
||||||
else { //~ERROR this `if` has identical blocks
|
else { //~ERROR this `if` has identical blocks
|
||||||
let foo = "";
|
let foo = "";
|
||||||
return &foo[0..];
|
return Ok(&foo[0..]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +175,15 @@ fn ifs_same_cond() {
|
|||||||
else if a == 1 {
|
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];
|
let mut v = vec![1];
|
||||||
if v.pop() == None { // ok, functions
|
if v.pop() == None { // ok, functions
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user