Skip to content

Commit b2c85b3

Browse files
committed
Move bail into lint to prevent no-linting, move to unfixable
1 parent 16f1cf8 commit b2c85b3

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

clippy_lints/src/from_over_into.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
8080
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
8181
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
8282
{
83-
if !target_ty.find_self_aliases().is_empty() {
84-
// It's tricky to expand self-aliases correctly, we'll ignore it to not cause a
85-
// bad suggestion/fix.
86-
return;
87-
}
8883
span_lint_and_then(
8984
cx,
9085
FROM_OVER_INTO,
@@ -161,6 +156,11 @@ fn convert_to_from(
161156
self_ty: &Ty<'_>,
162157
impl_item_ref: &ImplItemRef,
163158
) -> Option<Vec<(Span, String)>> {
159+
if !target_ty.find_self_aliases().is_empty() {
160+
// It's tricky to expand self-aliases correctly, we'll ignore it to not cause a
161+
// bad suggestion/fix.
162+
return None;
163+
}
164164
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
165165
let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else { return None };
166166
let body = cx.tcx.hir().body(body_id);

tests/ui/from_over_into.fixed

-10
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,4 @@ impl Into<Opaque> for IntoOpaque {
8888
fn into(self) -> Opaque {}
8989
}
9090

91-
pub struct Lval<T>(T);
92-
93-
pub struct Rval<T>(T);
94-
95-
impl<T> Into<Rval<Self>> for Lval<T> {
96-
fn into(self) -> Rval<Self> {
97-
Rval(self)
98-
}
99-
}
100-
10191
fn main() {}

tests/ui/from_over_into.rs

-10
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,4 @@ impl Into<Opaque> for IntoOpaque {
8888
fn into(self) -> Opaque {}
8989
}
9090

91-
pub struct Lval<T>(T);
92-
93-
pub struct Rval<T>(T);
94-
95-
impl<T> Into<Rval<Self>> for Lval<T> {
96-
fn into(self) -> Rval<Self> {
97-
Rval(self)
98-
}
99-
}
100-
10191
fn main() {}

tests/ui/from_over_into_unfixable.rs

+10
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ impl Into<u8> for ContainsVal {
3232
}
3333
}
3434

35+
pub struct Lval<T>(T);
36+
37+
pub struct Rval<T>(T);
38+
39+
impl<T> Into<Rval<Self>> for Lval<T> {
40+
fn into(self) -> Rval<Self> {
41+
Rval(self)
42+
}
43+
}
44+
3545
fn main() {}

tests/ui/from_over_into_unfixable.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,13 @@ LL | impl Into<u8> for ContainsVal {
2525
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
2626
= help: replace the `Into` implementation with `From<ContainsVal>`
2727

28-
error: aborting due to 3 previous errors
28+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
29+
--> $DIR/from_over_into_unfixable.rs:39:1
30+
|
31+
LL | impl<T> Into<Rval<Self>> for Lval<T> {
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= help: replace the `Into` implementation with `From<Lval<T>>`
35+
36+
error: aborting due to 4 previous errors
2937

0 commit comments

Comments
 (0)