2018-10-06 11:18:06 -05:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-05-11 06:20:39 -05:00
|
|
|
#![feature(const_fn)]
|
2016-03-01 09:25:15 -06:00
|
|
|
#![allow(dead_code)]
|
2018-07-28 10:34:52 -05:00
|
|
|
#![warn(clippy::new_without_default, clippy::new_without_default_derive)]
|
2016-03-01 09:25:15 -06:00
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct Foo;
|
2017-02-08 07:58:07 -06:00
|
|
|
|
2016-03-01 09:25:15 -06:00
|
|
|
impl Foo {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> Foo {
|
|
|
|
Foo
|
|
|
|
}
|
2016-03-01 09:25:15 -06:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct Bar;
|
2017-02-08 07:58:07 -06:00
|
|
|
|
2016-03-01 09:25:15 -06:00
|
|
|
impl Bar {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Bar
|
|
|
|
}
|
2016-03-01 09:25:15 -06:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct Ok;
|
2016-03-01 09:25:15 -06:00
|
|
|
|
|
|
|
impl Ok {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Ok
|
|
|
|
}
|
2016-03-01 09:25:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Ok {
|
2018-12-09 16:26:16 -06:00
|
|
|
fn default() -> Self {
|
|
|
|
Ok
|
|
|
|
}
|
2016-03-01 09:25:15 -06:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct Params;
|
2016-03-01 09:25:15 -06:00
|
|
|
|
|
|
|
impl Params {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new(_: u32) -> Self {
|
|
|
|
Params
|
|
|
|
}
|
2016-03-01 09:25:15 -06:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct GenericsOk<T> {
|
2016-03-03 12:46:10 -06:00
|
|
|
bar: T,
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:12:32 -05:00
|
|
|
impl<U> Default for GenericsOk<U> {
|
2018-12-09 16:26:16 -06:00
|
|
|
fn default() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2016-03-18 13:12:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c, V> GenericsOk<V> {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> GenericsOk<V> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-03-18 13:12:32 -05:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct LtOk<'a> {
|
2016-03-18 13:12:32 -05:00
|
|
|
foo: &'a bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'b> Default for LtOk<'b> {
|
2018-12-09 16:26:16 -06:00
|
|
|
fn default() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2016-03-18 13:12:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> LtOk<'c> {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> LtOk<'c> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-03-18 13:12:32 -05:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:35:14 -05:00
|
|
|
pub struct LtKo<'a> {
|
2016-03-18 13:12:32 -05:00
|
|
|
foo: &'a bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> LtKo<'c> {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new() -> LtKo<'c> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-07-10 07:07:13 -05:00
|
|
|
// FIXME: that suggestion is missing lifetimes
|
2016-06-01 16:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Private;
|
|
|
|
|
|
|
|
impl Private {
|
2018-12-09 16:26:16 -06:00
|
|
|
fn new() -> Private {
|
|
|
|
unimplemented!()
|
|
|
|
} // We don't lint private items
|
2016-03-03 12:46:10 -06:00
|
|
|
}
|
|
|
|
|
2016-06-03 09:45:07 -05:00
|
|
|
struct Const;
|
|
|
|
|
|
|
|
impl Const {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub const fn new() -> Const {
|
|
|
|
Const
|
|
|
|
} // const fns can't be implemented via Default
|
2016-06-03 09:45:07 -05:00
|
|
|
}
|
2017-06-14 11:50:19 -05:00
|
|
|
|
|
|
|
pub struct IgnoreGenericNew;
|
|
|
|
|
|
|
|
impl IgnoreGenericNew {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn new<T>() -> Self {
|
|
|
|
IgnoreGenericNew
|
|
|
|
} // the derived Default does not make sense here as the result depends on T
|
2017-06-14 11:50:19 -05:00
|
|
|
}
|
|
|
|
|
2017-11-29 10:06:27 -06:00
|
|
|
pub trait TraitWithNew: Sized {
|
|
|
|
fn new() -> Self {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:39:54 -05:00
|
|
|
pub struct IgnoreUnsafeNew;
|
|
|
|
|
|
|
|
impl IgnoreUnsafeNew {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub unsafe fn new() -> Self {
|
|
|
|
IgnoreUnsafeNew
|
|
|
|
}
|
2018-10-07 05:39:54 -05:00
|
|
|
}
|
|
|
|
|
2018-10-21 23:59:45 -05:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct OptionRefWrapper<'a, T: 'a>(Option<&'a T>);
|
|
|
|
|
|
|
|
impl<'a, T: 'a> OptionRefWrapper<'a, T> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
OptionRefWrapper(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 09:25:15 -06:00
|
|
|
fn main() {}
|