mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Add configuration for raw pointer heuristic
This commit is contained in:
parent
d413e157a5
commit
427a09ba7b
@ -535,7 +535,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
store.register_late_pass(move || Box::new(feature_name::FeatureName));
|
||||
store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
|
||||
store.register_late_pass(move || Box::new(if_then_panic::IfThenPanic));
|
||||
store.register_late_pass(|| Box::new(non_send_field_in_send_ty::NonSendFieldInSendTy));
|
||||
let enable_raw_pointer_heuristic = conf.enable_raw_pointer_heuristic;
|
||||
store.register_late_pass(move || Box::new(non_send_field_in_send_ty::NonSendFieldInSendTy::new(enable_raw_pointer_heuristic)));
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Item, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, subst::GenericArgKind, Ty};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
|
||||
@ -48,10 +48,29 @@ declare_clippy_lint! {
|
||||
"there is field that does not implement `Send` in a `Send` struct"
|
||||
}
|
||||
|
||||
declare_lint_pass!(NonSendFieldInSendTy => [NON_SEND_FIELD_IN_SEND_TY]);
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct NonSendFieldInSendTy {
|
||||
enable_raw_pointer_heuristic: bool,
|
||||
}
|
||||
|
||||
impl NonSendFieldInSendTy {
|
||||
pub fn new(enable_raw_pointer_heuristic: bool) -> Self {
|
||||
Self {
|
||||
enable_raw_pointer_heuristic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(NonSendFieldInSendTy => [NON_SEND_FIELD_IN_SEND_TY]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
let ty_allowed_in_send = if self.enable_raw_pointer_heuristic {
|
||||
ty_allowed_with_raw_pointer_heuristic
|
||||
} else {
|
||||
ty_implements_send_or_copy
|
||||
};
|
||||
|
||||
// Checks if we are in `Send` impl item.
|
||||
// We start from `Send` impl instead of `check_field_def()` because
|
||||
// single `AdtDef` may have multiple `Send` impls due to generic
|
||||
@ -157,13 +176,6 @@ fn collect_generic_params<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Vec<Ty<
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Determine if the given type is allowed in an ADT that implements `Send`
|
||||
fn ty_allowed_in_send(cx: &LateContext<'tcx>, ty: Ty<'tcx>, send_trait: DefId) -> bool {
|
||||
// TODO: check configuration and call `ty_implements_send_or_copy()` or
|
||||
// `ty_allowed_with_raw_pointer_heuristic()`
|
||||
ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
|
@ -284,6 +284,10 @@ define_Conf! {
|
||||
///
|
||||
/// The list of unicode scripts allowed to be used in the scope.
|
||||
(allowed_scripts: Vec<String> = vec!["Latin".to_string()]),
|
||||
/// Lint: NON_SEND_FIELD_IN_SEND_TY.
|
||||
///
|
||||
/// Whether to apply the raw pointer heuristic in `non_send_field_in_send_ty` lint.
|
||||
(enable_raw_pointer_heuristic: bool = true),
|
||||
}
|
||||
|
||||
/// Search for the configuration file.
|
||||
|
@ -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`, `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`, `third-party` at line 5 column 1
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user