about summary refs log tree commit diff
path: root/tests/ui/cast/non-primitive-cast-suggestion.rs
blob: 79006f4ba26d3c4d57c8bfa603c56882338d9598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion.
//!
//! You can't use `as` to cast between non-primitive types, even if they have
//! `From`/`Into` implementations. The compiler should suggest using `From::from()`
//! or `.into()` instead, and rustfix should be able to apply the suggestion.

//@ run-rustfix

#[derive(Debug)]
struct Foo {
    x: isize,
}

impl From<Foo> for isize {
    fn from(val: Foo) -> isize {
        val.x
    }
}

fn main() {
    let _ = Foo { x: 1 } as isize;
    //~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
}