Skip to content

Commit af3346a

Browse files
committed
Check for get method and new test case in unfixable
1 parent d43acb8 commit af3346a

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

clippy_lints/src/non_zero_suggestions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn check_non_zero_conversion(cx: &LateContext<'_>, expr: &Expr<'_>, applicabilit
7272
&& let ExprKind::Path(qpath) = &func.kind
7373
&& let Some(def_id) = cx.qpath_res(qpath, func.hir_id).opt_def_id()
7474
&& let ExprKind::MethodCall(rcv_path, receiver, _, _) = &arg.kind
75+
&& rcv_path.ident.name.as_str() == "get"
7576
{
7677
let fn_name = cx.tcx.item_name(def_id);
7778
let target_ty = cx.typeck_results().expr_ty(expr);

tests/ui/non_zero_suggestions_unfixable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ fn main() {
1010
let y = u64::from(n.get());
1111
//~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion
1212
some_fn_that_only_takes_u64(y);
13+
14+
let m = NonZeroU32::try_from(1).unwrap();
15+
let _z: NonZeroU64 = m.into();
1316
}
1417

1518
fn return_non_zero(x: u64, y: NonZeroU32) -> u64 {

tests/ui/non_zero_suggestions_unfixable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | let y = u64::from(n.get());
1414
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(n)`
1515

1616
error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion
17-
--> tests/ui/non_zero_suggestions_unfixable.rs:16:5
17+
--> tests/ui/non_zero_suggestions_unfixable.rs:19:5
1818
|
1919
LL | u64::from(y.get())
2020
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)`

0 commit comments

Comments
 (0)