mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 18:27:37 +00:00

Using an error type instead of `()` avoids the duplicated errors on `struct SUnsizedField` in `deriving-from-wrong-target.rs`. It also improves the expanded output from this: ``` struct S2(u32, u32); impl ::core::convert::From<()> for S2 { #[inline] fn from(value: ()) -> S2 { (/*ERROR*/) } } ``` to this: ``` struct S2(u32, u32); impl ::core::convert::From<(/*ERROR*/)> for S2 { #[inline] fn from(value: (/*ERROR*/)) -> S2 { (/*ERROR*/) } } ``` The new code also only matchs on `item.kind` once.
38 lines
737 B
Rust
38 lines
737 B
Rust
//@ check-fail
|
|
|
|
#![feature(derive_from)]
|
|
#![allow(dead_code)]
|
|
|
|
use std::from::From;
|
|
|
|
#[derive(From)]
|
|
//~^ ERROR `#[derive(From)]` used on a struct with no fields
|
|
struct S1;
|
|
|
|
#[derive(From)]
|
|
//~^ ERROR `#[derive(From)]` used on a struct with no fields
|
|
struct S2 {}
|
|
|
|
#[derive(From)]
|
|
//~^ ERROR `#[derive(From)]` used on a struct with multiple fields
|
|
struct S3(u32, bool);
|
|
|
|
#[derive(From)]
|
|
//~^ ERROR `#[derive(From)]` used on a struct with multiple fields
|
|
struct S4 {
|
|
a: u32,
|
|
b: bool,
|
|
}
|
|
|
|
#[derive(From)]
|
|
//~^ ERROR `#[derive(From)]` used on an enum
|
|
enum E1 {}
|
|
|
|
#[derive(From)]
|
|
struct SUnsizedField<T: ?Sized> {
|
|
last: T,
|
|
//~^ ERROR the size for values of type `T` cannot be known at compilation time [E0277]
|
|
}
|
|
|
|
fn main() {}
|