Dogfood missing_assert_message
on Clippy
Co-authored-by: Weihang Lo <me@weihanglo.tw>
This commit is contained in:
parent
ea2547b8c6
commit
8f3ac65227
@ -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))));
|
||||
|
@ -90,7 +90,11 @@ fn check_crate_post(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
@ -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)]
|
||||
|
@ -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::<missing_assert_message::MissingAssertMessage>::default());
|
||||
// add lints here, do not remove this comment, it's used in `new_lint`
|
||||
}
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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 @@ pub fn push_attrs(&mut self, sess: &Session, attrs: &[ast::Attribute], name: &'s
|
||||
}
|
||||
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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1011,10 +1011,13 @@ fn pat_capture_kind(cx: &LateContext<'_>, pat: &Pat<'_>) -> CaptureKind {
|
||||
capture
|
||||
}
|
||||
|
||||
debug_assert!(matches!(
|
||||
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;
|
||||
|
@ -179,7 +179,7 @@ pub fn format(&self) -> String {
|
||||
}
|
||||
|
||||
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 @@ pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial
|
||||
}
|
||||
|
||||
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<usize> {
|
||||
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()),
|
||||
|
@ -225,8 +225,7 @@ pub fn implements_trait_with_env<'tcx>(
|
||||
trait_id: DefId,
|
||||
ty_params: impl IntoIterator<Item = Option<GenericArg<'tcx>>>,
|
||||
) -> 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() {
|
||||
|
@ -383,7 +383,7 @@ fn run_clippy_lints(
|
||||
.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<String, usize>, 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));
|
||||
|
@ -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);
|
||||
|
@ -21,6 +21,7 @@
|
||||
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}");
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
pub static CARGO_CLIPPY_PATH: LazyLock<PathBuf> = 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
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user