This commit is contained in:
Oliver Schneider 2016-02-01 12:51:33 +01:00
parent 328d2c7626
commit 3b1df8d381
10 changed files with 210 additions and 216 deletions

View file

@ -3,8 +3,8 @@
#[allow(dead_code)]
enum Baz {
Baz1,
Baz2,
One,
Two,
}
struct Test {
@ -14,11 +14,11 @@ struct Test {
fn main() {
use Baz::*;
let x = Test { t: Some(0), b: Baz1 };
let x = Test { t: Some(0), b: One };
match x {
Test { t: Some(_), b: Baz1 } => unreachable!(),
Test { t: Some(42), b: Baz2 } => unreachable!(),
Test { t: Some(_), b: One } => unreachable!(),
Test { t: Some(42), b: Two } => unreachable!(),
Test { t: None, .. } => unreachable!(),
Test { .. } => unreachable!(),
}

View file

@ -16,8 +16,8 @@ struct S {
struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>); //~ERROR very complex type
enum E {
V1(Vec<Vec<Box<(u32, u32, u32, u32)>>>), //~ERROR very complex type
V2 { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> }, //~ERROR very complex type
Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>), //~ERROR very complex type
Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> }, //~ERROR very complex type
}
impl S {

View file

@ -11,8 +11,8 @@ struct Struct {
field: i32
}
enum Enum {
TupleVariant(i32),
StructVariant { field: i32 },
Tuple(i32),
Struct { field: i32 },
}
fn get_number() -> i32 { 0 }
@ -26,14 +26,14 @@ fn main() {
Tuple(0); //~ERROR statement with no effect
Struct { field: 0 }; //~ERROR statement with no effect
Struct { ..s }; //~ERROR statement with no effect
Enum::TupleVariant(0); //~ERROR statement with no effect
Enum::StructVariant { field: 0 }; //~ERROR statement with no effect
Enum::Tuple(0); //~ERROR statement with no effect
Enum::Struct { field: 0 }; //~ERROR statement with no effect
// Do not warn
get_number();
Tuple(get_number());
Struct { field: get_number() };
Struct { ..get_struct() };
Enum::TupleVariant(get_number());
Enum::StructVariant { field: get_number() };
Enum::Tuple(get_number());
Enum::Struct { field: get_number() };
}

View file

@ -50,17 +50,17 @@ fn multiple_underscores(__foo: u32) -> u32 {
fn _fn_test() {}
struct _StructTest;
enum _EnumTest {
_FieldA,
_FieldB(_StructTest)
_Empty,
_Value(_StructTest)
}
/// Test that we do not lint for non-variable bindings
fn non_variables() {
_fn_test();
let _s = _StructTest;
let _e = match _EnumTest::_FieldB(_StructTest) {
_EnumTest::_FieldA => 0,
_EnumTest::_FieldB(_st) => 1,
let _e = match _EnumTest::_Value(_StructTest) {
_EnumTest::_Empty => 0,
_EnumTest::_Value(_st) => 1,
};
let f = _fn_test;
f();

View file

@ -18,7 +18,6 @@ use syntax::ast::StrStyle::*;
use syntax::ast::Sign::*;
use clippy::consts::{constant_simple, Constant};
use clippy::consts::Constant::*;
fn spanned<T>(t: T) -> Spanned<T> {
Spanned{ node: t, span: COMMAND_LINE_SP }
@ -45,18 +44,18 @@ fn check(expect: Constant, expr: &Expr) {
assert_eq!(Some(expect), constant_simple(expr))
}
const TRUE : Constant = ConstantBool(true);
const FALSE : Constant = ConstantBool(false);
const ZERO : Constant = ConstantInt(0, UnsuffixedIntLit(Plus));
const ONE : Constant = ConstantInt(1, UnsuffixedIntLit(Plus));
const TWO : Constant = ConstantInt(2, UnsuffixedIntLit(Plus));
const TRUE : Constant = Constant::Bool(true);
const FALSE : Constant = Constant::Bool(false);
const ZERO : Constant = Constant::Int(0, UnsuffixedIntLit(Plus));
const ONE : Constant = Constant::Int(1, UnsuffixedIntLit(Plus));
const TWO : Constant = Constant::Int(2, UnsuffixedIntLit(Plus));
#[test]
fn test_lit() {
check(TRUE, &lit(LitBool(true)));
check(FALSE, &lit(LitBool(false)));
check(ZERO, &lit(LitInt(0, UnsuffixedIntLit(Plus))));
check(ConstantStr("cool!".into(), CookedStr), &lit(LitStr(
check(Constant::Str("cool!".into(), CookedStr), &lit(LitStr(
InternedString::new("cool!"), CookedStr)));
}