mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
unused_self: respect avoid-breaking-exported-api
This commit is contained in:
@@ -782,7 +782,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
))
|
||||
});
|
||||
store.register_late_pass(|| Box::new(default::Default::default()));
|
||||
store.register_late_pass(|| Box::new(unused_self::UnusedSelf));
|
||||
store.register_late_pass(move || Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api)));
|
||||
store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
|
||||
store.register_late_pass(|| Box::new(exit::Exit));
|
||||
store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use if_chain::if_chain;
|
||||
use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
@@ -35,7 +35,19 @@
|
||||
"methods that contain a `self` argument but don't use it"
|
||||
}
|
||||
|
||||
declare_lint_pass!(UnusedSelf => [UNUSED_SELF]);
|
||||
pub struct UnusedSelf {
|
||||
avoid_breaking_exported_api: bool,
|
||||
}
|
||||
|
||||
impl_lint_pass!(UnusedSelf => [UNUSED_SELF]);
|
||||
|
||||
impl UnusedSelf {
|
||||
pub fn new(avoid_breaking_exported_api: bool) -> Self {
|
||||
Self {
|
||||
avoid_breaking_exported_api,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>) {
|
||||
@@ -49,6 +61,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>)
|
||||
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
|
||||
if assoc_item.fn_has_self_parameter;
|
||||
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
|
||||
if !cx.access_levels.is_exported(impl_item.def_id) || !self.avoid_breaking_exported_api;
|
||||
let body = cx.tcx.hir().body(*body_id);
|
||||
if let [self_param, ..] = body.params;
|
||||
if !is_local_used(cx, body, self_param.pat.hir_id);
|
||||
|
||||
@@ -191,7 +191,7 @@ pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
|
||||
}
|
||||
|
||||
define_Conf! {
|
||||
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX.
|
||||
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX.
|
||||
///
|
||||
/// Suppress lints whenever the suggested change would cause breakage for other crates.
|
||||
(avoid_breaking_exported_api: bool = true),
|
||||
|
||||
@@ -53,8 +53,17 @@ fn some_fn((): ()) {}
|
||||
// shouldn't trigger
|
||||
fn unused_self_move(self) {}
|
||||
}
|
||||
|
||||
pub struct D;
|
||||
|
||||
impl D {
|
||||
// shouldn't trigger for public methods
|
||||
pub fn unused_self_move(self) {}
|
||||
}
|
||||
}
|
||||
|
||||
pub use unused_self_allow::D;
|
||||
|
||||
mod used_self {
|
||||
use std::pin::Pin;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user