Skip to content

add help text where missing to lints #11810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions clippy_lints/src/casts/cast_possible_wrap.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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");
};
});
}
17 changes: 11 additions & 6 deletions clippy_lints/src/module_style.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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(),),
);
}
}
Expand Down Expand Up @@ -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()),
);
}
}