Skip to content

Commit 2a8d79e

Browse files
committed
Add ExprKind::Block to type certainty algorithm
1 parent 1727363 commit 2a8d79e

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Diff for: clippy_utils/src/ty/type_certainty/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ fn expr_type_certainty(cx: &LateContext<'_>, expr: &Expr<'_>, in_arg: bool) -> C
110110

111111
ExprKind::Struct(qpath, _, _) => qpath_certainty(cx, qpath, true),
112112

113+
ExprKind::Block(block, _) => block
114+
.expr
115+
.map_or(Certainty::Certain(None), |expr| expr_type_certainty(cx, expr, false)),
116+
113117
_ => Certainty::Uncertain,
114118
};
115119

Diff for: tests/ui/unnecessary_cast.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,10 @@ mod fixable {
290290
f((1 + 2u32));
291291
//~^ unnecessary_cast
292292
}
293+
294+
fn with_blocks(a: i64, b: i64, c: u64) {
295+
let threshold = if c < 10 { a } else { b };
296+
let _ = threshold;
297+
//~^ unnecessary_cast
298+
}
293299
}

Diff for: tests/ui/unnecessary_cast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,10 @@ mod fixable {
290290
f((1 + 2u32) as u32);
291291
//~^ unnecessary_cast
292292
}
293+
294+
fn with_blocks(a: i64, b: i64, c: u64) {
295+
let threshold = if c < 10 { a } else { b };
296+
let _ = threshold as i64;
297+
//~^ unnecessary_cast
298+
}
293299
}

Diff for: tests/ui/unnecessary_cast.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,11 @@ error: casting to the same type is unnecessary (`u32` -> `u32`)
259259
LL | f((1 + 2u32) as u32);
260260
| ^^^^^^^^^^^^^^^^^ help: try: `(1 + 2u32)`
261261

262-
error: aborting due to 43 previous errors
262+
error: casting to the same type is unnecessary (`i64` -> `i64`)
263+
--> tests/ui/unnecessary_cast.rs:296:17
264+
|
265+
LL | let _ = threshold as i64;
266+
| ^^^^^^^^^^^^^^^^ help: try: `threshold`
267+
268+
error: aborting due to 44 previous errors
263269

0 commit comments

Comments
 (0)