2022-10-14 17:50:23 -05:00
|
|
|
#![warn(clippy::from_over_into)]
|
|
|
|
|
|
|
|
struct InMacro(String);
|
|
|
|
|
|
|
|
macro_rules! in_macro {
|
2023-05-28 16:50:08 -05:00
|
|
|
() => {
|
|
|
|
Self::new()
|
2022-10-14 17:50:23 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<InMacro> for String {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free
|
2022-10-14 17:50:23 -05:00
|
|
|
fn into(self) -> InMacro {
|
2023-05-28 16:50:08 -05:00
|
|
|
InMacro(in_macro!())
|
2022-10-14 17:50:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct WeirdUpperSelf;
|
|
|
|
|
|
|
|
impl Into<WeirdUpperSelf> for &'static [u8] {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free
|
2022-10-14 17:50:23 -05:00
|
|
|
fn into(self) -> WeirdUpperSelf {
|
|
|
|
let _ = Self::default();
|
|
|
|
WeirdUpperSelf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ContainsVal;
|
|
|
|
|
|
|
|
impl Into<u8> for ContainsVal {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free
|
2022-10-14 17:50:23 -05:00
|
|
|
fn into(self) -> u8 {
|
|
|
|
let val = 1;
|
|
|
|
val + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 09:02:42 -05:00
|
|
|
pub struct Lval<T>(T);
|
|
|
|
|
|
|
|
pub struct Rval<T>(T);
|
|
|
|
|
|
|
|
impl<T> Into<Rval<Self>> for Lval<T> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free
|
2023-06-01 09:02:42 -05:00
|
|
|
fn into(self) -> Rval<Self> {
|
|
|
|
Rval(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 17:50:23 -05:00
|
|
|
fn main() {}
|