Skip to content

Commit b11d7bf

Browse files
committed
fix-issue-14665
1 parent aeb6ac9 commit b11d7bf

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

clippy_lints/src/manual_div_ceil.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn build_suggestion(
199199
} else {
200200
format!("{dividend_sugg_str}{type_suffix}")
201201
};
202-
let divisor_snippet = snippet_with_applicability(cx, rhs.span.source_callsite(), "..", applicability);
202+
let divisor_snippet = snippet_with_applicability(cx, rhs.span, "..", applicability);
203203

204204
let sugg = format!("{suggestion_before_div_ceil}.div_ceil({divisor_snippet})");
205205

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
macro_rules! y {
2+
() => {
3+
let x = 33u32;
4+
let _ = x.div_ceil(8);
5+
//~^ manual_div_ceil
6+
let _ = x.div_ceil(8);
7+
//~^ manual_div_ceil
8+
};
9+
}
10+
11+
fn main() {
12+
y!();
13+
}

tests/ui/manual_div_ceil_in_macro.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
macro_rules! y {
2+
() => {
3+
let x = 33u32;
4+
let _ = (x + 7) / 8;
5+
//~^ manual_div_ceil
6+
let _ = (7 + x) / 8;
7+
//~^ manual_div_ceil
8+
};
9+
}
10+
11+
fn main() {
12+
y!();
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: manually reimplementing `div_ceil`
2+
--> tests/ui/manual_div_ceil_in_macro.rs:4:17
3+
|
4+
LL | let _ = (x + 7) / 8;
5+
| ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)`
6+
...
7+
LL | y!();
8+
| ---- in this macro invocation
9+
|
10+
= note: `-D clippy::manual-div-ceil` implied by `-D warnings`
11+
= help: to override `-D warnings` add `#[allow(clippy::manual_div_ceil)]`
12+
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
error: manually reimplementing `div_ceil`
15+
--> tests/ui/manual_div_ceil_in_macro.rs:6:17
16+
|
17+
LL | let _ = (7 + x) / 8;
18+
| ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)`
19+
...
20+
LL | y!();
21+
| ---- in this macro invocation
22+
|
23+
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
24+
25+
error: aborting due to 2 previous errors
26+

0 commit comments

Comments
 (0)