Skip to content

Commit b43c9f7

Browse files
committed
Auto merge of #9982 - Jarcho:issue_9935, r=flip1995
Don't lint `from_over_into` for opaque types fixes #9935 This is stalled until the next sync. The impl in question can't be written on the pinned nightly. changelog: Don't lint `from_over_into` for opaque types
2 parents fec0057 + 6ecdff0 commit b43c9f7

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{
1010
TyKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
13-
use rustc_middle::hir::nested_filter::OnlyBodies;
13+
use rustc_middle::{hir::nested_filter::OnlyBodies, ty};
1414
use rustc_session::{declare_tool_lint, impl_lint_pass};
1515
use rustc_span::symbol::{kw, sym};
1616
use rustc_span::{Span, Symbol};
@@ -78,6 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
7878
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
7979
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
8080
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
81+
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Opaque(..))
8182
{
8283
span_lint_and_then(
8384
cx,

tests/ui/from_over_into.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22

3+
#![feature(type_alias_impl_trait)]
34
#![warn(clippy::from_over_into)]
45
#![allow(unused)]
56

@@ -81,4 +82,10 @@ fn msrv_1_41() {
8182
}
8283
}
8384

85+
type Opaque = impl Sized;
86+
struct IntoOpaque;
87+
impl Into<Opaque> for IntoOpaque {
88+
fn into(self) -> Opaque {}
89+
}
90+
8491
fn main() {}

tests/ui/from_over_into.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22

3+
#![feature(type_alias_impl_trait)]
34
#![warn(clippy::from_over_into)]
45
#![allow(unused)]
56

@@ -81,4 +82,10 @@ fn msrv_1_41() {
8182
}
8283
}
8384

85+
type Opaque = impl Sized;
86+
struct IntoOpaque;
87+
impl Into<Opaque> for IntoOpaque {
88+
fn into(self) -> Opaque {}
89+
}
90+
8491
fn main() {}

tests/ui/from_over_into.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
2-
--> $DIR/from_over_into.rs:9:1
2+
--> $DIR/from_over_into.rs:10:1
33
|
44
LL | impl Into<StringWrapper> for String {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL ~ StringWrapper(val)
1313
|
1414

1515
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
16-
--> $DIR/from_over_into.rs:17:1
16+
--> $DIR/from_over_into.rs:18:1
1717
|
1818
LL | impl Into<SelfType> for String {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL ~ SelfType(String::new())
2626
|
2727

2828
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.rs:32:1
29+
--> $DIR/from_over_into.rs:33:1
3030
|
3131
LL | impl Into<SelfKeywords> for X {
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -41,7 +41,7 @@ LL ~ let _: X = val;
4141
|
4242

4343
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
44-
--> $DIR/from_over_into.rs:44:1
44+
--> $DIR/from_over_into.rs:45:1
4545
|
4646
LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -59,7 +59,7 @@ LL ~ val.0
5959
|
6060

6161
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
62-
--> $DIR/from_over_into.rs:77:5
62+
--> $DIR/from_over_into.rs:78:5
6363
|
6464
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)