blob: 9a1a3c022c791e933c6b03a0973f87e728aab26f (
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 _ = isize::from(Foo { x: 1 });
//~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
}
|