@@ -36,14 +36,19 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) {
36
36
/// Usually it's nicer to provide more context for lint messages.
37
37
/// Be sure the output is understandable when you use this method.
38
38
///
39
- /// NOTE: only lint-level attributes at the `LintPass::check_*` node from which you are calling this
40
- /// will be considered .
41
- /// This can be confusing if the given span is at a different place, because users won't know where
42
- /// `#[allow]` or `#[expect]` attributes need to be placed .
39
+ /// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
40
+ /// the lint level .
41
+ /// For the `span_lint` function, the node that was passed into the `LintPass::check_*` function is
42
+ /// used .
43
43
///
44
- /// This can happen if, for example, you are in `LintPass::check_block` and you are emitting a lint
45
- /// for a particular expression within that block.
46
- /// In those cases, consider using [`span_lint_hir`], and pass the `HirId` of that expression.
44
+ /// If you're emitting the lint at the span of a different node than the one provided by the
45
+ /// `LintPass::check_*` function, consider using [`span_lint_hir`] instead.
46
+ /// This is needed for `#[allow]` and `#[expect]` attributes to work on the node
47
+ /// highlighted in the displayed warning.
48
+ ///
49
+ /// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
50
+ /// where you would expect it to.
51
+ /// If it doesn't, you likely need to use [`span_lint_hir`] instead.
47
52
///
48
53
/// # Example
49
54
///
@@ -70,14 +75,19 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
70
75
///
71
76
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
72
77
///
73
- /// NOTE: only lint-level attributes at the `LintPass::check_*` node from which you are calling this
74
- /// will be considered.
75
- /// This can be confusing if the given span is at a different place, because users won't know where
76
- /// `#[allow]` or `#[expect]` attributes need to be placed.
78
+ /// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
79
+ /// the lint level.
80
+ /// For the `span_lint_and_help` function, the node that was passed into the `LintPass::check_*`
81
+ /// function is used.
82
+ ///
83
+ /// If you're emitting the lint at the span of a different node than the one provided by the
84
+ /// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead.
85
+ /// This is needed for `#[allow]` and `#[expect]` attributes to work on the node
86
+ /// highlighted in the displayed warning.
77
87
///
78
- /// This can happen if, for example, you are in `LintPass::check_block` and you are emitting a lint
79
- /// for a particular expression within that block .
80
- /// In those cases, consider using [`span_lint_hir`], and pass the `HirId` of that expression .
88
+ /// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
89
+ /// where you would expect it to .
90
+ /// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead .
81
91
///
82
92
/// # Example
83
93
///
@@ -117,14 +127,19 @@ pub fn span_lint_and_help<T: LintContext>(
117
127
///
118
128
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
119
129
///
120
- /// NOTE: only lint-level attributes at the `LintPass::check_*` node from which you are calling this
121
- /// will be considered .
122
- /// This can be confusing if the given span is at a different place, because users won't know where
123
- /// `#[allow]` or `#[expect]` attributes need to be placed .
130
+ /// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
131
+ /// the lint level .
132
+ /// For the `span_lint_and_note` function, the node that was passed into the `LintPass::check_*`
133
+ /// function is used .
124
134
///
125
- /// This can happen if, for example, you are in `LintPass::check_block` and you are emitting a lint
126
- /// for a particular expression within that block.
127
- /// In those cases, consider using [`span_lint_hir`], and pass the `HirId` of that expression.
135
+ /// If you're emitting the lint at the span of a different node than the one provided by the
136
+ /// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead.
137
+ /// This is needed for `#[allow]` and `#[expect]` attributes to work on the node
138
+ /// highlighted in the displayed warning.
139
+ ///
140
+ /// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
141
+ /// where you would expect it to.
142
+ /// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead.
128
143
///
129
144
/// # Example
130
145
///
@@ -167,14 +182,19 @@ pub fn span_lint_and_note<T: LintContext>(
167
182
/// If you need to customize your lint output a lot, use this function.
168
183
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
169
184
///
170
- /// NOTE: only lint-level attributes at the `LintPass::check_*` node from which you are calling this
171
- /// will be considered.
172
- /// This can be confusing if the given span is at a different place, because users won't know where
173
- /// `#[allow]` or `#[expect]` attributes need to be placed.
185
+ /// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
186
+ /// the lint level.
187
+ /// For the `span_lint_and_then` function, the node that was passed into the `LintPass::check_*`
188
+ /// function is used.
189
+ ///
190
+ /// If you're emitting the lint at the span of a different node than the one provided by the
191
+ /// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead.
192
+ /// This is needed for `#[allow]` and `#[expect]` attributes to work on the node
193
+ /// highlighted in the displayed warning.
174
194
///
175
- /// This can happen if, for example, you are in `LintPass::check_block` and you are emitting a lint
176
- /// for a particular expression within that block .
177
- /// In those cases, consider using [`span_lint_hir`], and pass the `HirId` of that expression .
195
+ /// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
196
+ /// where you would expect it to .
197
+ /// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead .
178
198
pub fn span_lint_and_then < C , S , F > ( cx : & C , lint : & ' static Lint , sp : S , msg : & str , f : F )
179
199
where
180
200
C : LintContext ,
@@ -188,8 +208,10 @@ where
188
208
} ) ;
189
209
}
190
210
191
- /// Like [`span_lint`], but allows providing the `HirId` of the node that caused us to emit this
192
- /// lint.
211
+ /// Like [`span_lint`], but emits the lint at the node identified by the given `HirId`.
212
+ ///
213
+ /// This is in contrast to [`span_lint`], which always emits the lint at the node that was last
214
+ /// passed to the `LintPass::check_*` function.
193
215
///
194
216
/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined
195
217
/// via the `#[expect]` attribute.
@@ -217,8 +239,10 @@ pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, s
217
239
} ) ;
218
240
}
219
241
220
- /// Like [`span_lint_and_then`], but allows providing the `HirId` of the node that caused us to emit
221
- /// this lint.
242
+ /// Like [`span_lint_and_then`], but emits the lint at the node identified by the given `HirId`.
243
+ ///
244
+ /// This is in contrast to [`span_lint_and_then`], which always emits the lint at the node that was
245
+ /// last passed to the `LintPass::check_*` function.
222
246
///
223
247
/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined
224
248
/// via the `#[expect]` attribute.
@@ -262,14 +286,19 @@ pub fn span_lint_hir_and_then(
262
286
///
263
287
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
264
288
///
265
- /// NOTE: only lint-level attributes at the `LintPass::check_*` node from which you are calling this
266
- /// will be considered.
267
- /// This can be confusing if the given span is at a different place, because users won't know where
268
- /// `#[allow]` or `#[expect]` attributes need to be placed.
289
+ /// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
290
+ /// the lint level.
291
+ /// For the `span_lint_and_sugg` function, the node that was passed into the `LintPass::check_*`
292
+ /// function is used.
293
+ ///
294
+ /// If you're emitting the lint at the span of a different node than the one provided by the
295
+ /// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead.
296
+ /// This is needed for `#[allow]` and `#[expect]` attributes to work on the node
297
+ /// highlighted in the displayed warning.
269
298
///
270
- /// This can happen if, for example, you are in `LintPass::check_block` and you are emitting a lint
271
- /// for a particular expression within that block .
272
- /// In those cases, consider using [`span_lint_hir`], and pass the `HirId` of that expression .
299
+ /// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
300
+ /// where you would expect it to .
301
+ /// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead .
273
302
///
274
303
/// # Example
275
304
///
0 commit comments