rust/tests/compile-fail/new_without_default.rs
Andre Bogus 9cfc42275d Split new_without_default and new_without_default_derive.
This is still very slow, because we do a trait lookup for each field.
Perhaps storing the visited types in a set to reuse types would improve
performance somewhat. Also we may want to pre-decide some known types
(e.g. `Vec<T>`, `Option<T>`).
2016-05-24 18:22:18 +02:00

68 lines
1.1 KiB
Rust

#![feature(plugin)]
#![plugin(clippy)]
#![allow(dead_code)]
#![deny(new_without_default, new_without_default_derive)]
struct Foo;
impl Foo {
fn new() -> Foo { Foo } //~ERROR: you should consider deriving a `Default` implementation for `Foo`
}
struct Bar;
impl Bar {
fn new() -> Self { Bar } //~ERROR: you should consider deriving a `Default` implementation for `Bar`
}
struct Ok;
impl Ok {
fn new() -> Self { Ok }
}
impl Default for Ok {
fn default() -> Self { Ok }
}
struct Params;
impl Params {
fn new(_: u32) -> Self { Params }
}
struct GenericsOk<T> {
bar: T,
}
impl<U> Default for GenericsOk<U> {
fn default() -> Self { unimplemented!(); }
}
impl<'c, V> GenericsOk<V> {
fn new() -> GenericsOk<V> { unimplemented!() }
}
struct LtOk<'a> {
foo: &'a bool,
}
impl<'b> Default for LtOk<'b> {
fn default() -> Self { unimplemented!(); }
}
impl<'c> LtOk<'c> {
fn new() -> LtOk<'c> { unimplemented!() }
}
struct LtKo<'a> {
foo: &'a bool,
}
impl<'c> LtKo<'c> {
fn new() -> LtKo<'c> { unimplemented!() } //~ERROR: you should consider adding a `Default` implementation for
}
fn main() {}