2022-12-17 13:12:54 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2021-01-02 15:29:43 +00:00
|
|
|
#![warn(clippy::from_over_into)]
|
2024-01-26 17:48:18 +00:00
|
|
|
#![allow(non_local_definitions)]
|
2022-10-23 13:18:45 +00:00
|
|
|
#![allow(unused)]
|
2021-01-02 15:29:43 +00:00
|
|
|
|
|
|
|
// this should throw an error
|
|
|
|
struct StringWrapper(String);
|
|
|
|
|
|
|
|
impl Into<StringWrapper> for String {
|
|
|
|
fn into(self) -> StringWrapper {
|
|
|
|
StringWrapper(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 13:18:45 +00:00
|
|
|
struct SelfType(String);
|
|
|
|
|
|
|
|
impl Into<SelfType> for String {
|
|
|
|
fn into(self) -> SelfType {
|
|
|
|
SelfType(Self::new())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct X;
|
|
|
|
|
|
|
|
impl X {
|
|
|
|
const FOO: &'static str = "a";
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SelfKeywords;
|
|
|
|
|
|
|
|
impl Into<SelfKeywords> for X {
|
|
|
|
fn into(self) -> SelfKeywords {
|
2023-05-05 15:45:49 +00:00
|
|
|
let _ = Self;
|
2022-10-23 13:18:45 +00:00
|
|
|
let _ = Self::FOO;
|
|
|
|
let _: Self = self;
|
|
|
|
|
|
|
|
SelfKeywords
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ExplicitPaths(bool);
|
|
|
|
|
|
|
|
impl core::convert::Into<bool> for crate::ExplicitPaths {
|
|
|
|
fn into(mut self) -> bool {
|
|
|
|
let in_closure = || self.0;
|
|
|
|
|
|
|
|
self.0 = false;
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 15:29:43 +00:00
|
|
|
// this is fine
|
|
|
|
struct A(String);
|
|
|
|
|
|
|
|
impl From<String> for A {
|
|
|
|
fn from(s: String) -> A {
|
|
|
|
A(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 12:35:19 +00:00
|
|
|
struct PathInExpansion;
|
|
|
|
|
|
|
|
impl Into<String> for PathInExpansion {
|
|
|
|
fn into(self) -> String {
|
|
|
|
// non self/Self paths in expansions are fine
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.40"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_40() {
|
|
|
|
struct FromOverInto<T>(Vec<T>);
|
|
|
|
|
|
|
|
impl<T> Into<FromOverInto<T>> for Vec<T> {
|
|
|
|
fn into(self) -> FromOverInto<T> {
|
|
|
|
FromOverInto(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.41"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_41() {
|
|
|
|
struct FromOverInto<T>(Vec<T>);
|
|
|
|
|
|
|
|
impl<T> Into<FromOverInto<T>> for Vec<T> {
|
|
|
|
fn into(self) -> FromOverInto<T> {
|
|
|
|
FromOverInto(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-25 18:17:36 +00:00
|
|
|
fn issue_12138() {
|
|
|
|
struct Hello;
|
|
|
|
|
|
|
|
impl Into<()> for Hello {
|
|
|
|
fn into(self) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 15:29:43 +00:00
|
|
|
fn main() {}
|