about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarcusGrass <marcus.grass@protonmail.com>2023-06-01 16:02:42 +0200
committerMarcusGrass <marcus.grass@protonmail.com>2023-06-01 16:02:42 +0200
commitb2c85b31bbe9dfd841c5d4999ac79cd431489101 (patch)
treeeb27a48d0341a13e5da1d8eb97efab65056cc8e3
parent16f1cf8fd4e378d61bb240a8c5bbbeba2d000cb0 (diff)
downloadrust-b2c85b31bbe9dfd841c5d4999ac79cd431489101.tar.gz
rust-b2c85b31bbe9dfd841c5d4999ac79cd431489101.zip
Move bail into lint to prevent no-linting, move to unfixable
-rw-r--r--clippy_lints/src/from_over_into.rs10
-rw-r--r--tests/ui/from_over_into.fixed10
-rw-r--r--tests/ui/from_over_into.rs10
-rw-r--r--tests/ui/from_over_into_unfixable.rs10
-rw-r--r--tests/ui/from_over_into_unfixable.stderr10
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 c4405feaa97..e25b45eaa2e 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<Vec<(Span, String)>> {
+    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 98310ac5c6c..d18f9387565 100644
--- a/tests/ui/from_over_into.fixed
+++ b/tests/ui/from_over_into.fixed
@@ -88,14 +88,4 @@ impl Into<Opaque> for IntoOpaque {
     fn into(self) -> Opaque {}
 }
 
-pub struct Lval<T>(T);
-
-pub struct Rval<T>(T);
-
-impl<T> Into<Rval<Self>> for Lval<T> {
-    fn into(self) -> Rval<Self> {
-        Rval(self)
-    }
-}
-
 fn main() {}
diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs
index 4fb91971db9..de8ff0b06bd 100644
--- a/tests/ui/from_over_into.rs
+++ b/tests/ui/from_over_into.rs
@@ -88,14 +88,4 @@ impl Into<Opaque> for IntoOpaque {
     fn into(self) -> Opaque {}
 }
 
-pub struct Lval<T>(T);
-
-pub struct Rval<T>(T);
-
-impl<T> Into<Rval<Self>> for Lval<T> {
-    fn into(self) -> Rval<Self> {
-        Rval(self)
-    }
-}
-
 fn main() {}
diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs
index 3b280b7488a..92d3504bc23 100644
--- a/tests/ui/from_over_into_unfixable.rs
+++ b/tests/ui/from_over_into_unfixable.rs
@@ -32,4 +32,14 @@ impl Into<u8> for ContainsVal {
     }
 }
 
+pub struct Lval<T>(T);
+
+pub struct Rval<T>(T);
+
+impl<T> Into<Rval<Self>> for Lval<T> {
+    fn into(self) -> Rval<Self> {
+        Rval(self)
+    }
+}
+
 fn main() {}
diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr
index 251f1d84e74..2ab9b9d6b17 100644
--- a/tests/ui/from_over_into_unfixable.stderr
+++ b/tests/ui/from_over_into_unfixable.stderr
@@ -25,5 +25,13 @@ LL | impl Into<u8> for ContainsVal {
            https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
    = help: replace the `Into` implementation with `From<ContainsVal>`
 
-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<T> Into<Rval<Self>> for Lval<T> {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: replace the `Into` implementation with `From<Lval<T>>`
+
+error: aborting due to 4 previous errors