Check for get method and new test case in unfixable

This commit is contained in:
Samarth1696 2024-08-31 11:53:16 +05:30
parent d43acb803f
commit af3346a85f
3 changed files with 5 additions and 1 deletions

View file

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

View file

@ -10,6 +10,9 @@ fn main() {
let y = u64::from(n.get());
//~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion
some_fn_that_only_takes_u64(y);
let m = NonZeroU32::try_from(1).unwrap();
let _z: NonZeroU64 = m.into();
}
fn return_non_zero(x: u64, y: NonZeroU32) -> u64 {

View file

@ -14,7 +14,7 @@ LL | let y = u64::from(n.get());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(n)`
error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion
--> tests/ui/non_zero_suggestions_unfixable.rs:16:5
--> tests/ui/non_zero_suggestions_unfixable.rs:19:5
|
LL | u64::from(y.get())
| ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)`