rust/tests/ui/new_without_default.rs

95 lines
1.3 KiB
Rust
Raw Normal View History

#![feature(plugin, const_fn)]
#![plugin(clippy)]
#![allow(dead_code)]
#![deny(new_without_default, new_without_default_derive)]
pub struct Foo;
2017-02-08 14:58:07 +01:00
impl Foo {
pub fn new() -> Foo { Foo }
2017-02-08 14:58:07 +01:00
}
pub struct Bar;
2017-02-08 14:58:07 +01:00
impl Bar {
pub fn new() -> Self { Bar }
2017-02-08 14:58:07 +01:00
}
pub struct Ok;
impl Ok {
pub fn new() -> Self { Ok }
}
impl Default for Ok {
fn default() -> Self { Ok }
}
pub struct Params;
impl Params {
pub fn new(_: u32) -> Self { Params }
}
pub struct GenericsOk<T> {
2016-03-03 19:46:10 +01:00
bar: T,
}
impl<U> Default for GenericsOk<U> {
fn default() -> Self { unimplemented!(); }
}
impl<'c, V> GenericsOk<V> {
pub fn new() -> GenericsOk<V> { unimplemented!() }
}
pub struct LtOk<'a> {
foo: &'a bool,
}
impl<'b> Default for LtOk<'b> {
fn default() -> Self { unimplemented!(); }
}
impl<'c> LtOk<'c> {
pub fn new() -> LtOk<'c> { unimplemented!() }
}
pub struct LtKo<'a> {
foo: &'a bool,
}
impl<'c> LtKo<'c> {
pub fn new() -> LtKo<'c> { unimplemented!() }
2017-02-08 14:58:07 +01:00
// FIXME: that suggestion is missing lifetimes
}
struct Private;
impl Private {
fn new() -> Private { unimplemented!() } // We don't lint private items
2016-03-03 19:46:10 +01:00
}
struct Const;
impl Const {
pub const fn new() -> Const { Const } // const fns can't be implemented via Default
}
fn main() {}