diff --git a/src/methods.rs b/src/methods.rs index a6200534e..e70d26820 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -173,8 +173,8 @@ declare_lint!(pub SEARCH_IS_SOME, Warn, impl LintPass for MethodsPass { fn get_lints(&self) -> LintArray { lint_array!(OPTION_UNWRAP_USED, RESULT_UNWRAP_USED, STR_TO_STRING, STRING_TO_STRING, - SHOULD_IMPLEMENT_TRAIT, WRONG_SELF_CONVENTION, OK_EXPECT, OPTION_MAP_UNWRAP_OR, - OPTION_MAP_UNWRAP_OR_ELSE) + SHOULD_IMPLEMENT_TRAIT, WRONG_SELF_CONVENTION, WRONG_PUB_SELF_CONVENTION, + OK_EXPECT, OPTION_MAP_UNWRAP_OR, OPTION_MAP_UNWRAP_OR_ELSE) } } diff --git a/tests/compile-fail/wrong_self_convention.rs b/tests/compile-fail/wrong_self_convention.rs new file mode 100644 index 000000000..ca896a6b9 --- /dev/null +++ b/tests/compile-fail/wrong_self_convention.rs @@ -0,0 +1,45 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#![deny(wrong_self_convention)] +#![deny(wrong_pub_self_convention)] +#![allow(dead_code)] + +fn main() {} + +#[derive(Clone, Copy)] +struct Foo; + +impl Foo { + + fn as_i32(self) {} + fn into_i32(self) {} + fn is_i32(self) {} + fn to_i32(self) {} + fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self + + pub fn as_i64(self) {} + pub fn into_i64(self) {} + pub fn is_i64(self) {} + pub fn to_i64(self) {} + pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self + +} + +struct Bar; + +impl Bar { + + fn as_i32(self) {} //~ERROR: methods called `as_*` usually take self by reference + fn into_i32(&self) {} //~ERROR: methods called `into_*` usually take self by value + fn is_i32(self) {} //~ERROR: methods called `is_*` usually take self by reference + fn to_i32(self) {} //~ERROR: methods called `to_*` usually take self by reference + fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self + + pub fn as_i64(self) {} //~ERROR: methods called `as_*` usually take self by reference + pub fn into_i64(&self) {} //~ERROR: methods called `into_*` usually take self by value + pub fn is_i64(self) {} //~ERROR: methods called `is_*` usually take self by reference + pub fn to_i64(self) {} //~ERROR: methods called `to_*` usually take self by reference + pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self + +}