Skip to content

Commit 9947495

Browse files
committed
Do not use full type path in help message
1 parent febad00 commit 9947495

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

clippy_lints/src/non_send_field_in_send_ty.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::is_lint_allowed;
3+
use clippy_utils::source::snippet;
34
use clippy_utils::ty::{implements_trait, is_copy};
45
use rustc_ast::ImplPolarity;
56
use rustc_hir::def_id::DefId;
6-
use rustc_hir::{Item, ItemKind};
7+
use rustc_hir::{FieldDef, Item, ItemKind, Node};
78
use rustc_lint::{LateContext, LateLintPass};
89
use rustc_middle::ty::{self, subst::GenericArgKind, Ty};
910
use rustc_session::{declare_tool_lint, impl_lint_pass};
10-
use rustc_span::symbol::Symbol;
11-
use rustc_span::{sym, Span};
11+
use rustc_span::sym;
1212

1313
declare_clippy_lint! {
1414
/// ### What it does
@@ -99,11 +99,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
9999
if !is_lint_allowed(cx, NON_SEND_FIELD_IN_SEND_TY, field_hir_id);
100100
if let field_ty = field.ty(cx.tcx, impl_trait_substs);
101101
if !ty_allowed_in_send(cx, field_ty, send_trait);
102-
if let Some(field_span) = hir_map.span_if_local(field.did);
102+
if let Node::Field(field_def) = hir_map.get(field_hir_id);
103103
then {
104104
non_send_fields.push(NonSendField {
105-
name: hir_map.name(field_hir_id),
106-
span: field_span,
105+
def: field_def,
107106
ty: field_ty,
108107
generic_params: collect_generic_params(cx, field_ty),
109108
})
@@ -119,13 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
119118
item.span,
120119
&format!(
121120
"this implementation is unsound, as some fields in `{}` are `!Send`",
122-
self_ty
121+
snippet(cx, hir_impl.self_ty.span, "Unknown")
123122
),
124123
|diag| {
125124
for field in non_send_fields {
126125
diag.span_note(
127-
field.span,
128-
&format!("the field `{}` has type `{}` which is `!Send`", field.name, field.ty),
126+
field.def.span,
127+
&format!("the type of field `{}` is `!Send`", field.def.ident.name),
129128
);
130129

131130
match field.generic_params.len() {
@@ -135,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
135134
"add bounds on type parameter{} `{}` that satisfy `{}: Send`",
136135
if field.generic_params.len() > 1 { "s" } else { "" },
137136
field.generic_params_string(),
138-
field.ty
137+
snippet(cx, field.def.ty.span, "Unknown"),
139138
)),
140139
};
141140
}
@@ -148,8 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
148147
}
149148

150149
struct NonSendField<'tcx> {
151-
name: Symbol,
152-
span: Span,
150+
def: &'tcx FieldDef<'tcx>,
153151
ty: Ty<'tcx>,
154152
generic_params: Vec<Ty<'tcx>>,
155153
}

tests/ui/non_send_field_in_send_ty.stderr

+19-19
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,46 @@ LL | unsafe impl<T> Send for RingBuffer<T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::non-send-field-in-send-ty` implied by `-D warnings`
8-
note: the field `data` has type `std::vec::Vec<std::cell::UnsafeCell<T>>` which is `!Send`
8+
note: the type of field `data` is `!Send`
99
--> $DIR/non_send_field_in_send_ty.rs:11:5
1010
|
1111
LL | data: Vec<UnsafeCell<T>>,
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^
13-
= help: add bounds on type parameter `T` that satisfy `std::vec::Vec<std::cell::UnsafeCell<T>>: Send`
13+
= help: add bounds on type parameter `T` that satisfy `Vec<UnsafeCell<T>>: Send`
1414

1515
error: this implementation is unsound, as some fields in `MvccRwLock<T>` are `!Send`
1616
--> $DIR/non_send_field_in_send_ty.rs:24:1
1717
|
1818
LL | unsafe impl<T> Send for MvccRwLock<T> {}
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
21-
note: the field `lock` has type `std::sync::Mutex<std::boxed::Box<T>>` which is `!Send`
21+
note: the type of field `lock` is `!Send`
2222
--> $DIR/non_send_field_in_send_ty.rs:21:5
2323
|
2424
LL | lock: Mutex<Box<T>>,
2525
| ^^^^^^^^^^^^^^^^^^^
26-
= help: add bounds on type parameter `T` that satisfy `std::sync::Mutex<std::boxed::Box<T>>: Send`
26+
= help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send`
2727

2828
error: this implementation is unsound, as some fields in `ArcGuard<RC, T>` are `!Send`
2929
--> $DIR/non_send_field_in_send_ty.rs:32:1
3030
|
3131
LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333
|
34-
note: the field `head` has type `std::sync::Arc<RC>` which is `!Send`
34+
note: the type of field `head` is `!Send`
3535
--> $DIR/non_send_field_in_send_ty.rs:29:5
3636
|
3737
LL | head: Arc<RC>,
3838
| ^^^^^^^^^^^^^
39-
= help: add bounds on type parameter `RC` that satisfy `std::sync::Arc<RC>: Send`
39+
= help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send`
4040

4141
error: this implementation is unsound, as some fields in `DeviceHandle<T>` are `!Send`
4242
--> $DIR/non_send_field_in_send_ty.rs:48:1
4343
|
4444
LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4646
|
47-
note: the field `context` has type `T` which is `!Send`
47+
note: the type of field `context` is `!Send`
4848
--> $DIR/non_send_field_in_send_ty.rs:44:5
4949
|
5050
LL | context: T,
@@ -57,7 +57,7 @@ error: this implementation is unsound, as some fields in `NoGeneric` are `!Send`
5757
LL | unsafe impl Send for NoGeneric {}
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959
|
60-
note: the field `rc_is_not_send` has type `std::rc::Rc<std::string::String>` which is `!Send`
60+
note: the type of field `rc_is_not_send` is `!Send`
6161
--> $DIR/non_send_field_in_send_ty.rs:52:5
6262
|
6363
LL | rc_is_not_send: Rc<String>,
@@ -70,19 +70,19 @@ error: this implementation is unsound, as some fields in `MultiField<T>` are `!S
7070
LL | unsafe impl<T> Send for MultiField<T> {}
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7272
|
73-
note: the field `field1` has type `T` which is `!Send`
73+
note: the type of field `field1` is `!Send`
7474
--> $DIR/non_send_field_in_send_ty.rs:58:5
7575
|
7676
LL | field1: T,
7777
| ^^^^^^^^^
7878
= help: add `T: Send` bound in `Send` impl
79-
note: the field `field2` has type `T` which is `!Send`
79+
note: the type of field `field2` is `!Send`
8080
--> $DIR/non_send_field_in_send_ty.rs:59:5
8181
|
8282
LL | field2: T,
8383
| ^^^^^^^^^
8484
= help: add `T: Send` bound in `Send` impl
85-
note: the field `field3` has type `T` which is `!Send`
85+
note: the type of field `field3` is `!Send`
8686
--> $DIR/non_send_field_in_send_ty.rs:60:5
8787
|
8888
LL | field3: T,
@@ -95,7 +95,7 @@ error: this implementation is unsound, as some fields in `MyOption<T>` are `!Sen
9595
LL | unsafe impl<T> Send for MyOption<T> {}
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9797
|
98-
note: the field `0` has type `T` which is `!Send`
98+
note: the type of field `0` is `!Send`
9999
--> $DIR/non_send_field_in_send_ty.rs:66:12
100100
|
101101
LL | MySome(T),
@@ -108,20 +108,20 @@ error: this implementation is unsound, as some fields in `MultiParam<A, B>` are
108108
LL | unsafe impl<A, B> Send for MultiParam<A, B> {}
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110110
|
111-
note: the field `vec` has type `std::vec::Vec<(A, B)>` which is `!Send`
111+
note: the type of field `vec` is `!Send`
112112
--> $DIR/non_send_field_in_send_ty.rs:74:5
113113
|
114114
LL | vec: Vec<(A, B)>,
115115
| ^^^^^^^^^^^^^^^^
116-
= help: add bounds on type parameters `A, B` that satisfy `std::vec::Vec<(A, B)>: Send`
116+
= help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send`
117117

118118
error: this implementation is unsound, as some fields in `HeuristicTest` are `!Send`
119119
--> $DIR/non_send_field_in_send_ty.rs:95:1
120120
|
121121
LL | unsafe impl Send for HeuristicTest {}
122122
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123123
|
124-
note: the field `field4` has type `(*const NonSend, std::rc::Rc<u8>)` which is `!Send`
124+
note: the type of field `field4` is `!Send`
125125
--> $DIR/non_send_field_in_send_ty.rs:90:5
126126
|
127127
LL | field4: (*const NonSend, Rc<u8>),
@@ -134,7 +134,7 @@ error: this implementation is unsound, as some fields in `AttrTest3<T>` are `!Se
134134
LL | unsafe impl<T> Send for AttrTest3<T> {}
135135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136136
|
137-
note: the field `0` has type `T` which is `!Send`
137+
note: the type of field `0` is `!Send`
138138
--> $DIR/non_send_field_in_send_ty.rs:109:11
139139
|
140140
LL | Enum2(T),
@@ -147,20 +147,20 @@ error: this implementation is unsound, as some fields in `Complex<P, u32>` are `
147147
LL | unsafe impl<P> Send for Complex<P, u32> {}
148148
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149149
|
150-
note: the field `field1` has type `P` which is `!Send`
150+
note: the type of field `field1` is `!Send`
151151
--> $DIR/non_send_field_in_send_ty.rs:118:5
152152
|
153153
LL | field1: A,
154154
| ^^^^^^^^^
155155
= help: add `P: Send` bound in `Send` impl
156156

157-
error: this implementation is unsound, as some fields in `Complex<Q, std::sync::MutexGuard<'static, bool>>` are `!Send`
157+
error: this implementation is unsound, as some fields in `Complex<Q, MutexGuard<'static, bool>>` are `!Send`
158158
--> $DIR/non_send_field_in_send_ty.rs:125:1
159159
|
160160
LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
161161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
162162
|
163-
note: the field `field2` has type `std::sync::MutexGuard<'static, bool>` which is `!Send`
163+
note: the type of field `field2` is `!Send`
164164
--> $DIR/non_send_field_in_send_ty.rs:119:5
165165
|
166166
LL | field2: B,

0 commit comments

Comments
 (0)