Skip to content

Commit 5b1f95c

Browse files
committed
apply review suggestions
1 parent eb5ce85 commit 5b1f95c

File tree

1 file changed

+68
-39
lines changed

1 file changed

+68
-39
lines changed

clippy_utils/src/diagnostics.rs

+68-39
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) {
3636
/// Usually it's nicer to provide more context for lint messages.
3737
/// Be sure the output is understandable when you use this method.
3838
///
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.
4343
///
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.
4752
///
4853
/// # Example
4954
///
@@ -70,14 +75,19 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
7075
///
7176
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
7277
///
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.
7787
///
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.
8191
///
8292
/// # Example
8393
///
@@ -117,14 +127,19 @@ pub fn span_lint_and_help<T: LintContext>(
117127
///
118128
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
119129
///
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.
124134
///
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.
128143
///
129144
/// # Example
130145
///
@@ -167,14 +182,19 @@ pub fn span_lint_and_note<T: LintContext>(
167182
/// If you need to customize your lint output a lot, use this function.
168183
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
169184
///
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.
174194
///
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.
178198
pub fn span_lint_and_then<C, S, F>(cx: &C, lint: &'static Lint, sp: S, msg: &str, f: F)
179199
where
180200
C: LintContext,
@@ -188,8 +208,10 @@ where
188208
});
189209
}
190210

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.
193215
///
194216
/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined
195217
/// via the `#[expect]` attribute.
@@ -217,8 +239,10 @@ pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, s
217239
});
218240
}
219241

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.
222246
///
223247
/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined
224248
/// via the `#[expect]` attribute.
@@ -262,14 +286,19 @@ pub fn span_lint_hir_and_then(
262286
///
263287
/// If you change the signature, remember to update the internal lint `CollapsibleCalls`
264288
///
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.
269298
///
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.
273302
///
274303
/// # Example
275304
///

0 commit comments

Comments
 (0)