@@ -22,8 +22,8 @@ use std::collections::BTreeMap;
2222use std:: collections:: HashMap ;
2323use std:: collections:: HashSet ;
2424use std:: collections:: VecDeque ;
25- use std:: ops:: Mul ;
2625use std:: iter:: FromIterator ;
26+ use std:: ops:: Mul ;
2727use std:: rc:: { self , Rc } ;
2828use std:: sync:: { self , Arc } ;
2929
@@ -32,22 +32,51 @@ use option_helpers::IteratorFalsePositives;
3232pub struct T ;
3333
3434impl T {
35- pub fn add ( self , other : T ) -> T { self }
35+ pub fn add ( self , other : T ) -> T {
36+ self
37+ }
38+
39+ // no error, not public interface
40+ pub ( crate ) fn drop ( & mut self ) { }
3641
37- pub ( crate ) fn drop ( & mut self ) { } // no error, not public interfact
38- fn neg ( self ) -> Self { self } // no error, private function
39- fn eq ( & self , other : T ) -> bool { true } // no error, private function
42+ // no error, private function
43+ fn neg ( self ) -> Self {
44+ self
45+ }
46+
47+ // no error, private function
48+ fn eq ( & self , other : T ) -> bool {
49+ true
50+ }
4051
41- fn sub ( & self , other : T ) -> & T { self } // no error, self is a ref
42- fn div ( self ) -> T { self } // no error, different #arguments
43- fn rem ( self , other : T ) { } // no error, wrong return type
52+ // no error, self is a ref
53+ fn sub ( & self , other : T ) -> & T {
54+ self
55+ }
56+
57+ // no error, different #arguments
58+ fn div ( self ) -> T {
59+ self
60+ }
61+
62+ fn rem ( self , other : T ) { } // no error, wrong return type
63+
64+ // fine
65+ fn into_u32 ( self ) -> u32 {
66+ 0
67+ }
4468
45- fn into_u32 ( self ) -> u32 { 0 } // fine
46- fn into_u16 ( & self ) -> u16 { 0 }
69+ fn into_u16 ( & self ) -> u16 {
70+ 0
71+ }
4772
48- fn to_something ( self ) -> u32 { 0 }
73+ fn to_something ( self ) -> u32 {
74+ 0
75+ }
4976
50- fn new ( self ) -> Self { unimplemented ! ( ) ; }
77+ fn new ( self ) -> Self {
78+ unimplemented ! ( ) ;
79+ }
5180}
5281
5382struct Lt < ' a > {
@@ -57,7 +86,9 @@ struct Lt<'a> {
5786impl < ' a > Lt < ' a > {
5887 // The lifetime is different, but that’s irrelevant, see #734
5988 #[ allow( clippy:: needless_lifetimes) ]
60- pub fn new < ' b > ( s : & ' b str ) -> Lt < ' b > { unimplemented ! ( ) }
89+ pub fn new < ' b > ( s : & ' b str ) -> Lt < ' b > {
90+ unimplemented ! ( )
91+ }
6192}
6293
6394struct Lt2 < ' a > {
@@ -66,7 +97,9 @@ struct Lt2<'a> {
6697
6798impl < ' a > Lt2 < ' a > {
6899 // The lifetime is different, but that’s irrelevant, see #734
69- pub fn new ( s : & str ) -> Lt2 { unimplemented ! ( ) }
100+ pub fn new ( s : & str ) -> Lt2 {
101+ unimplemented ! ( )
102+ }
70103}
71104
72105struct Lt3 < ' a > {
@@ -75,28 +108,40 @@ struct Lt3<'a> {
75108
76109impl < ' a > Lt3 < ' a > {
77110 // The lifetime is different, but that’s irrelevant, see #734
78- pub fn new ( ) -> Lt3 < ' static > { unimplemented ! ( ) }
111+ pub fn new ( ) -> Lt3 < ' static > {
112+ unimplemented ! ( )
113+ }
79114}
80115
81- #[ derive( Clone , Copy ) ]
116+ #[ derive( Clone , Copy ) ]
82117struct U ;
83118
84119impl U {
85- fn new ( ) -> Self { U }
86- fn to_something ( self ) -> u32 { 0 } // ok because U is Copy
120+ fn new ( ) -> Self {
121+ U
122+ }
123+ // ok because U is Copy
124+ fn to_something ( self ) -> u32 {
125+ 0
126+ }
87127}
88128
89129struct V < T > {
90- _dummy : T
130+ _dummy : T ,
91131}
92132
93133impl < T > V < T > {
94- fn new ( ) -> Option < V < T > > { None }
134+ fn new ( ) -> Option < V < T > > {
135+ None
136+ }
95137}
96138
97139impl Mul < T > for T {
98140 type Output = T ;
99- fn mul ( self , other : T ) -> T { self } // no error, obviously
141+ // no error, obviously
142+ fn mul ( self , other : T ) -> T {
143+ self
144+ }
100145}
101146
102147/// Checks implementation of the following lints:
@@ -238,16 +283,18 @@ fn or_fun_call() {
238283 struct Foo ;
239284
240285 impl Foo {
241- fn new ( ) -> Foo { Foo }
286+ fn new ( ) -> Foo {
287+ Foo
288+ }
242289 }
243290
244291 enum Enum {
245292 A ( i32 ) ,
246293 }
247294
248-
249-
250- fn make < T > ( ) -> T { unimplemented ! ( ) ; }
295+ fn make < T > ( ) -> T {
296+ unimplemented ! ( ) ;
297+ }
251298
252299 let with_enum = Some ( Enum :: A ( 1 ) ) ;
253300 with_enum. unwrap_or ( Enum :: A ( 5 ) ) ;
@@ -264,10 +311,10 @@ fn or_fun_call() {
264311 let with_const_args = Some ( vec ! [ 1 ] ) ;
265312 with_const_args. unwrap_or ( Vec :: with_capacity ( 12 ) ) ;
266313
267- let with_err : Result < _ , ( ) > = Ok ( vec ! [ 1 ] ) ;
314+ let with_err: Result < _ , ( ) > = Ok ( vec ! [ 1 ] ) ;
268315 with_err. unwrap_or ( make ( ) ) ;
269316
270- let with_err_args : Result < _ , ( ) > = Ok ( vec ! [ 1 ] ) ;
317+ let with_err_args: Result < _ , ( ) > = Ok ( vec ! [ 1 ] ) ;
271318 with_err_args. unwrap_or ( Vec :: with_capacity ( 12 ) ) ;
272319
273320 let with_default_trait = Some ( 1 ) ;
0 commit comments