Skip to content

Commit

Permalink
Add macro test
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Aug 28, 2024
1 parent cb897d0 commit 390f038
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
store.register_early_pass(|| Box::new(byte_char_slices::ByteCharSlice));
store.register_early_pass(|| Box::new(cfg_not_test::CfgNotTest));
store.register_late_pass(|_| Box::new(zombie_processes::ZombieProcesses));
store.register_late_pass(move |_| Box::new(manual_div_ceil::ManualDivCeil::new(msrv())));
store.register_late_pass(move |_| Box::new(manual_div_ceil::ManualDivCeil::new(conf)));
// add lints here, do not remove this comment, it's used in `new_lint`
}
8 changes: 6 additions & 2 deletions clippy_lints/src/manual_div_ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use rustc_middle::ty::{self};
use rustc_session::impl_lint_pass;
use rustc_span::symbol::Symbol;

use clippy_config::Conf;

declare_clippy_lint! {
/// ### What it does
/// Checks for an expression like `(x + (y - 1)) / y` which is a common manual reimplementation
Expand Down Expand Up @@ -45,8 +47,10 @@ pub struct ManualDivCeil {

impl ManualDivCeil {
#[must_use]
pub fn new(msrv: Msrv) -> Self {
Self { msrv }
pub fn new(conf: &'static Conf) -> Self {
Self {
msrv: conf.msrv.clone(),
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ui/manual_div_ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ fn main() {
let _ = (z as i32 + (y_i - 1)) / y_i;
let _ = (7_u32 as i32 + (y_i - 1)) / y_i;
let _ = (7_u32 as i32 + (4 - 1)) / 4;

macro_rules! fill_via_chunks {
($size: expr, $b: expr) => {{
let size = $size;
let chunk_size = ($b + size - 1) / size;
}};
}

fill_via_chunks!(45, 45);
}

0 comments on commit 390f038

Please sign in to comment.