mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 17:33:07 +00:00
Use break api config for wrong_pub_self_convention
This commit is contained in:
parent
2e2021bbda
commit
d7f47f280e
@ -141,3 +141,12 @@ declare_deprecated_lint! {
|
||||
pub FILTER_MAP,
|
||||
"this lint has been replaced by `manual_filter_map`, a more specific lint"
|
||||
}
|
||||
|
||||
declare_deprecated_lint! {
|
||||
/// **What it does:** Nothing. This lint has been deprecated.
|
||||
///
|
||||
/// **Deprecation reason:** The `avoid_breaking_exported_api` config option was added, which
|
||||
/// enables the `wrong_self_conversion` lint for public items.
|
||||
pub WRONG_PUB_SELF_CONVENTION,
|
||||
"set the `avoid_breaking_exported_api` config option to `false` to enable the `wrong_self_convention` lint for public items"
|
||||
}
|
||||
|
@ -505,6 +505,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
"clippy::filter_map",
|
||||
"this lint has been replaced by `manual_filter_map`, a more specific lint",
|
||||
);
|
||||
store.register_removed(
|
||||
"clippy::wrong_pub_self_convention",
|
||||
"set the `avoid_breaking_exported_api` config option to `false` to enable the `wrong_self_convention` lint for public items",
|
||||
);
|
||||
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
||||
|
||||
// begin register lints, do not remove this comment, it’s used in `update_lints`
|
||||
@ -802,7 +806,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
methods::UNNECESSARY_LAZY_EVALUATIONS,
|
||||
methods::UNWRAP_USED,
|
||||
methods::USELESS_ASREF,
|
||||
methods::WRONG_PUB_SELF_CONVENTION,
|
||||
methods::WRONG_SELF_CONVENTION,
|
||||
methods::ZST_OFFSET,
|
||||
minmax::MIN_MAX,
|
||||
@ -1026,7 +1029,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
LintId::of(methods::FILETYPE_IS_FILE),
|
||||
LintId::of(methods::GET_UNWRAP),
|
||||
LintId::of(methods::UNWRAP_USED),
|
||||
LintId::of(methods::WRONG_PUB_SELF_CONVENTION),
|
||||
LintId::of(misc::FLOAT_CMP_CONST),
|
||||
LintId::of(misc_early::UNNEEDED_FIELD_PATTERN),
|
||||
LintId::of(missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
|
||||
@ -1862,7 +1864,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
})
|
||||
});
|
||||
|
||||
store.register_late_pass(move || box methods::Methods::new(msrv));
|
||||
let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
|
||||
store.register_late_pass(move || box methods::Methods::new(avoid_breaking_exported_api, msrv));
|
||||
store.register_late_pass(move || box matches::Matches::new(msrv));
|
||||
store.register_early_pass(move || box manual_non_exhaustive::ManualNonExhaustive::new(msrv));
|
||||
store.register_late_pass(move || box manual_strip::ManualStrip::new(msrv));
|
||||
|
@ -282,30 +282,6 @@ declare_clippy_lint! {
|
||||
"defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** This is the same as
|
||||
/// [`wrong_self_convention`](#wrong_self_convention), but for public items.
|
||||
///
|
||||
/// **Why is this bad?** See [`wrong_self_convention`](#wrong_self_convention).
|
||||
///
|
||||
/// **Known problems:** Actually *renaming* the function may break clients if
|
||||
/// the function is part of the public interface. In that case, be mindful of
|
||||
/// the stability guarantees you've given your users.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// # struct X;
|
||||
/// impl<'a> X {
|
||||
/// pub fn as_str(self) -> &'a str {
|
||||
/// "foo"
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub WRONG_PUB_SELF_CONVENTION,
|
||||
restriction,
|
||||
"defining a public method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for usage of `ok().expect(..)`.
|
||||
///
|
||||
@ -1658,13 +1634,17 @@ declare_clippy_lint! {
|
||||
}
|
||||
|
||||
pub struct Methods {
|
||||
avoid_breaking_exported_api: bool,
|
||||
msrv: Option<RustcVersion>,
|
||||
}
|
||||
|
||||
impl Methods {
|
||||
#[must_use]
|
||||
pub fn new(msrv: Option<RustcVersion>) -> Self {
|
||||
Self { msrv }
|
||||
pub fn new(avoid_breaking_exported_api: bool, msrv: Option<RustcVersion>) -> Self {
|
||||
Self {
|
||||
avoid_breaking_exported_api,
|
||||
msrv,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1673,7 +1653,6 @@ impl_lint_pass!(Methods => [
|
||||
EXPECT_USED,
|
||||
SHOULD_IMPLEMENT_TRAIT,
|
||||
WRONG_SELF_CONVENTION,
|
||||
WRONG_PUB_SELF_CONVENTION,
|
||||
OK_EXPECT,
|
||||
MAP_UNWRAP_OR,
|
||||
RESULT_MAP_OR_INTO_OPTION,
|
||||
@ -1838,11 +1817,13 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
}
|
||||
}
|
||||
|
||||
if sig.decl.implicit_self.has_implicit_self() {
|
||||
if sig.decl.implicit_self.has_implicit_self()
|
||||
&& !(self.avoid_breaking_exported_api
|
||||
&& cx.access_levels.is_exported(impl_item.hir_id()))
|
||||
{
|
||||
wrong_self_convention::check(
|
||||
cx,
|
||||
&name,
|
||||
item.vis.node.is_pub(),
|
||||
self_ty,
|
||||
first_arg_ty,
|
||||
first_arg.pat.span,
|
||||
@ -1915,7 +1896,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
wrong_self_convention::check(
|
||||
cx,
|
||||
&item.ident.name.as_str(),
|
||||
false,
|
||||
self_ty,
|
||||
first_arg_ty,
|
||||
first_arg_span,
|
||||
|
@ -6,7 +6,6 @@ use rustc_middle::ty::TyS;
|
||||
use rustc_span::source_map::Span;
|
||||
use std::fmt;
|
||||
|
||||
use super::WRONG_PUB_SELF_CONVENTION;
|
||||
use super::WRONG_SELF_CONVENTION;
|
||||
|
||||
#[rustfmt::skip]
|
||||
@ -85,18 +84,12 @@ impl fmt::Display for Convention {
|
||||
pub(super) fn check<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
item_name: &str,
|
||||
is_pub: bool,
|
||||
self_ty: &'tcx TyS<'tcx>,
|
||||
first_arg_ty: &'tcx TyS<'tcx>,
|
||||
first_arg_span: Span,
|
||||
implements_trait: bool,
|
||||
is_trait_item: bool,
|
||||
) {
|
||||
let lint = if is_pub {
|
||||
WRONG_PUB_SELF_CONVENTION
|
||||
} else {
|
||||
WRONG_SELF_CONVENTION
|
||||
};
|
||||
if let Some((conventions, self_kinds)) = &CONVENTIONS.iter().find(|(convs, _)| {
|
||||
convs
|
||||
.iter()
|
||||
@ -142,7 +135,7 @@ pub(super) fn check<'tcx>(
|
||||
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
lint,
|
||||
WRONG_SELF_CONVENTION,
|
||||
first_arg_span,
|
||||
&format!(
|
||||
"{} usually take {}",
|
||||
|
@ -20,7 +20,7 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
0
|
||||
}
|
||||
|
||||
pub struct A;
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
pub fn as_ref(self) -> &'static str {
|
||||
|
@ -15,12 +15,4 @@ mod foo {
|
||||
pub struct Foobar;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
// edition:2018
|
||||
#![warn(clippy::wrong_self_convention)]
|
||||
#![warn(clippy::wrong_pub_self_convention)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:18:17
|
||||
--> $DIR/wrong_self_convention.rs:17:17
|
||||
|
|
||||
LL | fn from_i32(self) {}
|
||||
| ^^^^
|
||||
@ -8,7 +8,7 @@ LL | fn from_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:24:21
|
||||
--> $DIR/wrong_self_convention.rs:23:21
|
||||
|
|
||||
LL | pub fn from_i64(self) {}
|
||||
| ^^^^
|
||||
@ -16,7 +16,7 @@ LL | pub fn from_i64(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
|
||||
--> $DIR/wrong_self_convention.rs:36:15
|
||||
--> $DIR/wrong_self_convention.rs:35:15
|
||||
|
|
||||
LL | fn as_i32(self) {}
|
||||
| ^^^^
|
||||
@ -24,7 +24,7 @@ LL | fn as_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `into_*` usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:38:17
|
||||
--> $DIR/wrong_self_convention.rs:37:17
|
||||
|
|
||||
LL | fn into_i32(&self) {}
|
||||
| ^^^^^
|
||||
@ -32,7 +32,7 @@ LL | fn into_i32(&self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `is_*` usually take `self` by reference or no `self`
|
||||
--> $DIR/wrong_self_convention.rs:40:15
|
||||
--> $DIR/wrong_self_convention.rs:39:15
|
||||
|
|
||||
LL | fn is_i32(self) {}
|
||||
| ^^^^
|
||||
@ -40,7 +40,7 @@ LL | fn is_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
|
||||
--> $DIR/wrong_self_convention.rs:42:15
|
||||
--> $DIR/wrong_self_convention.rs:41:15
|
||||
|
|
||||
LL | fn to_i32(self) {}
|
||||
| ^^^^
|
||||
@ -48,7 +48,7 @@ LL | fn to_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:44:17
|
||||
--> $DIR/wrong_self_convention.rs:43:17
|
||||
|
|
||||
LL | fn from_i32(self) {}
|
||||
| ^^^^
|
||||
@ -56,7 +56,7 @@ LL | fn from_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
|
||||
--> $DIR/wrong_self_convention.rs:46:19
|
||||
--> $DIR/wrong_self_convention.rs:45:19
|
||||
|
|
||||
LL | pub fn as_i64(self) {}
|
||||
| ^^^^
|
||||
@ -64,7 +64,7 @@ LL | pub fn as_i64(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `into_*` usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:47:21
|
||||
--> $DIR/wrong_self_convention.rs:46:21
|
||||
|
|
||||
LL | pub fn into_i64(&self) {}
|
||||
| ^^^^^
|
||||
@ -72,7 +72,7 @@ LL | pub fn into_i64(&self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `is_*` usually take `self` by reference or no `self`
|
||||
--> $DIR/wrong_self_convention.rs:48:19
|
||||
--> $DIR/wrong_self_convention.rs:47:19
|
||||
|
|
||||
LL | pub fn is_i64(self) {}
|
||||
| ^^^^
|
||||
@ -80,7 +80,7 @@ LL | pub fn is_i64(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
|
||||
--> $DIR/wrong_self_convention.rs:49:19
|
||||
--> $DIR/wrong_self_convention.rs:48:19
|
||||
|
|
||||
LL | pub fn to_i64(self) {}
|
||||
| ^^^^
|
||||
@ -88,7 +88,7 @@ LL | pub fn to_i64(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:50:21
|
||||
--> $DIR/wrong_self_convention.rs:49:21
|
||||
|
|
||||
LL | pub fn from_i64(self) {}
|
||||
| ^^^^
|
||||
@ -96,7 +96,7 @@ LL | pub fn from_i64(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
|
||||
--> $DIR/wrong_self_convention.rs:95:19
|
||||
--> $DIR/wrong_self_convention.rs:94:19
|
||||
|
|
||||
LL | fn as_i32(self) {}
|
||||
| ^^^^
|
||||
@ -104,7 +104,7 @@ LL | fn as_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `into_*` usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:98:25
|
||||
--> $DIR/wrong_self_convention.rs:97:25
|
||||
|
|
||||
LL | fn into_i32_ref(&self) {}
|
||||
| ^^^^^
|
||||
@ -112,7 +112,7 @@ LL | fn into_i32_ref(&self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `is_*` usually take `self` by reference or no `self`
|
||||
--> $DIR/wrong_self_convention.rs:100:19
|
||||
--> $DIR/wrong_self_convention.rs:99:19
|
||||
|
|
||||
LL | fn is_i32(self) {}
|
||||
| ^^^^
|
||||
@ -120,7 +120,7 @@ LL | fn is_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:104:21
|
||||
--> $DIR/wrong_self_convention.rs:103:21
|
||||
|
|
||||
LL | fn from_i32(self) {}
|
||||
| ^^^^
|
||||
@ -128,7 +128,7 @@ LL | fn from_i32(self) {}
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
|
||||
--> $DIR/wrong_self_convention.rs:119:19
|
||||
--> $DIR/wrong_self_convention.rs:118:19
|
||||
|
|
||||
LL | fn as_i32(self);
|
||||
| ^^^^
|
||||
@ -136,7 +136,7 @@ LL | fn as_i32(self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `into_*` usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:122:25
|
||||
--> $DIR/wrong_self_convention.rs:121:25
|
||||
|
|
||||
LL | fn into_i32_ref(&self);
|
||||
| ^^^^^
|
||||
@ -144,7 +144,7 @@ LL | fn into_i32_ref(&self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `is_*` usually take `self` by reference or no `self`
|
||||
--> $DIR/wrong_self_convention.rs:124:19
|
||||
--> $DIR/wrong_self_convention.rs:123:19
|
||||
|
|
||||
LL | fn is_i32(self);
|
||||
| ^^^^
|
||||
@ -152,7 +152,7 @@ LL | fn is_i32(self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:128:21
|
||||
--> $DIR/wrong_self_convention.rs:127:21
|
||||
|
|
||||
LL | fn from_i32(self);
|
||||
| ^^^^
|
||||
@ -160,7 +160,7 @@ LL | fn from_i32(self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `into_*` usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:146:25
|
||||
--> $DIR/wrong_self_convention.rs:145:25
|
||||
|
|
||||
LL | fn into_i32_ref(&self);
|
||||
| ^^^^^
|
||||
@ -168,7 +168,7 @@ LL | fn into_i32_ref(&self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention.rs:152:21
|
||||
--> $DIR/wrong_self_convention.rs:151:21
|
||||
|
|
||||
LL | fn from_i32(self);
|
||||
| ^^^^
|
||||
@ -176,7 +176,7 @@ LL | fn from_i32(self);
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
|
||||
--> $DIR/wrong_self_convention.rs:176:22
|
||||
--> $DIR/wrong_self_convention.rs:175:22
|
||||
|
|
||||
LL | fn to_u64_v2(&self) -> u64 {
|
||||
| ^^^^^
|
||||
@ -184,7 +184,7 @@ LL | fn to_u64_v2(&self) -> u64 {
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
|
||||
--> $DIR/wrong_self_convention.rs:185:19
|
||||
--> $DIR/wrong_self_convention.rs:184:19
|
||||
|
|
||||
LL | fn to_u64(self) -> u64 {
|
||||
| ^^^^
|
||||
|
@ -1,6 +1,5 @@
|
||||
// edition:2018
|
||||
#![warn(clippy::wrong_self_convention)]
|
||||
#![warn(clippy::wrong_pub_self_convention)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention2.rs:56:29
|
||||
--> $DIR/wrong_self_convention2.rs:55:29
|
||||
|
|
||||
LL | pub fn from_be_self(self) -> Self {
|
||||
| ^^^^
|
||||
@ -8,7 +8,7 @@ LL | pub fn from_be_self(self) -> Self {
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `from_*` usually take no `self`
|
||||
--> $DIR/wrong_self_convention2.rs:65:25
|
||||
--> $DIR/wrong_self_convention2.rs:64:25
|
||||
|
|
||||
LL | fn from_be_self(self) -> Self;
|
||||
| ^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user