1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
//@ check-pass
//@ edition:2021
struct Cat;
struct Wrap<T>(T);
fn main() {
impl From<Cat> for () {
//~^ WARN non-local `impl` definition
fn from(_: Cat) -> () {
todo!()
}
}
#[derive(Debug)]
struct Elephant;
impl From<Wrap<Wrap<Elephant>>> for () {
fn from(_: Wrap<Wrap<Elephant>>) -> Self {
todo!()
}
}
}
pub trait StillNonLocal {}
impl StillNonLocal for &str {}
fn only_global() {
struct Foo;
impl StillNonLocal for &Foo {}
}
struct GlobalSameFunction;
fn same_function() {
struct Local1(GlobalSameFunction);
impl From<Local1> for GlobalSameFunction {
fn from(x: Local1) -> GlobalSameFunction {
x.0
}
}
struct Local2(GlobalSameFunction);
impl From<Local2> for GlobalSameFunction {
fn from(x: Local2) -> GlobalSameFunction {
x.0
}
}
}
struct GlobalDifferentFunction;
fn diff_function_1() {
struct Local(GlobalDifferentFunction);
impl From<Local> for GlobalDifferentFunction {
fn from(x: Local) -> GlobalDifferentFunction {
x.0
}
}
}
fn diff_function_2() {
struct Local(GlobalDifferentFunction);
impl From<Local> for GlobalDifferentFunction {
fn from(x: Local) -> GlobalDifferentFunction {
x.0
}
}
}
// https://github.com/rust-lang/rust/issues/121621#issuecomment-1976826895
fn commonly_reported() {
struct Local(u8);
impl From<Local> for u8 {
fn from(x: Local) -> u8 {
x.0
}
}
}
// https://github.com/rust-lang/rust/issues/121621#issue-2153187542
pub trait Serde {}
impl Serde for &[u8] {}
impl Serde for &str {}
fn serde() {
struct Thing;
impl Serde for &Thing {}
}
|