1- use clippy_utils:: diagnostics:: span_lint_and_sugg ;
1+ use clippy_utils:: diagnostics:: span_lint_hir_and_then ;
22use itertools:: Itertools ;
33use rustc_errors:: Applicability ;
4- use rustc_hir:: { Item , ItemKind } ;
4+ use rustc_hir:: { HirId , Item , ItemKind } ;
55use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
66use rustc_middle:: lint:: in_external_macro;
77use rustc_session:: impl_lint_pass;
@@ -77,7 +77,7 @@ fn correct_ident(ident: &str) -> String {
7777 ident
7878}
7979
80- fn check_ident ( cx : & LateContext < ' _ > , ident : & Ident , be_aggressive : bool ) {
80+ fn check_ident ( cx : & LateContext < ' _ > , ident : & Ident , hir_id : HirId , be_aggressive : bool ) {
8181 let span = ident. span ;
8282 let ident = ident. as_str ( ) ;
8383 let corrected = correct_ident ( ident) ;
@@ -89,14 +89,20 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
8989 // upper-case-acronyms-aggressive config option enabled
9090 || ( be_aggressive && ident != corrected)
9191 {
92- span_lint_and_sugg (
92+ span_lint_hir_and_then (
9393 cx,
9494 UPPER_CASE_ACRONYMS ,
95+ hir_id,
9596 span,
9697 & format ! ( "name `{ident}` contains a capitalized acronym" ) ,
97- "consider making the acronym lowercase, except the initial letter" ,
98- corrected,
99- Applicability :: MaybeIncorrect ,
98+ |diag| {
99+ diag. span_suggestion (
100+ span,
101+ "consider making the acronym lowercase, except the initial letter" ,
102+ corrected,
103+ Applicability :: MaybeIncorrect ,
104+ ) ;
105+ } ,
100106 ) ;
101107 }
102108}
@@ -111,16 +117,15 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
111117 }
112118 match it. kind {
113119 ItemKind :: TyAlias ( ..) | ItemKind :: Struct ( ..) | ItemKind :: Trait ( ..) => {
114- check_ident ( cx, & it. ident , self . upper_case_acronyms_aggressive ) ;
120+ check_ident ( cx, & it. ident , it . hir_id ( ) , self . upper_case_acronyms_aggressive ) ;
115121 } ,
116122 ItemKind :: Enum ( ref enumdef, _) => {
117- check_ident ( cx, & it. ident , self . upper_case_acronyms_aggressive ) ;
123+ check_ident ( cx, & it. ident , it . hir_id ( ) , self . upper_case_acronyms_aggressive ) ;
118124 // check enum variants separately because again we only want to lint on private enums and
119125 // the fn check_variant does not know about the vis of the enum of its variants
120- enumdef
121- . variants
122- . iter ( )
123- . for_each ( |variant| check_ident ( cx, & variant. ident , self . upper_case_acronyms_aggressive ) ) ;
126+ enumdef. variants . iter ( ) . for_each ( |variant| {
127+ check_ident ( cx, & variant. ident , variant. hir_id , self . upper_case_acronyms_aggressive ) ;
128+ } ) ;
124129 } ,
125130 _ => { } ,
126131 }
0 commit comments