Skip to content

Commit 1ce581d

Browse files
committed
Use break api config for unnecessary_wraps
1 parent 3d77a2b commit 1ce581d

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
19761976
store.register_late_pass(|| box redundant_clone::RedundantClone);
19771977
store.register_late_pass(|| box slow_vector_initialization::SlowVectorInit);
19781978
store.register_late_pass(|| box unnecessary_sort_by::UnnecessarySortBy);
1979-
store.register_late_pass(|| box unnecessary_wraps::UnnecessaryWraps);
1979+
store.register_late_pass(move || box unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api));
19801980
store.register_late_pass(|| box assertions_on_constants::AssertionsOnConstants);
19811981
store.register_late_pass(|| box transmuting_null::TransmutingNull);
19821982
store.register_late_pass(|| box path_buf_push_overwrite::PathBufPushOverwrite);

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::LangItem::{OptionSome, ResultOk};
88
use rustc_hir::{Body, ExprKind, FnDecl, HirId, Impl, ItemKind, Node};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty;
11-
use rustc_session::{declare_lint_pass, declare_tool_lint};
11+
use rustc_session::{declare_tool_lint, impl_lint_pass};
1212
use rustc_span::symbol::sym;
1313
use rustc_span::Span;
1414

@@ -52,7 +52,19 @@ declare_clippy_lint! {
5252
"functions that only return `Ok` or `Some`"
5353
}
5454

55-
declare_lint_pass!(UnnecessaryWraps => [UNNECESSARY_WRAPS]);
55+
pub struct UnnecessaryWraps {
56+
avoid_breaking_exported_api: bool,
57+
}
58+
59+
impl_lint_pass!(UnnecessaryWraps => [UNNECESSARY_WRAPS]);
60+
61+
impl UnnecessaryWraps {
62+
pub fn new(avoid_breaking_exported_api: bool) -> Self {
63+
Self {
64+
avoid_breaking_exported_api,
65+
}
66+
}
67+
}
5668

5769
impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
5870
fn check_fn(
@@ -66,13 +78,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
6678
) {
6779
// Abort if public function/method or closure.
6880
match fn_kind {
69-
FnKind::ItemFn(.., visibility) | FnKind::Method(.., Some(visibility)) => {
70-
if visibility.node.is_pub() {
81+
FnKind::ItemFn(..) | FnKind::Method(..) => {
82+
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) {
7183
return;
7284
}
7385
},
7486
FnKind::Closure => return,
75-
FnKind::Method(..) => (),
7687
}
7788

7889
// Abort if the method is implementing a trait or of it a trait method.

tests/ui/unnecessary_wraps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn func10() -> Option<()> {
6565
unimplemented!()
6666
}
6767

68-
struct A;
68+
pub struct A;
6969

7070
impl A {
7171
// should not be linted

0 commit comments

Comments
 (0)