diff options
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/lints.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/nonstandard_style.rs | 24 | 
2 files changed, 28 insertions, 11 deletions
| diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index d157bf6986c..a20050a10b4 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1349,7 +1349,7 @@ pub(crate) struct NonUpperCaseGlobal<'a> { #[subdiagnostic] pub sub: NonUpperCaseGlobalSub, #[subdiagnostic] - pub usages: Vec<NonUpperCaseGlobalSub>, + pub usages: Vec<NonUpperCaseGlobalSubTool>, } #[derive(Subdiagnostic)] @@ -1367,6 +1367,19 @@ pub(crate) enum NonUpperCaseGlobalSub { }, } +#[derive(Subdiagnostic)] +#[suggestion( + lint_suggestion, + code = "{replace}", + applicability = "maybe-incorrect", + style = "tool-only" +)] +pub(crate) struct NonUpperCaseGlobalSubTool { + #[primary_span] + pub(crate) span: Span, + pub(crate) replace: String, +} + // noop_method_call.rs #[derive(LintDiagnostic)] #[diag(lint_noop_method_call)] diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index a5b3eb3f0ff..e92e8e06382 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -14,7 +14,7 @@ use {rustc_ast as ast, rustc_hir as hir}; use crate::lints::{ NonCamelCaseType, NonCamelCaseTypeSub, NonSnakeCaseDiag, NonSnakeCaseDiagSub, - NonUpperCaseGlobal, NonUpperCaseGlobalSub, + NonUpperCaseGlobal, NonUpperCaseGlobalSub, NonUpperCaseGlobalSubTool, }; use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; @@ -497,12 +497,10 @@ impl NonUpperCaseGlobals { // We cannot provide meaningful suggestions // if the characters are in the category of "Lowercase Letter". - let sub = |span| { - if *name != uc { - NonUpperCaseGlobalSub::Suggestion { span, replace: uc.clone() } - } else { - NonUpperCaseGlobalSub::Label { span } - } + let sub = if *name != uc { + NonUpperCaseGlobalSub::Suggestion { span: ident.span, replace: uc.clone() } + } else { + NonUpperCaseGlobalSub::Label { span: ident.span } }; struct UsageCollector<'a, 'tcx> { @@ -531,10 +529,16 @@ impl NonUpperCaseGlobals { } } - let usages = if let Some(did) = did { + let usages = if let Some(did) = did + && *name != uc + { let mut usage_collector = UsageCollector { cx, did, collected: Vec::new() }; cx.tcx.hir_walk_toplevel_module(&mut usage_collector); - usage_collector.collected.into_iter().map(|span| sub(span)).collect() + usage_collector + .collected + .into_iter() + .map(|span| NonUpperCaseGlobalSubTool { span, replace: uc.clone() }) + .collect() } else { vec![] }; @@ -542,7 +546,7 @@ impl NonUpperCaseGlobals { cx.emit_span_lint( NON_UPPER_CASE_GLOBALS, ident.span, - NonUpperCaseGlobal { sort, name, sub: sub(ident.span), usages }, + NonUpperCaseGlobal { sort, name, sub, usages }, ); } } | 
