Skip to content

Commit ecc0c19

Browse files
committed
store some DefIds in the struct
1 parent b3d0a09 commit ecc0c19

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

clippy_lints/src/future_not_send.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::print::PrintTraitRefExt;
1010
use rustc_middle::ty::{
1111
self, AliasTy, Binder, ClauseKind, PredicateKind, Ty, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor,
1212
};
13-
use rustc_session::declare_lint_pass;
14-
use rustc_span::def_id::LocalDefId;
13+
use rustc_session::impl_lint_pass;
14+
use rustc_span::def_id::{DefId, LocalDefId};
1515
use rustc_span::{Span, sym};
1616
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1717
use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt};
@@ -59,7 +59,21 @@ declare_clippy_lint! {
5959
"public Futures must be Send"
6060
}
6161

62-
declare_lint_pass!(FutureNotSend => [FUTURE_NOT_SEND]);
62+
impl_lint_pass!(FutureNotSend => [FUTURE_NOT_SEND]);
63+
64+
pub(crate) struct FutureNotSend {
65+
future_trait: Option<DefId>,
66+
send_trait: Option<DefId>,
67+
}
68+
69+
impl FutureNotSend {
70+
pub(crate) fn new(tcx: TyCtxt<'_>) -> Self {
71+
Self {
72+
future_trait: tcx.lang_items().future_trait(),
73+
send_trait: tcx.get_diagnostic_item(sym::Send),
74+
}
75+
}
76+
}
6377

6478
impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6579
fn check_fn(
@@ -76,8 +90,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7690
}
7791
let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner());
7892
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind()
79-
&& let Some(future_trait) = cx.tcx.lang_items().future_trait()
80-
&& let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send)
93+
&& let Some(future_trait) = self.future_trait
94+
&& let Some(send_trait) = self.send_trait
8195
{
8296
let preds = cx.tcx.explicit_item_self_bounds(def_id);
8397
let is_future = preds.iter_instantiated_copied(cx.tcx, args).any(|(p, _)| {

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
645645
store.register_late_pass(|_| Box::<redundant_pub_crate::RedundantPubCrate>::default());
646646
store.register_late_pass(|_| Box::<dereference::Dereferencing<'_>>::default());
647647
store.register_late_pass(|_| Box::new(option_if_let_else::OptionIfLetElse));
648-
store.register_late_pass(|_| Box::new(future_not_send::FutureNotSend));
648+
store.register_late_pass(|tcx| Box::new(future_not_send::FutureNotSend::new(tcx)));
649649
store.register_late_pass(move |_| Box::new(large_futures::LargeFuture::new(conf)));
650650
store.register_late_pass(|_| Box::new(if_let_mutex::IfLetMutex));
651651
store.register_late_pass(|_| Box::new(if_not_else::IfNotElse));

0 commit comments

Comments
 (0)