diff options
| author | bors <bors@rust-lang.org> | 2023-11-15 01:23:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-15 01:23:11 +0000 |
| commit | abf01e469b9f9a49fdf96eddb3537f9ab6ae2e4a (patch) | |
| tree | 2390c4ef646bd5d669e36e15186a0892cd614110 | |
| parent | 0c42e451d643d54347aa47d7bc6c731896fe5fde (diff) | |
| parent | 11881bee6bd99852ed7777ecfa1bee241fdd4c73 (diff) | |
| download | rust-abf01e469b9f9a49fdf96eddb3537f9ab6ae2e4a.tar.gz rust-abf01e469b9f9a49fdf96eddb3537f9ab6ae2e4a.zip | |
Auto merge of #11810 - Jacherr:cast-possible-wrap-link, r=Manishearth
add help text where missing to lints Fixes https://github.com/rust-lang/rust-clippy/issues/11805 Essentially just changes the section of code that applies the lint from using `cx.struct_span_lint` and instead opts for `span_lint_and_then`, which automatically appends the help text. changelog: add missing help text for `cast_possible_wrap`, `mod_module_files`, and `self_named_module_files` lints
| -rw-r--r-- | clippy_lints/src/casts/cast_possible_wrap.rs | 13 | ||||
| -rw-r--r-- | clippy_lints/src/module_style.rs | 17 |
2 files changed, 17 insertions, 13 deletions
diff --git a/clippy_lints/src/casts/cast_possible_wrap.rs b/clippy_lints/src/casts/cast_possible_wrap.rs index ffa571abb39..2ddb0f00ecd 100644 --- a/clippy_lints/src/casts/cast_possible_wrap.rs +++ b/clippy_lints/src/casts/cast_possible_wrap.rs @@ -1,5 +1,6 @@ +use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::Expr; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::LateContext; use rustc_middle::ty::Ty; use super::{utils, CAST_POSSIBLE_WRAP}; @@ -78,13 +79,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca ), }; - cx.struct_span_lint(CAST_POSSIBLE_WRAP, expr.span, message, |diag| { + span_lint_and_then(cx, CAST_POSSIBLE_WRAP, expr.span, &message, |diag| { if let EmitState::LintOnPtrSize(16) = should_lint { diag - .note("`usize` and `isize` may be as small as 16 bits on some platforms") - .note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types") - } else { - diag - } + .note("`usize` and `isize` may be as small as 16 bits on some platforms") + .note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types"); + }; }); } diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index b49a5614329..cd45467407e 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -1,3 +1,4 @@ +use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext}; @@ -124,11 +125,13 @@ impl EarlyLintPass for ModStyle { correct.pop(); correct.push(folder); correct.push("mod.rs"); - cx.struct_span_lint( + span_lint_and_help( + cx, SELF_NAMED_MODULE_FILES, Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), - format!("`mod.rs` files are required, found `{}`", path.display()), - |lint| lint.help(format!("move `{}` to `{}`", path.display(), correct.display(),)), + &format!("`mod.rs` files are required, found `{}`", path.display()), + None, + &format!("move `{}` to `{}`", path.display(), correct.display(),), ); } } @@ -162,11 +165,13 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source mod_file.pop(); mod_file.set_extension("rs"); - cx.struct_span_lint( + span_lint_and_help( + cx, MOD_MODULE_FILES, Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), - format!("`mod.rs` files are not allowed, found `{}`", path.display()), - |lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())), + &format!("`mod.rs` files are not allowed, found `{}`", path.display()), + None, + &format!("move `{}` to `{}`", path.display(), mod_file.display()), ); } } |
