@@ -152,13 +152,51 @@ where
152
152
} ) ;
153
153
}
154
154
155
+ /// Like [`span_lint`], but allows providing the `HirId` of the node that caused us to emit this
156
+ /// lint.
157
+ ///
158
+ /// The `HirId` is used for checking lint level attributes.
159
+ ///
160
+ /// For example:
161
+ /// ```ignore
162
+ /// fn f() { /* '1 */
163
+ ///
164
+ /// #[allow(clippy::some_lint)]
165
+ /// let _x = /* '2 */;
166
+ /// }
167
+ /// ```
168
+ /// If `some_lint` does its analysis in `LintPass::check_fn` (at `'1`) and emits a lint at `'2`
169
+ /// using [`span_lint`], then allowing the lint at `'2` as attempted in the snippet will not work!
170
+ /// Even though that is where the warning points at, which would be confusing to users.
171
+ ///
172
+ /// Instead, use this function and also pass the `HirId` of the node at `'2`, which will let the
173
+ /// compiler check lint level attributes at `'2` as one would expect, and the `#[allow]` will work.
155
174
pub fn span_lint_hir ( cx : & LateContext < ' _ > , lint : & ' static Lint , hir_id : HirId , sp : Span , msg : & str ) {
156
175
#[ expect( clippy:: disallowed_methods) ]
157
176
cx. tcx . node_span_lint ( lint, hir_id, sp, msg. to_string ( ) , |diag| {
158
177
docs_link ( diag, lint) ;
159
178
} ) ;
160
179
}
161
180
181
+ /// Like [`span_lint_and_then`], but allows providing the `HirId` of the node that caused us to emit
182
+ /// this lint.
183
+ ///
184
+ /// The `HirId` is used for checking lint level attributes.
185
+ ///
186
+ /// For example:
187
+ /// ```ignore
188
+ /// fn f() { /* '1 */
189
+ ///
190
+ /// #[allow(clippy::some_lint)]
191
+ /// let _x = /* '2 */;
192
+ /// }
193
+ /// ```
194
+ /// If `some_lint` does its analysis in `LintPass::check_fn` (at `'1`) and emits a lint at `'2`
195
+ /// using [`span_lint_and_then`], then allowing the lint at `'2` as attempted in the snippet will
196
+ /// not work! Even though that is where the warning points at, which would be confusing to users.
197
+ ///
198
+ /// Instead, use this function and also pass the `HirId` of the node at `'2`, which will let the
199
+ /// compiler check lint level attributes at `'2` as one would expect, and the `#[allow]` will work.
162
200
pub fn span_lint_hir_and_then (
163
201
cx : & LateContext < ' _ > ,
164
202
lint : & ' static Lint ,
0 commit comments