diff options
| author | KonaeAkira <longtruong2411@gmail.com> | 2025-03-15 00:05:32 +0100 |
|---|---|---|
| committer | KonaeAkira <longtruong2411@gmail.com> | 2025-03-15 00:05:32 +0100 |
| commit | 4a324c9dffa87a802a3e976976020ed605eeb1bc (patch) | |
| tree | 7f0bf01ad7c0f22682aedb689b2e2fd355f352f0 | |
| parent | da910b14e2af9d790c18c5861a8669b30a90939d (diff) | |
| download | rust-4a324c9dffa87a802a3e976976020ed605eeb1bc.tar.gz rust-4a324c9dffa87a802a3e976976020ed605eeb1bc.zip | |
Fix from_over_into lint suggesting invalid code
| -rw-r--r-- | clippy_lints/src/from_over_into.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 6da5567d9c7..58a3f9288c0 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -176,8 +176,8 @@ fn convert_to_from( return None; }; let body = cx.tcx.hir_body(body_id); - let [input] = body.params else { return None }; - let PatKind::Binding(.., self_ident, None) = input.pat.kind else { + let [self_param] = body.params else { return None }; + let PatKind::Binding(.., self_ident, None) = self_param.pat.kind else { return None; }; @@ -197,11 +197,21 @@ fn convert_to_from( // fn into(self) -> T -> fn from(self) -> T // ~~~~ ~~~~ (impl_item.ident.span, String::from("from")), - // fn into([mut] self) -> T -> fn into([mut] v: T) -> T - // ~~~~ ~~~~ - (self_ident.span, format!("val: {from}")), ]; + if self_ident.span.overlaps(self_param.ty_span) { + // fn into([mut] self) -> T -> fn into([mut] val: T) -> T + // ~~~~ ~~~~~~ + suggestions.push((self_ident.span, format!("val: {from}"))); + } else { + // fn into([mut] self: U) -> T -> fn into([mut] val: U) -> T + // ~~~~ ~~~ + suggestions.push((self_ident.span, String::from("val"))); + // fn into([mut] val: U) -> T -> fn into([mut] val: T) -> T + // ~ ~ + suggestions.push((self_param.ty_span, from.to_owned())); + } + if let FnRetTy::Return(_) = sig.decl.output { // fn into(self) -> T -> fn into(self) -> Self // ~ ~~~~ |
