diff options
| author | Philipp Krones <hello@philkrones.com> | 2022-06-04 13:34:07 +0200 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2022-06-04 13:34:07 +0200 |
| commit | f067783461aff336e1273c9948d620d4009aedc4 (patch) | |
| tree | 0e752a00449438fe3444421e235a133212746859 /clippy_lints/src/utils | |
| parent | 57304823dbd1c246d1166e85c156e694d2f7a184 (diff) | |
Merge commit 'd9ddce8a223cb9916389c039777b6966ea448dc8' into clippyup
Diffstat (limited to 'clippy_lints/src/utils')
| -rw-r--r-- | clippy_lints/src/utils/conf.rs | 4 | ||||
| -rw-r--r-- | clippy_lints/src/utils/internal_lints.rs | 8 | ||||
| -rw-r--r-- | clippy_lints/src/utils/internal_lints/metadata_collector.rs | 58 |
3 files changed, 61 insertions, 9 deletions
diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index cd4d16fe95f..b5c5d35135f 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -340,6 +340,10 @@ define_Conf! { /// /// Whether `unwrap` should be allowed in test functions (allow_unwrap_in_tests: bool = false), + /// Lint: DBG_MACRO. + /// + /// Whether `dbg!` should be allowed in test functions + (allow_dbg_in_tests: bool = false), } /// Search for the configuration file. diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 0e8f40e9210..60f98876994 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -422,7 +422,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } } else if let Some(macro_call) = root_macro_call_first_node(cx, item) { if !matches!( - &*cx.tcx.item_name(macro_call.def_id).as_str(), + cx.tcx.item_name(macro_call.def_id).as_str(), "impl_lint_pass" | "declare_lint_pass" ) { return; @@ -504,7 +504,7 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<' return; } - if RustcVersion::parse(&*value.as_str()).is_err() { + if RustcVersion::parse(value.as_str()).is_err() { span_lint_and_help( cx, INVALID_CLIPPY_VERSION_ATTRIBUTE, @@ -595,7 +595,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { if_chain! { if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; let fn_name = path.ident; - if let Some(sugg) = self.map.get(&*fn_name.as_str()); + if let Some(sugg) = self.map.get(fn_name.as_str()); let ty = cx.typeck_results().expr_ty(self_arg).peel_refs(); if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT); @@ -679,7 +679,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { then { let and_then_snippets = get_and_then_snippets(cx, and_then_args); let mut sle = SpanlessEq::new(cx).deny_side_effects(); - match &*ps.ident.as_str() { + match ps.ident.as_str() { "span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[1]) => { suggest_suggestion(cx, expr, &and_then_snippets, &span_suggestion_snippets(cx, span_call_args)); }, diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 8c1910b3b2a..cf2de6a42af 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -7,6 +7,7 @@ //! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such //! a simple mistake) +use crate::renamed_lints::RENAMED_LINTS; use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type}; use clippy_utils::diagnostics::span_lint; @@ -26,6 +27,7 @@ use rustc_span::{sym, Loc, Span, Symbol}; use serde::{ser::SerializeStruct, Serialize, Serializer}; use std::collections::BinaryHeap; use std::fmt; +use std::fmt::Write as _; use std::fs::{self, OpenOptions}; use std::io::prelude::*; use std::path::Path; @@ -85,6 +87,21 @@ macro_rules! CONFIGURATION_VALUE_TEMPLATE { }; } +macro_rules! RENAMES_SECTION_TEMPLATE { + () => { + r#" +### Past names + +{names} +"# + }; +} +macro_rules! RENAME_VALUE_TEMPLATE { + () => { + "* `{name}`\n" + }; +} + const LINT_EMISSION_FUNCTIONS: [&[&str]; 8] = [ &["clippy_utils", "diagnostics", "span_lint"], &["clippy_utils", "diagnostics", "span_lint_and_help"], @@ -198,9 +215,10 @@ impl Drop for MetadataCollector { // Mapping the final data let mut lints = std::mem::take(&mut self.lints).into_sorted_vec(); - lints - .iter_mut() - .for_each(|x| x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default())); + collect_renames(&mut lints); + for x in &mut lints { + x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default()); + } // Outputting if Path::new(OUTPUT_FILE).exists() { @@ -527,12 +545,11 @@ fn extract_attr_docs_or_lint(cx: &LateContext<'_>, item: &Item<'_>) -> Option<St fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option<String> { let attrs = cx.tcx.hir().attrs(item.hir_id()); let mut lines = attrs.iter().filter_map(ast::Attribute::doc_str); - let mut docs = String::from(&*lines.next()?.as_str()); + let mut docs = String::from(lines.next()?.as_str()); let mut in_code_block = false; let mut is_code_block_rust = false; for line in lines { let line = line.as_str(); - let line = &*line; // Rustdoc hides code lines starting with `# ` and this removes them from Clippy's lint list :) if is_code_block_rust && line.trim_start().starts_with("# ") { @@ -643,6 +660,37 @@ fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } +fn collect_renames(lints: &mut Vec<LintMetadata>) { + for lint in lints { + let mut collected = String::new(); + let mut names = vec![lint.id.clone()]; + + loop { + if let Some(lint_name) = names.pop() { + for (k, v) in RENAMED_LINTS { + if_chain! { + if let Some(name) = v.strip_prefix(CLIPPY_LINT_GROUP_PREFIX); + if name == lint_name; + if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX); + then { + write!(collected, RENAME_VALUE_TEMPLATE!(), name = past_name).unwrap(); + names.push(past_name.to_string()); + } + } + } + + continue; + } + + break; + } + + if !collected.is_empty() { + write!(&mut lint.docs, RENAMES_SECTION_TEMPLATE!(), names = collected).unwrap(); + } + } +} + // ================================================================== // Lint emission // ================================================================== |
