Skip to content

Commit 8f3ac65

Browse files
unexgeweihanglo
andcommitted
Dogfood missing_assert_message on Clippy
Co-authored-by: Weihang Lo <me@weihanglo.tw>
1 parent ea2547b commit 8f3ac65

File tree

13 files changed

+35
-19
lines changed

13 files changed

+35
-19
lines changed

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
467467
let mut contains_initial_stars = false;
468468
for line in doc.lines() {
469469
let offset = line.as_ptr() as usize - doc.as_ptr() as usize;
470-
debug_assert_eq!(offset as u32 as usize, offset);
470+
debug_assert_eq!(offset as u32 as usize, offset, "`offset` shouldn't overflow `u32`");
471471
contains_initial_stars |= line.trim_start().starts_with('*');
472472
// +1 adds the newline, +3 skips the opening delimiter
473473
sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32))));

clippy_lints/src/duplicate_mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ impl EarlyLintPass for DuplicateMod {
9090
}
9191

9292
// At this point the lint would be emitted
93-
assert_eq!(spans.len(), lint_levels.len());
93+
assert_eq!(
94+
spans.len(),
95+
lint_levels.len(),
96+
"`spans` and `lint_levels` should have equal lengths"
97+
);
9498
let spans: Vec<_> = spans
9599
.iter()
96100
.zip(lint_levels)

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn to_camel_case(item_name: &str) -> String {
242242
impl LateLintPass<'_> for EnumVariantNames {
243243
fn check_item_post(&mut self, _cx: &LateContext<'_>, _item: &Item<'_>) {
244244
let last = self.modules.pop();
245-
assert!(last.is_some());
245+
assert!(last.is_some(), "`modules` should not be empty");
246246
}
247247

248248
#[expect(clippy::similar_names)]

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
927927
});
928928
store.register_late_pass(|_| Box::new(no_mangle_with_rust_abi::NoMangleWithRustAbi));
929929
store.register_late_pass(|_| Box::new(collection_is_never_read::CollectionIsNeverRead));
930-
store.register_pre_expansion_pass(|| Box::new(missing_assert_message::MissingAssertMessage));
930+
store.register_pre_expansion_pass(|| Box::<missing_assert_message::MissingAssertMessage>::default());
931931
// add lints here, do not remove this comment, it's used in `new_lint`
932932
}
933933

clippy_lints/src/non_expressive_names.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attri
408408
/// Precondition: `a_name.chars().count() < b_name.chars().count()`.
409409
#[must_use]
410410
fn levenstein_not_1(a_name: &str, b_name: &str) -> bool {
411-
debug_assert!(a_name.chars().count() < b_name.chars().count());
411+
debug_assert!(
412+
a_name.chars().count() < b_name.chars().count(),
413+
"Precondition: `a_name.chars().count() < b_name.chars().count()` does not meet"
414+
);
412415
let mut a_chars = a_name.chars();
413416
let mut b_chars = b_name.chars();
414417
while let (Some(a), Some(b)) = (a_chars.next(), b_chars.next()) {

clippy_utils/src/attrs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct LimitStack {
3131

3232
impl Drop for LimitStack {
3333
fn drop(&mut self) {
34-
assert_eq!(self.stack.len(), 1);
34+
assert_eq!(self.stack.len(), 1, "stack should only have one element");
3535
}
3636
}
3737

@@ -49,7 +49,9 @@ impl LimitStack {
4949
}
5050
pub fn pop_attrs(&mut self, sess: &Session, attrs: &[ast::Attribute], name: &'static str) {
5151
let stack = &mut self.stack;
52-
parse_attrs(sess, attrs, name, |val| assert_eq!(stack.pop(), Some(val)));
52+
parse_attrs(sess, attrs, name, |val| {
53+
assert_eq!(stack.pop(), Some(val), "incorrect last element");
54+
});
5355
}
5456
}
5557

clippy_utils/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,13 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
10111011
capture
10121012
}
10131013

1014-
debug_assert!(matches!(
1015-
e.kind,
1016-
ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. }))
1017-
));
1014+
debug_assert!(
1015+
matches!(
1016+
e.kind,
1017+
ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. }))
1018+
),
1019+
"`e.kind` should be a resolved local path"
1020+
);
10181021

10191022
let mut child_id = e.hir_id;
10201023
let mut capture = CaptureKind::Value;

clippy_utils/src/numeric_literal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'a> NumericLiteral<'a> {
179179
}
180180

181181
pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial_group_first: bool, pad: bool) {
182-
debug_assert!(group_size > 0);
182+
debug_assert!(group_size > 0, "group size should be greater than zero");
183183

184184
let mut digits = input.chars().filter(|&c| c != '_');
185185

@@ -219,7 +219,7 @@ impl<'a> NumericLiteral<'a> {
219219
}
220220

221221
fn split_suffix<'a>(src: &'a str, lit_kind: &LitKind) -> (&'a str, Option<&'a str>) {
222-
debug_assert!(lit_kind.is_numeric());
222+
debug_assert!(lit_kind.is_numeric(), "`lit_kind` should be numeric");
223223
lit_suffix_length(lit_kind)
224224
.and_then(|suffix_length| src.len().checked_sub(suffix_length))
225225
.map_or((src, None), |split_pos| {
@@ -229,7 +229,7 @@ fn split_suffix<'a>(src: &'a str, lit_kind: &LitKind) -> (&'a str, Option<&'a st
229229
}
230230

231231
fn lit_suffix_length(lit_kind: &LitKind) -> Option<usize> {
232-
debug_assert!(lit_kind.is_numeric());
232+
debug_assert!(lit_kind.is_numeric(), "`lit_kind` should be numeric");
233233
let suffix = match lit_kind {
234234
LitKind::Int(_, int_lit_kind) => match int_lit_kind {
235235
LitIntType::Signed(int_ty) => Some(int_ty.name_str()),

clippy_utils/src/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ pub fn implements_trait_with_env<'tcx>(
225225
trait_id: DefId,
226226
ty_params: impl IntoIterator<Item = Option<GenericArg<'tcx>>>,
227227
) -> bool {
228-
// Clippy shouldn't have infer types
229-
assert!(!ty.needs_infer());
228+
assert!(!ty.needs_infer(), "Clippy shouldn't have infer types");
230229

231230
let ty = tcx.erase_regions(ty);
232231
if ty.has_escaping_bound_vars() {

lintcheck/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl Crate {
383383
.status()
384384
.expect("failed to run cargo");
385385

386-
assert_eq!(status.code(), Some(0));
386+
assert_eq!(status.code(), Some(0), "`cargo check` exited with non-zero code");
387387

388388
return Vec::new();
389389
}
@@ -741,6 +741,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
741741
let mut new_stats_deduped = new_stats;
742742

743743
// remove duplicates from both hashmaps
744+
#[allow(clippy::missing_assert_message)]
744745
for (k, v) in &same_in_both_hashmaps {
745746
assert!(old_stats_deduped.remove(k) == Some(*v));
746747
assert!(new_stats_deduped.remove(k) == Some(*v));

0 commit comments

Comments
 (0)