From b2c85b31bbe9dfd841c5d4999ac79cd431489101 Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Thu, 1 Jun 2023 16:02:42 +0200 Subject: [PATCH] Move bail into lint to prevent no-linting, move to unfixable --- clippy_lints/src/from_over_into.rs | 10 +++++----- tests/ui/from_over_into.fixed | 10 ---------- tests/ui/from_over_into.rs | 10 ---------- tests/ui/from_over_into_unfixable.rs | 10 ++++++++++ tests/ui/from_over_into_unfixable.stderr | 10 +++++++++- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index c4405feaa..e25b45eaa 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -80,11 +80,6 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { - if !target_ty.find_self_aliases().is_empty() { - // It's tricky to expand self-aliases correctly, we'll ignore it to not cause a - // bad suggestion/fix. - return; - } span_lint_and_then( cx, FROM_OVER_INTO, @@ -161,6 +156,11 @@ fn convert_to_from( self_ty: &Ty<'_>, impl_item_ref: &ImplItemRef, ) -> Option> { + if !target_ty.find_self_aliases().is_empty() { + // It's tricky to expand self-aliases correctly, we'll ignore it to not cause a + // bad suggestion/fix. + return None; + } let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else { return None }; let body = cx.tcx.hir().body(body_id); diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index 98310ac5c..d18f93875 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -88,14 +88,4 @@ impl Into for IntoOpaque { fn into(self) -> Opaque {} } -pub struct Lval(T); - -pub struct Rval(T); - -impl Into> for Lval { - fn into(self) -> Rval { - Rval(self) - } -} - fn main() {} diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index 4fb91971d..de8ff0b06 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -88,14 +88,4 @@ impl Into for IntoOpaque { fn into(self) -> Opaque {} } -pub struct Lval(T); - -pub struct Rval(T); - -impl Into> for Lval { - fn into(self) -> Rval { - Rval(self) - } -} - fn main() {} diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index 3b280b748..92d3504bc 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -32,4 +32,14 @@ impl Into for ContainsVal { } } +pub struct Lval(T); + +pub struct Rval(T); + +impl Into> for Lval { + fn into(self) -> Rval { + Rval(self) + } +} + fn main() {} diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index 251f1d84e..2ab9b9d6b 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -25,5 +25,13 @@ LL | impl Into for ContainsVal { https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence = help: replace the `Into` implementation with `From` -error: aborting due to 3 previous errors +error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true + --> $DIR/from_over_into_unfixable.rs:39:1 + | +LL | impl Into> for Lval { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: replace the `Into` implementation with `From>` + +error: aborting due to 4 previous errors