remove internal compiler_lint_functions
lint
This commit is contained in:
parent
2b01d69212
commit
ecbb2d7ba9
@ -1,5 +1,9 @@
|
|||||||
avoid-breaking-exported-api = false
|
avoid-breaking-exported-api = false
|
||||||
|
|
||||||
|
[[disallowed-methods]]
|
||||||
|
path = "rustc_lint::context::LintContext::lint"
|
||||||
|
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
|
||||||
|
|
||||||
[[disallowed-methods]]
|
[[disallowed-methods]]
|
||||||
path = "rustc_lint::context::LintContext::span_lint"
|
path = "rustc_lint::context::LintContext::span_lint"
|
||||||
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
|
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#[cfg(feature = "internal")]
|
#[cfg(feature = "internal")]
|
||||||
crate::utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS_INFO,
|
crate::utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS_INFO,
|
||||||
#[cfg(feature = "internal")]
|
#[cfg(feature = "internal")]
|
||||||
crate::utils::internal_lints::compiler_lint_functions::COMPILER_LINT_FUNCTIONS_INFO,
|
|
||||||
#[cfg(feature = "internal")]
|
|
||||||
crate::utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL_INFO,
|
crate::utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL_INFO,
|
||||||
#[cfg(feature = "internal")]
|
#[cfg(feature = "internal")]
|
||||||
crate::utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR_INFO,
|
crate::utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR_INFO,
|
||||||
|
@ -641,9 +641,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
|
|||||||
});
|
});
|
||||||
store.register_early_pass(|| Box::new(utils::internal_lints::produce_ice::ProduceIce));
|
store.register_early_pass(|| Box::new(utils::internal_lints::produce_ice::ProduceIce));
|
||||||
store.register_late_pass(|_| Box::new(utils::internal_lints::collapsible_calls::CollapsibleCalls));
|
store.register_late_pass(|_| Box::new(utils::internal_lints::collapsible_calls::CollapsibleCalls));
|
||||||
store.register_late_pass(|_| {
|
|
||||||
Box::new(utils::internal_lints::compiler_lint_functions::CompilerLintFunctions::new())
|
|
||||||
});
|
|
||||||
store.register_late_pass(|_| Box::new(utils::internal_lints::invalid_paths::InvalidPaths));
|
store.register_late_pass(|_| Box::new(utils::internal_lints::invalid_paths::InvalidPaths));
|
||||||
store.register_late_pass(|_| {
|
store.register_late_pass(|_| {
|
||||||
Box::<utils::internal_lints::interning_defined_symbol::InterningDefinedSymbol>::default()
|
Box::<utils::internal_lints::interning_defined_symbol::InterningDefinedSymbol>::default()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
pub mod almost_standard_lint_formulation;
|
pub mod almost_standard_lint_formulation;
|
||||||
pub mod collapsible_calls;
|
pub mod collapsible_calls;
|
||||||
pub mod compiler_lint_functions;
|
|
||||||
pub mod interning_defined_symbol;
|
pub mod interning_defined_symbol;
|
||||||
pub mod invalid_paths;
|
pub mod invalid_paths;
|
||||||
pub mod lint_without_lint_pass;
|
pub mod lint_without_lint_pass;
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
|
||||||
use clippy_utils::ty::match_type;
|
|
||||||
use clippy_utils::{is_lint_allowed, paths};
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
|
||||||
use rustc_hir::{Expr, ExprKind};
|
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
|
||||||
use rustc_session::impl_lint_pass;
|
|
||||||
|
|
||||||
declare_clippy_lint! {
|
|
||||||
/// ### What it does
|
|
||||||
/// Checks for calls to `cx.span_lint*` and suggests to use the `utils::*`
|
|
||||||
/// variant of the function.
|
|
||||||
///
|
|
||||||
/// ### Why is this bad?
|
|
||||||
/// The `utils::*` variants also add a link to the Clippy documentation to the
|
|
||||||
/// warning/error messages.
|
|
||||||
///
|
|
||||||
/// ### Example
|
|
||||||
/// ```rust,ignore
|
|
||||||
/// cx.span_lint(LINT_NAME, "message");
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// Use instead:
|
|
||||||
/// ```rust,ignore
|
|
||||||
/// utils::span_lint(cx, LINT_NAME, "message");
|
|
||||||
/// ```
|
|
||||||
pub COMPILER_LINT_FUNCTIONS,
|
|
||||||
internal,
|
|
||||||
"usage of the lint functions of the compiler instead of the utils::* variant"
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
|
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
|
||||||
pub struct CompilerLintFunctions {
|
|
||||||
map: FxHashMap<&'static str, &'static str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CompilerLintFunctions {
|
|
||||||
#[must_use]
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let mut map = FxHashMap::default();
|
|
||||||
map.insert("span_lint", "utils::span_lint");
|
|
||||||
map.insert("lint", "utils::span_lint");
|
|
||||||
map.insert("span_lint_note", "utils::span_lint_and_note");
|
|
||||||
map.insert("span_lint_help", "utils::span_lint_and_help");
|
|
||||||
Self { map }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
|
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
|
||||||
if is_lint_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let ExprKind::MethodCall(path, self_arg, _, _) = &expr.kind
|
|
||||||
&& let fn_name = path.ident
|
|
||||||
&& let Some(sugg) = self.map.get(fn_name.as_str())
|
|
||||||
&& let ty = cx.typeck_results().expr_ty(self_arg).peel_refs()
|
|
||||||
&& (match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT))
|
|
||||||
{
|
|
||||||
span_lint_and_help(
|
|
||||||
cx,
|
|
||||||
COMPILER_LINT_FUNCTIONS,
|
|
||||||
path.ident.span,
|
|
||||||
"usage of a compiler lint function",
|
|
||||||
None,
|
|
||||||
format!("please use the Clippy variant of this function: `{sugg}`"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user