Skip to content

Commit abf01e4

Browse files
committed
Auto merge of rust-lang#11810 - Jacherr:cast-possible-wrap-link, r=Manishearth
add help text where missing to lints Fixes rust-lang/rust-clippy#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
2 parents 0c42e45 + 11881be commit abf01e4

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

clippy_lints/src/casts/cast_possible_wrap.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use clippy_utils::diagnostics::span_lint_and_then;
12
use rustc_hir::Expr;
2-
use rustc_lint::{LateContext, LintContext};
3+
use rustc_lint::LateContext;
34
use rustc_middle::ty::Ty;
45

56
use super::{utils, CAST_POSSIBLE_WRAP};
@@ -78,13 +79,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca
7879
),
7980
};
8081

81-
cx.struct_span_lint(CAST_POSSIBLE_WRAP, expr.span, message, |diag| {
82+
span_lint_and_then(cx, CAST_POSSIBLE_WRAP, expr.span, &message, |diag| {
8283
if let EmitState::LintOnPtrSize(16) = should_lint {
8384
diag
84-
.note("`usize` and `isize` may be as small as 16 bits on some platforms")
85-
.note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types")
86-
} else {
87-
diag
88-
}
85+
.note("`usize` and `isize` may be as small as 16 bits on some platforms")
86+
.note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types");
87+
};
8988
});
9089
}

clippy_lints/src/module_style.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clippy_utils::diagnostics::span_lint_and_help;
12
use rustc_ast::ast;
23
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
34
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
@@ -124,11 +125,13 @@ impl EarlyLintPass for ModStyle {
124125
correct.pop();
125126
correct.push(folder);
126127
correct.push("mod.rs");
127-
cx.struct_span_lint(
128+
span_lint_and_help(
129+
cx,
128130
SELF_NAMED_MODULE_FILES,
129131
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
130-
format!("`mod.rs` files are required, found `{}`", path.display()),
131-
|lint| lint.help(format!("move `{}` to `{}`", path.display(), correct.display(),)),
132+
&format!("`mod.rs` files are required, found `{}`", path.display()),
133+
None,
134+
&format!("move `{}` to `{}`", path.display(), correct.display(),),
132135
);
133136
}
134137
}
@@ -162,11 +165,13 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source
162165
mod_file.pop();
163166
mod_file.set_extension("rs");
164167

165-
cx.struct_span_lint(
168+
span_lint_and_help(
169+
cx,
166170
MOD_MODULE_FILES,
167171
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
168-
format!("`mod.rs` files are not allowed, found `{}`", path.display()),
169-
|lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())),
172+
&format!("`mod.rs` files are not allowed, found `{}`", path.display()),
173+
None,
174+
&format!("move `{}` to `{}`", path.display(), mod_file.display()),
170175
);
171176
}
172177
}

0 commit comments

Comments
 (0)