Add ui-test for enable-raw-pointer-heuristic-for-send config
This commit is contained in:
parent
08f0aecffd
commit
4f01656a7d
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||
let ty_allowed_in_send = if self.enable_raw_pointer_heuristic {
|
||||
ty_allowed_with_raw_pointer_heuristic
|
||||
} else {
|
||||
ty_implements_send_or_copy
|
||||
ty_allowed_without_raw_pointer_heuristic
|
||||
};
|
||||
|
||||
// Checks if we are in `Send` impl item.
|
||||
@ -176,14 +176,22 @@ fn collect_generic_params<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Vec<Ty<
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Determine if the given type is `Send` or `Copy`
|
||||
fn ty_implements_send_or_copy(cx: &LateContext<'tcx>, ty: Ty<'tcx>, send_trait: DefId) -> bool {
|
||||
implements_trait(cx, ty, send_trait, &[]) || is_copy(cx, ty)
|
||||
/// Be more strict when the heuristic is disabled
|
||||
fn ty_allowed_without_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, send_trait: DefId) -> bool {
|
||||
if implements_trait(cx, ty, send_trait, &[]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if is_copy(cx, ty) && !contains_raw_pointer(cx, ty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// Heuristic to allow cases like `Vec<*const u8>`
|
||||
fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, send_trait: DefId) -> bool {
|
||||
if ty_implements_send_or_copy(cx, ty, send_trait) {
|
||||
if implements_trait(cx, ty, send_trait, &[]) || is_copy(cx, ty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
enable-raw-pointer-heuristic-for-send = false
|
43
tests/ui-toml/strict_non_send_field_in_send_ty/test.rs
Normal file
43
tests/ui-toml/strict_non_send_field_in_send_ty/test.rs
Normal file
@ -0,0 +1,43 @@
|
||||
#![warn(clippy::non_send_field_in_send_ty)]
|
||||
#![feature(extern_types)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
// Basic tests should not be affected
|
||||
pub struct NoGeneric {
|
||||
rc_is_not_send: Rc<String>,
|
||||
}
|
||||
|
||||
unsafe impl Send for NoGeneric {}
|
||||
|
||||
pub struct MultiField<T> {
|
||||
field1: T,
|
||||
field2: T,
|
||||
field3: T,
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for MultiField<T> {}
|
||||
|
||||
pub enum MyOption<T> {
|
||||
MySome(T),
|
||||
MyNone,
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for MyOption<T> {}
|
||||
|
||||
// All fields are disallowed when raw pointer heuristic is off
|
||||
extern "C" {
|
||||
type NonSend;
|
||||
}
|
||||
|
||||
pub struct HeuristicTest {
|
||||
field1: Vec<*const NonSend>,
|
||||
field2: [*const NonSend; 3],
|
||||
field3: (*const NonSend, *const NonSend, *const NonSend),
|
||||
field4: (*const NonSend, Rc<u8>),
|
||||
field5: Vec<Vec<*const NonSend>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for HeuristicTest {}
|
||||
|
||||
fn main() {}
|
91
tests/ui-toml/strict_non_send_field_in_send_ty/test.stderr
Normal file
91
tests/ui-toml/strict_non_send_field_in_send_ty/test.stderr
Normal file
@ -0,0 +1,91 @@
|
||||
error: this implementation is unsound, as some fields in `NoGeneric` are `!Send`
|
||||
--> $DIR/test.rs:11:1
|
||||
|
|
||||
LL | unsafe impl Send for NoGeneric {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::non-send-field-in-send-ty` implied by `-D warnings`
|
||||
note: the field `rc_is_not_send` has type `std::rc::Rc<std::string::String>` which is `!Send`
|
||||
--> $DIR/test.rs:8:5
|
||||
|
|
||||
LL | rc_is_not_send: Rc<String>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
|
||||
error: this implementation is unsound, as some fields in `MultiField<T>` are `!Send`
|
||||
--> $DIR/test.rs:19:1
|
||||
|
|
||||
LL | unsafe impl<T> Send for MultiField<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field1` has type `T` which is `!Send`
|
||||
--> $DIR/test.rs:14:5
|
||||
|
|
||||
LL | field1: T,
|
||||
| ^^^^^^^^^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
note: the field `field2` has type `T` which is `!Send`
|
||||
--> $DIR/test.rs:15:5
|
||||
|
|
||||
LL | field2: T,
|
||||
| ^^^^^^^^^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
note: the field `field3` has type `T` which is `!Send`
|
||||
--> $DIR/test.rs:16:5
|
||||
|
|
||||
LL | field3: T,
|
||||
| ^^^^^^^^^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
|
||||
error: this implementation is unsound, as some fields in `MyOption<T>` are `!Send`
|
||||
--> $DIR/test.rs:26:1
|
||||
|
|
||||
LL | unsafe impl<T> Send for MyOption<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `0` has type `T` which is `!Send`
|
||||
--> $DIR/test.rs:22:12
|
||||
|
|
||||
LL | MySome(T),
|
||||
| ^
|
||||
= help: add `T: Send` bound in `Send` impl
|
||||
|
||||
error: this implementation is unsound, as some fields in `HeuristicTest` are `!Send`
|
||||
--> $DIR/test.rs:41:1
|
||||
|
|
||||
LL | unsafe impl Send for HeuristicTest {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the field `field1` has type `std::vec::Vec<*const NonSend>` which is `!Send`
|
||||
--> $DIR/test.rs:34:5
|
||||
|
|
||||
LL | field1: Vec<*const NonSend>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
note: the field `field2` has type `[*const NonSend; 3]` which is `!Send`
|
||||
--> $DIR/test.rs:35:5
|
||||
|
|
||||
LL | field2: [*const NonSend; 3],
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
note: the field `field3` has type `(*const NonSend, *const NonSend, *const NonSend)` which is `!Send`
|
||||
--> $DIR/test.rs:36:5
|
||||
|
|
||||
LL | field3: (*const NonSend, *const NonSend, *const NonSend),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
note: the field `field4` has type `(*const NonSend, std::rc::Rc<u8>)` which is `!Send`
|
||||
--> $DIR/test.rs:37:5
|
||||
|
|
||||
LL | field4: (*const NonSend, Rc<u8>),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
note: the field `field5` has type `std::vec::Vec<std::vec::Vec<*const NonSend>>` which is `!Send`
|
||||
--> $DIR/test.rs:38:5
|
||||
|
|
||||
LL | field5: Vec<Vec<*const NonSend>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use a thread-safe type that implements `Send`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `enable-raw-pointer-heuristic`, `third-party` at line 5 column 1
|
||||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `enable-raw-pointer-heuristic-for-send`, `third-party` at line 5 column 1
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user