2018-10-03 05:11:56 +02:00
|
|
|
#![warn(clippy::new_ret_no_self)]
|
|
|
|
#![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
|
|
|
|
|
2018-12-09 23:26:16 +01:00
|
|
|
fn main() {}
|
2018-10-03 05:11:56 +02:00
|
|
|
|
2018-10-03 12:55:31 +02:00
|
|
|
trait R {
|
|
|
|
type Item;
|
|
|
|
}
|
|
|
|
|
2018-10-05 04:01:04 +02:00
|
|
|
trait Q {
|
|
|
|
type Item;
|
|
|
|
type Item2;
|
|
|
|
}
|
|
|
|
|
2018-10-03 12:55:31 +02:00
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl R for S {
|
|
|
|
type Item = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new() -> impl R<Item = Self> {
|
|
|
|
S
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S2;
|
|
|
|
|
|
|
|
impl R for S2 {
|
|
|
|
type Item = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S2 {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new(_: String) -> impl R<Item = Self> {
|
|
|
|
S2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:59:14 +02:00
|
|
|
struct S3;
|
|
|
|
|
|
|
|
impl R for S3 {
|
|
|
|
type Item = u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S3 {
|
2018-10-05 04:01:04 +02:00
|
|
|
// should trigger the lint
|
2018-10-03 13:59:14 +02:00
|
|
|
pub fn new(_: String) -> impl R<Item = u32> {
|
|
|
|
S3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 04:01:04 +02:00
|
|
|
struct S4;
|
|
|
|
|
|
|
|
impl Q for S4 {
|
|
|
|
type Item = u32;
|
|
|
|
type Item2 = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S4 {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new(_: String) -> impl Q<Item = u32, Item2 = Self> {
|
|
|
|
S4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 12:55:31 +02:00
|
|
|
struct T;
|
|
|
|
|
|
|
|
impl T {
|
|
|
|
// should not trigger lint
|
|
|
|
pub fn new() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 05:11:56 +02:00
|
|
|
|
|
|
|
struct U;
|
|
|
|
|
|
|
|
impl U {
|
|
|
|
// should trigger lint
|
|
|
|
pub fn new() -> u32 {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct V;
|
|
|
|
|
|
|
|
impl V {
|
|
|
|
// should trigger lint
|
|
|
|
pub fn new(_: String) -> u32 {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2018-10-19 13:55:06 +02:00
|
|
|
|
|
|
|
struct TupleReturnerOk;
|
|
|
|
|
|
|
|
impl TupleReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> (Self, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 13:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerOk2;
|
|
|
|
|
|
|
|
impl TupleReturnerOk2 {
|
|
|
|
// should not trigger lint (it doesn't matter which element in the tuple is Self)
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> (u32, Self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 13:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerOk3;
|
|
|
|
|
|
|
|
impl TupleReturnerOk3 {
|
|
|
|
// should not trigger lint (tuple can contain multiple Self)
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> (Self, Self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 13:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerBad;
|
|
|
|
|
|
|
|
impl TupleReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> (u32, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 13:55:06 +02:00
|
|
|
}
|
2018-10-19 14:20:33 +02:00
|
|
|
|
|
|
|
struct MutPointerReturnerOk;
|
|
|
|
|
|
|
|
impl MutPointerReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> *mut Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 14:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MutPointerReturnerOk2;
|
|
|
|
|
|
|
|
impl MutPointerReturnerOk2 {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> *const Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 14:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MutPointerReturnerBad;
|
|
|
|
|
|
|
|
impl MutPointerReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> *mut V {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 14:20:33 +02:00
|
|
|
}
|
2018-10-20 15:29:17 +02:00
|
|
|
|
|
|
|
struct GenericReturnerOk;
|
|
|
|
|
|
|
|
impl GenericReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> Option<Self> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct GenericReturnerBad;
|
|
|
|
|
|
|
|
impl GenericReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> Option<u32> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NestedReturnerOk;
|
|
|
|
|
|
|
|
impl NestedReturnerOk {
|
2018-10-24 15:43:21 +02:00
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> (Option<Self>, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 15:29:17 +02:00
|
|
|
}
|
2018-10-24 15:43:21 +02:00
|
|
|
|
|
|
|
struct NestedReturnerOk2;
|
|
|
|
|
|
|
|
impl NestedReturnerOk2 {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> ((Self, u32), u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-24 15:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NestedReturnerOk3;
|
|
|
|
|
|
|
|
impl NestedReturnerOk3 {
|
|
|
|
// should not trigger lint
|
2018-12-09 23:26:16 +01:00
|
|
|
pub fn new() -> Option<(Self, u32)> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-24 15:43:21 +02:00
|
|
|
}
|