mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
Merge pull request #284 from birkenfeld/is_methods
methods: allow multiple self kinds for "is_" methods
This commit is contained in:
commit
8edc87e3bd
1 changed files with 11 additions and 9 deletions
|
@ -88,12 +88,14 @@ impl LintPass for MethodsPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check conventions w.r.t. conversion method names and predicates
|
// check conventions w.r.t. conversion method names and predicates
|
||||||
for &(prefix, self_kind) in &CONVENTIONS {
|
let is_copy = is_copy(cx, &ty, &item);
|
||||||
|
for &(prefix, self_kinds) in &CONVENTIONS {
|
||||||
if name.as_str().starts_with(prefix) &&
|
if name.as_str().starts_with(prefix) &&
|
||||||
!self_kind.matches(&sig.explicit_self.node, is_copy(cx, &ty, &item)) {
|
!self_kinds.iter().any(|k| k.matches(&sig.explicit_self.node, is_copy)) {
|
||||||
span_lint(cx, WRONG_SELF_CONVENTION, sig.explicit_self.span, &format!(
|
span_lint(cx, WRONG_SELF_CONVENTION, sig.explicit_self.span, &format!(
|
||||||
"methods called `{}*` usually take {}; consider choosing a less \
|
"methods called `{}*` usually take {}; consider choosing a less \
|
||||||
ambiguous name", prefix, self_kind.description()));
|
ambiguous name", prefix,
|
||||||
|
&self_kinds.iter().map(|k| k.description()).collect::<Vec<_>>().join(" or ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,12 +104,12 @@ impl LintPass for MethodsPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONVENTIONS: [(&'static str, SelfKind); 5] = [
|
const CONVENTIONS: [(&'static str, &'static [SelfKind]); 5] = [
|
||||||
("into_", ValueSelf),
|
("into_", &[ValueSelf]),
|
||||||
("to_", RefSelf),
|
("to_", &[RefSelf]),
|
||||||
("as_", RefSelf),
|
("as_", &[RefSelf]),
|
||||||
("is_", RefSelf),
|
("is_", &[RefSelf, NoSelf]),
|
||||||
("from_", NoSelf),
|
("from_", &[NoSelf]),
|
||||||
];
|
];
|
||||||
|
|
||||||
const TRAIT_METHODS: [(&'static str, usize, SelfKind, OutType, &'static str); 30] = [
|
const TRAIT_METHODS: [(&'static str, usize, SelfKind, OutType, &'static str); 30] = [
|
||||||
|
|
Loading…
Reference in a new issue