1
- use clippy_utils:: diagnostics:: span_lint_and_sugg ;
1
+ use clippy_utils:: diagnostics:: span_lint_hir_and_then ;
2
2
use itertools:: Itertools ;
3
3
use rustc_errors:: Applicability ;
4
- use rustc_hir:: { Item , ItemKind } ;
4
+ use rustc_hir:: { HirId , Item , ItemKind } ;
5
5
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
6
6
use rustc_middle:: lint:: in_external_macro;
7
7
use rustc_session:: impl_lint_pass;
@@ -77,7 +77,7 @@ fn correct_ident(ident: &str) -> String {
77
77
ident
78
78
}
79
79
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 ) {
81
81
let span = ident. span ;
82
82
let ident = ident. as_str ( ) ;
83
83
let corrected = correct_ident ( ident) ;
@@ -89,14 +89,20 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
89
89
// upper-case-acronyms-aggressive config option enabled
90
90
|| ( be_aggressive && ident != corrected)
91
91
{
92
- span_lint_and_sugg (
92
+ span_lint_hir_and_then (
93
93
cx,
94
94
UPPER_CASE_ACRONYMS ,
95
+ hir_id,
95
96
span,
96
97
& 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
+ } ,
100
106
) ;
101
107
}
102
108
}
@@ -111,16 +117,15 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
111
117
}
112
118
match it. kind {
113
119
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 ) ;
115
121
} ,
116
122
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 ) ;
118
124
// check enum variants separately because again we only want to lint on private enums and
119
125
// 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
+ } ) ;
124
129
} ,
125
130
_ => { } ,
126
131
}
0 commit comments