Skip to content

Update Clippy #108974

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 99 commits into from
Mar 10, 2023
Merged
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
c439373
[arithmetic_side_effects] Fix #10252
c410-f3r Feb 12, 2023
f531abc
Do not suggest using Self in const generic parameters
samueltardieu Feb 19, 2023
783b55e
Rename many interner functions.
nnethercote Feb 17, 2023
e5df17a
Use `List::empty()` instead of `mk_substs(&[])`.
nnethercote Feb 20, 2023
730fa93
chore: remove unneeded rustfmt skip
calebcartwright Feb 25, 2023
9fd0a41
Make clippy happy
compiler-errors Feb 23, 2023
49a06ed
Scope missing_docs_in_private_items to only private items
andrewbanchich Feb 12, 2023
0413fb3
Merge commit '149392b0baa4730c68f3c3eadf5c6ed7b16b85a4' into clippyup
Jarcho Feb 26, 2023
e1ac133
Auto merge of #10375 - samueltardieu:issue-10371, r=Manishearth
bors Feb 26, 2023
3d193fa
Auto merge of #10400 - calebcartwright:rustfmt-cleanup, r=Jarcho
bors Feb 26, 2023
002e934
Don't assume paths work with `fn_sig` in `multiple_unsafe_ops_pre_blo…
Jarcho Feb 26, 2023
0f3446b
Remove `from_fn` lang item
Noratrieb Feb 26, 2023
2e2e45a
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂…
matthiaskrgr Feb 26, 2023
c82ff00
Do not suggest to derive Default on generics with implicit arguments
samueltardieu Feb 25, 2023
5f3df6c
exit lint: potentualy -> potentially
cdown Feb 26, 2023
0966f59
Auto merge of #108474 - Jarcho:clippyup, r=Manishearth
bors Feb 26, 2023
ba7fd68
Auto merge of #10408 - cdown:cdown/2023-02-26/exit_lint_sp, r=Alexendoo
bors Feb 26, 2023
2a9c254
Add `collection_is_never_read`
schubart Feb 16, 2023
2742ac0
Auto merge of #10399 - samueltardieu:issue-10396, r=Manishearth
bors Feb 27, 2023
0870819
Fix lint documentation
schubart Feb 27, 2023
03a3f74
Fixing typos
deining Feb 27, 2023
8b65632
Auto merge of #10419 - deining:fix/typos, r=Jarcho
bors Feb 27, 2023
2cadea5
Fix array-size-threshold config deserialization error
Alexendoo Feb 28, 2023
69a1100
Run dogfood on all packages before failing
Jarcho Feb 27, 2023
90ba82b
Two small documentation improvements
smoelius Feb 28, 2023
acf70ea
Auto merge of #10423 - Alexendoo:array-size-threshold, r=flip1995
bors Feb 28, 2023
1a11ad7
Auto merge of #10405 - Jarcho:issue_10367, r=flip1995
bors Feb 28, 2023
d988734
Auto merge of #10418 - Jarcho:finish_dogfood, r=flip1995
bors Feb 28, 2023
ba86a99
Auto merge of #10324 - andrewbanchich:fix-missing-private-docs, r=dswij
bors Feb 28, 2023
2d9ca94
Auto merge of #10425 - smoelius:docs, r=llogiq
bors Feb 28, 2023
7fb76a1
Update version attribute for 1.68 lints
xFrednet Feb 28, 2023
917ebc3
Changelog for Rust 1.68 :dog:
xFrednet Feb 28, 2023
113c704
Auto merge of #10427 - xFrednet:changelog-1-68, r=Manishearth
bors Feb 28, 2023
5770d40
More compact `use` statements
schubart Feb 28, 2023
cb3bb8a
Add tests that show: insert() can be a read or not
schubart Feb 28, 2023
fbb7fd5
Add test for an interesting edge case
schubart Feb 28, 2023
09566cc
Use UnordSet instead of FxHashSet for names_imported_by_glob_use query.
michaelwoerister Feb 21, 2023
702a83b
Restrict `#[rustc_box]` to `Box::new` calls
clubby789 Feb 27, 2023
5cf9c34
Rollup merge of #108516 - clubby789:rustc-box-restrict, r=compiler-er…
matthiaskrgr Mar 2, 2023
79359cb
rustc_middle: Remove trait `DefIdTree`
petrochenkov Feb 22, 2023
64b54ef
Fix array-size-threshold config deserialization error
Alexendoo Feb 28, 2023
efbcb99
Use `snippet_with_context` more
Jarcho Mar 2, 2023
027f19c
Fix FP for `let_unit_value` when `await` used
giraffate Mar 3, 2023
03b9940
Downgrade let_underscore_untyped to restriction
dtolnay Mar 3, 2023
cc6180c
Include former name of renamed lints in lints.json
dtolnay Mar 4, 2023
d423703
Auto merge of #10443 - dtolnay-contrib:formerids, r=llogiq
bors Mar 4, 2023
308d680
Auto merge of #10442 - dtolnay-contrib:letunderscore, r=llogiq
bors Mar 4, 2023
446ae42
lintcheck: fix parallel processing handling
samueltardieu Mar 2, 2023
2500f96
Auto merge of #10439 - giraffate:fix_fp_for_let_unit_value, r=Jarcho
bors Mar 4, 2023
79829d8
lintcheck: use clap's derive interface
samueltardieu Mar 4, 2023
78f0f78
Auto merge of #10445 - samueltardieu:lintcheck-maintenance, r=llogiq
bors Mar 4, 2023
f95d9de
Handle ambiguous projections
smoelius Feb 25, 2023
70e85d1
Auto merge of #10403 - smoelius:fix-107877, r=Jarcho
bors Mar 5, 2023
ea2073a
Auto merge of #108351 - petrochenkov:rmdit, r=cjgillot
bors Mar 5, 2023
783bc62
Auto merge of #10438 - Jarcho:use_snip_ctxt, r=dswij
bors Mar 5, 2023
b6f0ebf
help: refer to `cargo check --help`
samueltardieu Mar 5, 2023
9035958
Auto merge of #10457 - samueltardieu:issue-10436, r=Manishearth
bors Mar 5, 2023
85ad8a6
Avoid false positives from extension traits
schubart Mar 6, 2023
a2906a1
Migrate `write.rs` to `rustc_ast::FormatArgs`
Alexendoo Feb 1, 2023
dc23e42
Add `format_args_collector` internal lint
Alexendoo Feb 2, 2023
fa0c3cc
Move test for 10148 to tests/ui/crashes
Alexendoo Mar 6, 2023
4ee6553
Add test where container is passed to a function
schubart Mar 6, 2023
5619fd5
Remove DropAndReplace terminator
zeegomo Mar 5, 2023
41fa24c
Auto merge of #10415 - schubart:collection_is_never_read, r=llogiq
bors Mar 7, 2023
5369052
Include async functions in the len_without_is_empty
mladedav Feb 16, 2023
5331d05
Auto merge of #108312 - michaelwoerister:hash-set-not-hash-stable, r=…
bors Mar 8, 2023
ce3415e
Add the `popular-crates` binary
samueltardieu Mar 7, 2023
ea2547b
Add `missing_assert_message` lint
unexge Feb 16, 2023
8f3ac65
Dogfood `missing_assert_message` on Clippy
unexge Feb 16, 2023
099d610
Apply suggestions from code review
unexge Feb 18, 2023
4eb6ccc
Update lint description and add help section
unexge Feb 18, 2023
6fac73b
Move lint to `restriction` category
unexge Feb 18, 2023
b4b2b12
Revert "Dogfood `missing_assert_message` on Clippy"
unexge Feb 18, 2023
e7065ef
Revert `tests/ui/filter_map_next_fixable.rs`
unexge Feb 18, 2023
682d52c
Update assertion macro parsing logic for Rust 1.52 changes
unexge Feb 24, 2023
87f58a1
Use late lint pass for `missing_assert_message` lint
unexge Feb 24, 2023
b554ff4
Add `Known problems` section
unexge Mar 5, 2023
216aefb
Auto merge of #10362 - unexge:missing-assert-message-lint, r=llogiq
bors Mar 8, 2023
5eefbb3
Auto merge of #10466 - samueltardieu:popular-crates, r=llogiq
bors Mar 8, 2023
d5429ea
Add new `redundant_async_block` lint
samueltardieu Mar 4, 2023
56fbfe5
Auto merge of #10448 - samueltardieu:issue-10444, r=llogiq
bors Mar 8, 2023
aff9b72
move clippy tests back to their intended directory
pietroalbini Mar 8, 2023
d9fdac5
Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiasko
matthiaskrgr Mar 8, 2023
a701af4
lintcheck: use multithreading unless --fix or --recursive is used
samueltardieu Mar 5, 2023
eceedd9
Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgr
bors Mar 9, 2023
ea4ebed
Auto merge of #10309 - c410-f3r:arith, r=giraffate
bors Mar 9, 2023
ca3bf94
Add `let_with_type_underscore` lint
blyxyas Mar 8, 2023
5f98734
Auto merge of #10467 - blyxyas:underscore_typed, r=Jarcho
bors Mar 9, 2023
a45f712
Auto merge of #10458 - samueltardieu:multithreading-lintcheck, r=llogiq
bors Mar 9, 2023
9074da0
Auto merge of #10359 - mladedav:dm/private/is-empty, r=llogiq
bors Mar 9, 2023
7ce9ca0
Mark Rust 1.68.0 as release in the changelog
xFrednet Mar 9, 2023
a7fae6e
Auto merge of #10471 - xFrednet:00000-mark-version-as-released, r=fli…
bors Mar 10, 2023
baa997c
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Mar 10, 2023
ec9029d
Bump Clippy version -> 0.1.70
flip1995 Mar 10, 2023
f3074c4
Bump nightly version -> 2023-03-10
flip1995 Mar 10, 2023
991610a
Auto merge of #10473 - flip1995:rustup, r=flip1995
bors Mar 10, 2023
3c06e0b
Auto merge of #10275 - Alexendoo:format-args-ast, r=flip1995
bors Mar 10, 2023
01ffa51
Merge commit '3c06e0b1ce003912f8fe0536d3a7fe22558e38cf' into clippyup
flip1995 Mar 10, 2023
a87abc2
Update Cargo.lock (Clippy version)
flip1995 Mar 10, 2023
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
Prev Previous commit
Next Next commit
Use late lint pass for missing_assert_message lint
Co-authored-by: Weihang Lo <[email protected]>
  • Loading branch information
unexge and weihanglo committed Mar 8, 2023
commit 87f58a1a4fb0a95973add9ff8c0c8e3439599e8a
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -927,7 +927,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
});
store.register_late_pass(|_| Box::new(no_mangle_with_rust_abi::NoMangleWithRustAbi));
store.register_late_pass(|_| Box::new(collection_is_never_read::CollectionIsNeverRead));
store.register_pre_expansion_pass(|| Box::<missing_assert_message::MissingAssertMessage>::default());
store.register_late_pass(|_| Box::new(missing_assert_message::MissingAssertMessage));
// add lints here, do not remove this comment, it's used in `new_lint`
}

106 changes: 26 additions & 80 deletions clippy_lints/src/missing_assert_message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use clippy_utils::diagnostics::span_lint_and_help;
use rustc_ast::ast;
use rustc_ast::{
token::{Token, TokenKind},
tokenstream::TokenTree,
};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use clippy_utils::macros::{find_assert_args, find_assert_eq_args, root_macro_call_first_node, PanicExpn};
use clippy_utils::{is_in_cfg_test, is_in_test_function};
use rustc_hir::Expr;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;

declare_clippy_lint! {
@@ -37,93 +35,41 @@ declare_clippy_lint! {
"checks assertions without a custom panic message"
}

#[derive(Default, Clone, Debug)]
pub struct MissingAssertMessage {
// This field will be greater than zero if we are inside a `#[test]` or `#[cfg(test)]`
test_deepnes: usize,
}
declare_lint_pass!(MissingAssertMessage => [MISSING_ASSERT_MESSAGE]);

impl_lint_pass!(MissingAssertMessage => [MISSING_ASSERT_MESSAGE]);
impl<'tcx> LateLintPass<'tcx> for MissingAssertMessage {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return };
let single_argument = match cx.tcx.get_diagnostic_name(macro_call.def_id) {
Some(sym::assert_macro | sym::debug_assert_macro) => true,
Some(
sym::assert_eq_macro | sym::assert_ne_macro | sym::debug_assert_eq_macro | sym::debug_assert_ne_macro,
) => false,
_ => return,
};

impl EarlyLintPass for MissingAssertMessage {
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac_call: &ast::MacCall) {
if self.test_deepnes != 0 {
// This lint would be very noisy in tests, so just ignore if we're in test context
if is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id) {
return;
}

let Some(last_segment) = mac_call.path.segments.last() else { return; };
let num_separators_needed = match last_segment.ident.as_str() {
"assert" | "debug_assert" => 1,
"assert_eq" | "assert_ne" | "debug_assert_eq" | "debug_assert_ne" => 2,
_ => return,
let panic_expn = if single_argument {
let Some((_, panic_expn)) = find_assert_args(cx, expr, macro_call.expn) else { return };
panic_expn
} else {
let Some((_, _, panic_expn)) = find_assert_eq_args(cx, expr, macro_call.expn) else { return };
panic_expn
};
let num_separators = num_commas_on_arguments(mac_call);

if num_separators < num_separators_needed {
if let PanicExpn::Empty = panic_expn {
span_lint_and_help(
cx,
MISSING_ASSERT_MESSAGE,
mac_call.span(),
macro_call.span,
"assert without any message",
None,
"consider describing why the failing assert is problematic",
);
}
}

fn check_item(&mut self, _: &EarlyContext<'_>, item: &ast::Item) {
if item.attrs.iter().any(is_a_test_attribute) {
self.test_deepnes += 1;
}
}

fn check_item_post(&mut self, _: &EarlyContext<'_>, item: &ast::Item) {
if item.attrs.iter().any(is_a_test_attribute) {
self.test_deepnes -= 1;
}
}
}

// Returns number of commas (excluding trailing comma) from `MacCall`'s arguments.
fn num_commas_on_arguments(mac_call: &ast::MacCall) -> usize {
let mut num_separators = 0;
let mut is_trailing = false;
for tt in mac_call.args.tokens.trees() {
match tt {
TokenTree::Token(
Token {
kind: TokenKind::Comma,
span: _,
},
_,
) => {
num_separators += 1;
is_trailing = true;
},
_ => {
is_trailing = false;
},
}
}
if is_trailing {
num_separators -= 1;
}
num_separators
}

// Returns true if the attribute is either a `#[test]` or a `#[cfg(test)]`.
fn is_a_test_attribute(attr: &ast::Attribute) -> bool {
if attr.has_name(sym::test) {
return true;
}

if attr.has_name(sym::cfg)
&& let Some(items) = attr.meta_item_list()
&& let [item] = &*items
&& item.has_name(sym::test)
{
true
} else {
false
}
}