mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Add MSRV check for manual_noop_waker
This commit is contained in:
@@ -928,6 +928,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
|
||||
* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else)
|
||||
* [`manual_midpoint`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_midpoint)
|
||||
* [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive)
|
||||
* [`manual_noop_waker`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_noop_waker)
|
||||
* [`manual_option_as_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice)
|
||||
* [`manual_pattern_char_comparison`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison)
|
||||
* [`manual_range_contains`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains)
|
||||
|
||||
@@ -789,6 +789,7 @@ fn span_from_toml_range(file: &SourceFile, span: Range<usize>) -> Span {
|
||||
manual_let_else,
|
||||
manual_midpoint,
|
||||
manual_non_exhaustive,
|
||||
manual_noop_waker,
|
||||
manual_option_as_slice,
|
||||
manual_pattern_char_comparison,
|
||||
manual_range_contains,
|
||||
|
||||
@@ -866,7 +866,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
|
||||
Box::new(move |_| Box::new(manual_take::ManualTake::new(conf))),
|
||||
Box::new(|_| Box::new(manual_checked_ops::ManualCheckedOps)),
|
||||
Box::new(move |tcx| Box::new(manual_pop_if::ManualPopIf::new(tcx, conf))),
|
||||
Box::new(|_| Box::new(manual_noop_waker::ManualNoopWaker)),
|
||||
Box::new(move |_| Box::new(manual_noop_waker::ManualNoopWaker::new(conf))),
|
||||
// add late passes here, used by `cargo dev new_lint`
|
||||
];
|
||||
store.late_passes.extend(late_lints);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use clippy_config::Conf;
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::{is_empty_block, sym};
|
||||
use rustc_hir::{ImplItemKind, Item, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_session::impl_lint_pass;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
@@ -35,7 +37,17 @@
|
||||
"manual implementations of noop wakers can be simplified using Waker::noop()"
|
||||
}
|
||||
|
||||
declare_lint_pass!(ManualNoopWaker => [MANUAL_NOOP_WAKER]);
|
||||
impl_lint_pass!(ManualNoopWaker => [MANUAL_NOOP_WAKER]);
|
||||
|
||||
pub struct ManualNoopWaker {
|
||||
msrv: Msrv,
|
||||
}
|
||||
|
||||
impl ManualNoopWaker {
|
||||
pub fn new(conf: &'static Conf) -> Self {
|
||||
Self { msrv: conf.msrv }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualNoopWaker {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
@@ -43,6 +55,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
&& let Some(trait_ref) = imp.of_trait
|
||||
&& let Some(trait_id) = trait_ref.trait_ref.trait_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::Wake, trait_id)
|
||||
&& self.msrv.meets(cx, msrvs::WAKER_NOOP)
|
||||
{
|
||||
for impl_item_ref in imp.items {
|
||||
let impl_item = cx
|
||||
|
||||
@@ -28,7 +28,7 @@ macro_rules! msrv_aliases {
|
||||
1,88,0 { LET_CHAINS }
|
||||
1,87,0 { OS_STR_DISPLAY, INT_MIDPOINT, CONST_CHAR_IS_DIGIT, UNSIGNED_IS_MULTIPLE_OF, INTEGER_SIGN_CAST }
|
||||
1,86,0 { VEC_POP_IF }
|
||||
1,85,0 { UINT_FLOAT_MIDPOINT, CONST_SIZE_OF_VAL }
|
||||
1,85,0 { UINT_FLOAT_MIDPOINT, CONST_SIZE_OF_VAL, WAKER_NOOP }
|
||||
1,84,0 { CONST_OPTION_AS_SLICE, MANUAL_DANGLING_PTR }
|
||||
1,83,0 { CONST_EXTERN_FN, CONST_FLOAT_BITS_CONV, CONST_FLOAT_CLASSIFY, CONST_MUT_REFS, CONST_UNWRAP }
|
||||
1,82,0 { IS_NONE_OR, REPEAT_N, RAW_REF_OP, SPECIALIZED_TO_STRING_FOR_REFS }
|
||||
|
||||
@@ -38,3 +38,28 @@ fn wake(self: Arc<Self>) {}
|
||||
fn wake_by_ref(self: &Arc<Self>) {}
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.84"]
|
||||
mod msrv_1_84 {
|
||||
use std::sync::Arc;
|
||||
use std::task::Wake;
|
||||
|
||||
struct CustomWaker;
|
||||
impl Wake for CustomWaker {
|
||||
fn wake(self: Arc<Self>) {}
|
||||
fn wake_by_ref(self: &Arc<Self>) {}
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.85"]
|
||||
mod msrv_1_85 {
|
||||
use std::sync::Arc;
|
||||
use std::task::Wake;
|
||||
|
||||
struct CustomWaker;
|
||||
impl Wake for CustomWaker {
|
||||
//~^ manual_noop_waker
|
||||
fn wake(self: Arc<Self>) {}
|
||||
fn wake_by_ref(self: &Arc<Self>) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,13 @@ LL | impl Wake for MyWakerPartial {
|
||||
|
|
||||
= help: use `std::task::Waker::noop()` instead
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: manual implementation of a no-op waker
|
||||
--> tests/ui/manual_noop_waker.rs:60:10
|
||||
|
|
||||
LL | impl Wake for CustomWaker {
|
||||
| ^^^^
|
||||
|
|
||||
= help: use `std::task::Waker::noop()` instead
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user