split wrong_self_convention in pub/default visibility part
This commit is contained in:
parent
f4c28f8521
commit
92b04cd75d
@ -4,10 +4,10 @@
|
||||
A collection of lints that give helpful tips to newbies and catch oversights.
|
||||
|
||||
##Lints
|
||||
There are 55 lints included in this crate:
|
||||
There are 56 lints included in this crate:
|
||||
|
||||
name | default | meaning
|
||||
-----------------------------------------------------------------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[approx_constant](https://github.com/Manishearth/rust-clippy/wiki#approx_constant) | warn | the approximate of a known float constant (in `std::f64::consts` or `std::f32::consts`) is found; suggests to use the constant
|
||||
[bad_bit_mask](https://github.com/Manishearth/rust-clippy/wiki#bad_bit_mask) | warn | expressions of the form `_ & mask == select` that will only ever return `true` or `false` (because in the example `select` containing bits that `mask` doesn't have)
|
||||
[box_vec](https://github.com/Manishearth/rust-clippy/wiki#box_vec) | warn | usage of `Box<Vec<T>>`, vector elements are already on the heap
|
||||
@ -61,6 +61,7 @@ name
|
||||
[unit_cmp](https://github.com/Manishearth/rust-clippy/wiki#unit_cmp) | warn | comparing unit values (which is always `true` or `false`, respectively)
|
||||
[unused_collect](https://github.com/Manishearth/rust-clippy/wiki#unused_collect) | warn | `collect()`ing an iterator without using the result; this is usually better written as a for loop
|
||||
[while_let_loop](https://github.com/Manishearth/rust-clippy/wiki#while_let_loop) | warn | `loop { if let { ... } else break }` can be written as a `while let` loop
|
||||
[wrong_pub_self_convention](https://github.com/Manishearth/rust-clippy/wiki#wrong_pub_self_convention) | allow | defining a public method named with an established prefix (like "into_") that takes `self` with the wrong convention
|
||||
[wrong_self_convention](https://github.com/Manishearth/rust-clippy/wiki#wrong_self_convention) | warn | defining a method named with an established prefix (like "into_") that takes `self` with the wrong convention
|
||||
[zero_width_space](https://github.com/Manishearth/rust-clippy/wiki#zero_width_space) | deny | using a zero-width space in a string literal, which is confusing
|
||||
|
||||
|
@ -91,6 +91,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
||||
reg.register_lint_group("clippy_pedantic", vec![
|
||||
methods::OPTION_UNWRAP_USED,
|
||||
methods::RESULT_UNWRAP_USED,
|
||||
methods::WRONG_PUB_SELF_CONVENTION,
|
||||
ptr_arg::PTR_ARG,
|
||||
shadow::SHADOW_REUSE,
|
||||
shadow::SHADOW_SAME,
|
||||
|
@ -27,6 +27,9 @@ declare_lint!(pub SHOULD_IMPLEMENT_TRAIT, Warn,
|
||||
declare_lint!(pub WRONG_SELF_CONVENTION, Warn,
|
||||
"defining a method named with an established prefix (like \"into_\") that takes \
|
||||
`self` with the wrong convention");
|
||||
declare_lint!(pub WRONG_PUB_SELF_CONVENTION, Allow,
|
||||
"defining a public method named with an established prefix (like \"into_\") that takes \
|
||||
`self` with the wrong convention");
|
||||
|
||||
impl LintPass for MethodsPass {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
@ -93,7 +96,12 @@ impl LintPass for MethodsPass {
|
||||
for &(prefix, self_kinds) in &CONVENTIONS {
|
||||
if name.as_str().starts_with(prefix) &&
|
||||
!self_kinds.iter().any(|k| k.matches(&sig.explicit_self.node, is_copy)) {
|
||||
span_lint(cx, WRONG_SELF_CONVENTION, sig.explicit_self.span, &format!(
|
||||
let lint = if let Visibility::Public = item.vis {
|
||||
WRONG_PUB_SELF_CONVENTION
|
||||
} else {
|
||||
WRONG_SELF_CONVENTION
|
||||
};
|
||||
span_lint(cx, lint, sig.explicit_self.span, &format!(
|
||||
"methods called `{}*` usually take {}; consider choosing a less \
|
||||
ambiguous name", prefix,
|
||||
&self_kinds.iter().map(|k| k.description()).collect::<Vec<_>>().join(" or ")));
|
||||
|
Loading…
Reference in New Issue
Block a user