Do not use full type path in help message
This commit is contained in:
parent
4f01656a7d
commit
dfed2e31d5
@ -1,14 +1,14 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::is_lint_allowed;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::ty::{implements_trait, is_copy};
|
||||
use rustc_ast::ImplPolarity;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Item, ItemKind};
|
||||
use rustc_hir::{FieldDef, Item, ItemKind, Node};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, subst::GenericArgKind, Ty};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::sym;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
@ -99,11 +99,10 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if !is_lint_allowed(cx, NON_SEND_FIELD_IN_SEND_TY, field_hir_id);
|
||||
if let field_ty = field.ty(cx.tcx, impl_trait_substs);
|
||||
if !ty_allowed_in_send(cx, field_ty, send_trait);
|
||||
if let Some(field_span) = hir_map.span_if_local(field.did);
|
||||
if let Node::Field(field_def) = hir_map.get(field_hir_id);
|
||||
then {
|
||||
non_send_fields.push(NonSendField {
|
||||
name: hir_map.name(field_hir_id),
|
||||
span: field_span,
|
||||
def: field_def,
|
||||
ty: field_ty,
|
||||
generic_params: collect_generic_params(cx, field_ty),
|
||||
})
|
||||
@ -119,13 +118,13 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
item.span,
|
||||
&format!(
|
||||
"this implementation is unsound, as some fields in `{}` are `!Send`",
|
||||
self_ty
|
||||
snippet(cx, hir_impl.self_ty.span, "Unknown")
|
||||
),
|
||||
|diag| {
|
||||
for field in non_send_fields {
|
||||
diag.span_note(
|
||||
field.span,
|
||||
&format!("the field `{}` has type `{}` which is `!Send`", field.name, field.ty),
|
||||
field.def.span,
|
||||
&format!("the type of field `{}` is `!Send`", field.def.ident.name),
|
||||
);
|
||||
|
||||
match field.generic_params.len() {
|
||||
@ -135,7 +134,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
"add bounds on type parameter{} `{}` that satisfy `{}: Send`",
|
||||
if field.generic_params.len() > 1 { "s" } else { "" },
|
||||
field.generic_params_string(),
|
||||
field.ty
|
||||
snippet(cx, field.def.ty.span, "Unknown"),
|
||||
)),
|
||||
};
|
||||
}
|
||||
@ -148,8 +147,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
}
|
||||
|
||||
struct NonSendField<'tcx> {
|
||||
name: Symbol,
|
||||
span: Span,
|
||||
def: &'tcx FieldDef<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
generic_params: Vec<Ty<'tcx>>,
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ LL | unsafe impl<T> Send for RingBuffer<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::non-send-field-in-send-ty` implied by `-D warnings`
|
||||
note: the field `data` has type `std::vec::Vec<std::cell::UnsafeCell<T>>` which is `!Send`
|
||||
note: the type of field `data` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:11:5
|
||||
|
|
||||
LL | data: Vec<UnsafeCell<T>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: add bounds on type parameter `T` that satisfy `std::vec::Vec<std::cell::UnsafeCell<T>>: Send`
|
||||
= help: add bounds on type parameter `T` that satisfy `Vec<UnsafeCell<T>>: Send`
|
||||
|
||||
error: this implementation is unsound, as some fields in `MvccRwLock<T>` are `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:24:1
|
||||
@ -18,12 +18,12 @@ error: this implementation is unsound, as some fields in `MvccRwLock<T>` are `!S
|
||||
LL | unsafe impl<T> Send for MvccRwLock<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `lock` has type `std::sync::Mutex<std::boxed::Box<T>>` which is `!Send`
|
||||
note: the type of field `lock` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:21:5
|
||||
|
|
||||
LL | lock: Mutex<Box<T>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
= help: add bounds on type parameter `T` that satisfy `std::sync::Mutex<std::boxed::Box<T>>: Send`
|
||||
= help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send`
|
||||
|
||||
error: this implementation is unsound, as some fields in `ArcGuard<RC, T>` are `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:32:1
|
||||
@ -31,12 +31,12 @@ error: this implementation is unsound, as some fields in `ArcGuard<RC, T>` are `
|
||||
LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `head` has type `std::sync::Arc<RC>` which is `!Send`
|
||||
note: the type of field `head` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:29:5
|
||||
|
|
||||
LL | head: Arc<RC>,
|
||||
| ^^^^^^^^^^^^^
|
||||
= help: add bounds on type parameter `RC` that satisfy `std::sync::Arc<RC>: Send`
|
||||
= help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send`
|
||||
|
||||
error: this implementation is unsound, as some fields in `DeviceHandle<T>` are `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:48:1
|
||||
@ -44,7 +44,7 @@ error: this implementation is unsound, as some fields in `DeviceHandle<T>` are `
|
||||
LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `context` has type `T` which is `!Send`
|
||||
note: the type of field `context` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:44:5
|
||||
|
|
||||
LL | context: T,
|
||||
@ -57,7 +57,7 @@ error: this implementation is unsound, as some fields in `NoGeneric` are `!Send`
|
||||
LL | unsafe impl Send for NoGeneric {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `rc_is_not_send` has type `std::rc::Rc<std::string::String>` which is `!Send`
|
||||
note: the type of field `rc_is_not_send` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:52:5
|
||||
|
|
||||
LL | rc_is_not_send: Rc<String>,
|
||||
@ -70,19 +70,19 @@ error: this implementation is unsound, as some fields in `MultiField<T>` are `!S
|
||||
LL | unsafe impl<T> Send for MultiField<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field1` has type `T` which is `!Send`
|
||||
note: the type of field `field1` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:58:5
|
||||
|
|
||||
LL | field1: T,
|
||||
| ^^^^^^^^^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
note: the field `field2` has type `T` which is `!Send`
|
||||
note: the type of field `field2` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:59:5
|
||||
|
|
||||
LL | field2: T,
|
||||
| ^^^^^^^^^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
note: the field `field3` has type `T` which is `!Send`
|
||||
note: the type of field `field3` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:60:5
|
||||
|
|
||||
LL | field3: T,
|
||||
@ -95,7 +95,7 @@ error: this implementation is unsound, as some fields in `MyOption<T>` are `!Sen
|
||||
LL | unsafe impl<T> Send for MyOption<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `0` has type `T` which is `!Send`
|
||||
note: the type of field `0` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:66:12
|
||||
|
|
||||
LL | MySome(T),
|
||||
@ -108,12 +108,12 @@ error: this implementation is unsound, as some fields in `MultiParam<A, B>` are
|
||||
LL | unsafe impl<A, B> Send for MultiParam<A, B> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `vec` has type `std::vec::Vec<(A, B)>` which is `!Send`
|
||||
note: the type of field `vec` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:74:5
|
||||
|
|
||||
LL | vec: Vec<(A, B)>,
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= help: add bounds on type parameters `A, B` that satisfy `std::vec::Vec<(A, B)>: Send`
|
||||
= help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send`
|
||||
|
||||
error: this implementation is unsound, as some fields in `HeuristicTest` are `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:95:1
|
||||
@ -121,7 +121,7 @@ error: this implementation is unsound, as some fields in `HeuristicTest` are `!S
|
||||
LL | unsafe impl Send for HeuristicTest {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field4` has type `(*const NonSend, std::rc::Rc<u8>)` which is `!Send`
|
||||
note: the type of field `field4` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:90:5
|
||||
|
|
||||
LL | field4: (*const NonSend, Rc<u8>),
|
||||
@ -134,7 +134,7 @@ error: this implementation is unsound, as some fields in `AttrTest3<T>` are `!Se
|
||||
LL | unsafe impl<T> Send for AttrTest3<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `0` has type `T` which is `!Send`
|
||||
note: the type of field `0` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:109:11
|
||||
|
|
||||
LL | Enum2(T),
|
||||
@ -147,20 +147,20 @@ error: this implementation is unsound, as some fields in `Complex<P, u32>` are `
|
||||
LL | unsafe impl<P> Send for Complex<P, u32> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field1` has type `P` which is `!Send`
|
||||
note: the type of field `field1` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:118:5
|
||||
|
|
||||
LL | field1: A,
|
||||
| ^^^^^^^^^
|
||||
= help: add `P: Send` bound in `Send` impl
|
||||
|
||||
error: this implementation is unsound, as some fields in `Complex<Q, std::sync::MutexGuard<'static, bool>>` are `!Send`
|
||||
error: this implementation is unsound, as some fields in `Complex<Q, MutexGuard<'static, bool>>` are `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:125:1
|
||||
|
|
||||
LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field2` has type `std::sync::MutexGuard<'static, bool>` which is `!Send`
|
||||
note: the type of field `field2` is `!Send`
|
||||
--> $DIR/non_send_field_in_send_ty.rs:119:5
|
||||
|
|
||||
LL | field2: B,
|
||||
|
Loading…
Reference in New Issue
Block a user