mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
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
This commit is contained in:
commit
b43c9f7638
@ -10,7 +10,7 @@ use rustc_hir::{
|
|||||||
TyKind,
|
TyKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
use rustc_middle::{hir::nested_filter::OnlyBodies, ty};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::symbol::{kw, sym};
|
use rustc_span::symbol::{kw, sym};
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
@ -78,6 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
|||||||
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
||||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
||||||
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
||||||
|
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Opaque(..))
|
||||||
{
|
{
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
#![warn(clippy::from_over_into)]
|
#![warn(clippy::from_over_into)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
@ -81,4 +82,10 @@ fn msrv_1_41() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Opaque = impl Sized;
|
||||||
|
struct IntoOpaque;
|
||||||
|
impl Into<Opaque> for IntoOpaque {
|
||||||
|
fn into(self) -> Opaque {}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
#![warn(clippy::from_over_into)]
|
#![warn(clippy::from_over_into)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
@ -81,4 +82,10 @@ fn msrv_1_41() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Opaque = impl Sized;
|
||||||
|
struct IntoOpaque;
|
||||||
|
impl Into<Opaque> for IntoOpaque {
|
||||||
|
fn into(self) -> Opaque {}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
||||||
--> $DIR/from_over_into.rs:9:1
|
--> $DIR/from_over_into.rs:10:1
|
||||||
|
|
|
|
||||||
LL | impl Into<StringWrapper> for String {
|
LL | impl Into<StringWrapper> for String {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -13,7 +13,7 @@ LL ~ StringWrapper(val)
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
||||||
--> $DIR/from_over_into.rs:17:1
|
--> $DIR/from_over_into.rs:18:1
|
||||||
|
|
|
|
||||||
LL | impl Into<SelfType> for String {
|
LL | impl Into<SelfType> for String {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -26,7 +26,7 @@ LL ~ SelfType(String::new())
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
||||||
--> $DIR/from_over_into.rs:32:1
|
--> $DIR/from_over_into.rs:33:1
|
||||||
|
|
|
|
||||||
LL | impl Into<SelfKeywords> for X {
|
LL | impl Into<SelfKeywords> for X {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -41,7 +41,7 @@ LL ~ let _: X = val;
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
||||||
--> $DIR/from_over_into.rs:44:1
|
--> $DIR/from_over_into.rs:45:1
|
||||||
|
|
|
|
||||||
LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
|
LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -59,7 +59,7 @@ LL ~ val.0
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
|
||||||
--> $DIR/from_over_into.rs:77:5
|
--> $DIR/from_over_into.rs:78:5
|
||||||
|
|
|
|
||||||
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
|
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Loading…
Reference in New Issue
Block a user