diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 384aca7fe..b1c2a51da 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -467,7 +467,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: let mut contains_initial_stars = false; for line in doc.lines() { let offset = line.as_ptr() as usize - doc.as_ptr() as usize; - debug_assert_eq!(offset as u32 as usize, offset); + debug_assert_eq!(offset as u32 as usize, offset, "`offset` shouldn't overflow `u32`"); contains_initial_stars |= line.trim_start().starts_with('*'); // +1 adds the newline, +3 skips the opening delimiter sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); diff --git a/clippy_lints/src/duplicate_mod.rs b/clippy_lints/src/duplicate_mod.rs index 7ff7068f0..9135af409 100644 --- a/clippy_lints/src/duplicate_mod.rs +++ b/clippy_lints/src/duplicate_mod.rs @@ -90,7 +90,11 @@ impl EarlyLintPass for DuplicateMod { } // At this point the lint would be emitted - assert_eq!(spans.len(), lint_levels.len()); + assert_eq!( + spans.len(), + lint_levels.len(), + "`spans` and `lint_levels` should have equal lengths" + ); let spans: Vec<_> = spans .iter() .zip(lint_levels) diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 4c69dacf3..68fb88bcf 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -242,7 +242,7 @@ fn to_camel_case(item_name: &str) -> String { impl LateLintPass<'_> for EnumVariantNames { fn check_item_post(&mut self, _cx: &LateContext<'_>, _item: &Item<'_>) { let last = self.modules.pop(); - assert!(last.is_some()); + assert!(last.is_some(), "`modules` should not be empty"); } #[expect(clippy::similar_names)] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index fe0229a81..e3be798f3 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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::new(missing_assert_message::MissingAssertMessage)); + store.register_pre_expansion_pass(|| Box::::default()); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 9f6917c14..e24f3aa56 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -408,7 +408,10 @@ fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attri /// Precondition: `a_name.chars().count() < b_name.chars().count()`. #[must_use] fn levenstein_not_1(a_name: &str, b_name: &str) -> bool { - debug_assert!(a_name.chars().count() < b_name.chars().count()); + debug_assert!( + a_name.chars().count() < b_name.chars().count(), + "Precondition: `a_name.chars().count() < b_name.chars().count()` does not meet" + ); let mut a_chars = a_name.chars(); let mut b_chars = b_name.chars(); while let (Some(a), Some(b)) = (a_chars.next(), b_chars.next()) { diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 7987a233b..75f7b5cf9 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -31,7 +31,7 @@ pub struct LimitStack { impl Drop for LimitStack { fn drop(&mut self) { - assert_eq!(self.stack.len(), 1); + assert_eq!(self.stack.len(), 1, "stack should only have one element"); } } @@ -49,7 +49,9 @@ impl LimitStack { } pub fn pop_attrs(&mut self, sess: &Session, attrs: &[ast::Attribute], name: &'static str) { let stack = &mut self.stack; - parse_attrs(sess, attrs, name, |val| assert_eq!(stack.pop(), Some(val))); + parse_attrs(sess, attrs, name, |val| { + assert_eq!(stack.pop(), Some(val), "incorrect last element"); + }); } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 213e5b335..1c453b87f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1011,10 +1011,13 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { capture } - debug_assert!(matches!( - e.kind, - ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. })) - )); + debug_assert!( + matches!( + e.kind, + ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. })) + ), + "`e.kind` should be a resolved local path" + ); let mut child_id = e.hir_id; let mut capture = CaptureKind::Value; diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index c225398ad..7d8f31e1d 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -179,7 +179,7 @@ impl<'a> NumericLiteral<'a> { } pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial_group_first: bool, pad: bool) { - debug_assert!(group_size > 0); + debug_assert!(group_size > 0, "group size should be greater than zero"); let mut digits = input.chars().filter(|&c| c != '_'); @@ -219,7 +219,7 @@ impl<'a> NumericLiteral<'a> { } fn split_suffix<'a>(src: &'a str, lit_kind: &LitKind) -> (&'a str, Option<&'a str>) { - debug_assert!(lit_kind.is_numeric()); + debug_assert!(lit_kind.is_numeric(), "`lit_kind` should be numeric"); lit_suffix_length(lit_kind) .and_then(|suffix_length| src.len().checked_sub(suffix_length)) .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 } fn lit_suffix_length(lit_kind: &LitKind) -> Option { - debug_assert!(lit_kind.is_numeric()); + debug_assert!(lit_kind.is_numeric(), "`lit_kind` should be numeric"); let suffix = match lit_kind { LitKind::Int(_, int_lit_kind) => match int_lit_kind { LitIntType::Signed(int_ty) => Some(int_ty.name_str()), diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 7cbb77ea2..2b3c78147 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -225,8 +225,7 @@ pub fn implements_trait_with_env<'tcx>( trait_id: DefId, ty_params: impl IntoIterator>>, ) -> bool { - // Clippy shouldn't have infer types - assert!(!ty.needs_infer()); + assert!(!ty.needs_infer(), "Clippy shouldn't have infer types"); let ty = tcx.erase_regions(ty); if ty.has_escaping_bound_vars() { diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index 23c852980..6e39c8d42 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -383,7 +383,7 @@ impl Crate { .status() .expect("failed to run cargo"); - assert_eq!(status.code(), Some(0)); + assert_eq!(status.code(), Some(0), "`cargo check` exited with non-zero code"); return Vec::new(); } @@ -741,6 +741,7 @@ fn print_stats(old_stats: HashMap, new_stats: HashMap<&String, us let mut new_stats_deduped = new_stats; // remove duplicates from both hashmaps + #[allow(clippy::missing_assert_message)] for (k, v) in &same_in_both_hashmaps { assert!(old_stats_deduped.remove(k) == Some(*v)); assert!(new_stats_deduped.remove(k) == Some(*v)); diff --git a/tests/compile-test.rs b/tests/compile-test.rs index c10ee969c..2f2d305f5 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -410,7 +410,10 @@ fn check_rustfix_coverage() { }; if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) { - assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new)); + assert!( + RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new), + "`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` should be sorted" + ); for rs_file in missing_coverage_contents.lines() { let rs_path = Path::new(rs_file); diff --git a/tests/integration.rs b/tests/integration.rs index a771d8b87..2d2d6e673 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -21,6 +21,7 @@ const CARGO_CLIPPY: &str = "cargo-clippy"; const CARGO_CLIPPY: &str = "cargo-clippy.exe"; #[cfg_attr(feature = "integration", test)] +#[allow(clippy::missing_assert_message)] fn integration_test() { let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set"); let repo_url = format!("https://github.com/{repo_name}"); diff --git a/tests/test_utils/mod.rs b/tests/test_utils/mod.rs index ea8c54e08..3081bf2d8 100644 --- a/tests/test_utils/mod.rs +++ b/tests/test_utils/mod.rs @@ -5,7 +5,7 @@ use std::sync::LazyLock; pub static CARGO_CLIPPY_PATH: LazyLock = LazyLock::new(|| { let mut path = std::env::current_exe().unwrap(); - assert!(path.pop()); // deps + assert!(path.pop(), "current running executable path shouldn't be empty"); // deps path.set_file_name("cargo-clippy"); path });