2017-07-28 13:28:07 +02:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
#![warn(use_self)]
|
|
|
|
#![allow(dead_code)]
|
2017-08-22 00:18:37 +02:00
|
|
|
#![allow(should_implement_trait)]
|
2017-07-28 13:28:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
mod use_self {
|
|
|
|
struct Foo {}
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn new() -> Foo {
|
|
|
|
Foo {}
|
|
|
|
}
|
|
|
|
fn test() -> Foo {
|
|
|
|
Foo::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Foo {
|
|
|
|
fn default() -> Foo {
|
|
|
|
Foo::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod better {
|
|
|
|
struct Foo {}
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn new() -> Self {
|
|
|
|
Self {}
|
|
|
|
}
|
|
|
|
fn test() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Foo {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 00:18:37 +02:00
|
|
|
|
|
|
|
//todo the lint does not handle lifetimed struct
|
|
|
|
//the following module should trigger the lint on the third method only
|
|
|
|
mod lifetimes {
|
|
|
|
struct Foo<'a>{foo_str: &'a str}
|
|
|
|
|
|
|
|
impl<'a> Foo<'a> {
|
|
|
|
// Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>`
|
|
|
|
fn foo(s: &str) -> Foo {
|
|
|
|
Foo { foo_str: s }
|
|
|
|
}
|
|
|
|
// cannot replace with `Self`, because that's `Foo<'a>`
|
|
|
|
fn bar() -> Foo<'static> {
|
|
|
|
Foo { foo_str: "foo"}
|
|
|
|
}
|
|
|
|
|
|
|
|
// `Self` is applicable here
|
|
|
|
fn clone(&self) -> Foo<'a> {
|
|
|
|
Foo {foo_str: self.foo_str}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|