@@ -74,6 +74,7 @@ pub enum VolatileItemKind {
74
74
/// This builder has a number of configuration options which modify how the
75
75
/// generated tests are emitted, and it is also the main entry point for parsing
76
76
/// an FFI header crate for definitions.
77
+ #[ allow( clippy:: type_complexity) ]
77
78
pub struct TestGenerator {
78
79
headers : Vec < String > ,
79
80
includes : Vec < PathBuf > ,
@@ -163,7 +164,7 @@ impl TestGenerator {
163
164
f. to_string ( )
164
165
}
165
166
} ) ,
166
- const_cname : Box :: new ( std :: string :: ToString :: to_string) ,
167
+ const_cname : Box :: new ( ToString :: to_string) ,
167
168
rust_version : rustc_version:: version ( ) . unwrap ( ) ,
168
169
}
169
170
}
@@ -324,7 +325,7 @@ impl TestGenerator {
324
325
/// ```
325
326
pub fn define ( & mut self , k : & str , v : Option < & str > ) -> & mut Self {
326
327
self . defines
327
- . push ( ( k. to_string ( ) , v. map ( std :: string :: ToString :: to_string) ) ) ;
328
+ . push ( ( k. to_string ( ) , v. map ( ToString :: to_string) ) ) ;
328
329
self
329
330
}
330
331
@@ -337,10 +338,10 @@ impl TestGenerator {
337
338
/// optional value of `v`:
338
339
///
339
340
/// * `k == "foo"` and `v == None` makes `#[cfg(foo)]` expand. That is,
340
- /// `cfg!(foo)` expands to `true`.
341
+ /// `cfg!(foo)` expands to `true`.
341
342
///
342
343
/// * `k == "bar"` and `v == Some("baz")` makes `#[cfg(bar = "baz")]`
343
- /// expand. That is, `cfg!(bar = "baz")` expands to `true`.
344
+ /// expand. That is, `cfg!(bar = "baz")` expands to `true`.
344
345
///
345
346
/// # Examples
346
347
///
@@ -352,8 +353,7 @@ impl TestGenerator {
352
353
/// .cfg("bar", Some("baz")); // cfg!(bar = "baz")
353
354
/// ```
354
355
pub fn cfg ( & mut self , k : & str , v : Option < & str > ) -> & mut Self {
355
- self . cfg
356
- . push ( ( k. to_string ( ) , v. map ( std:: string:: ToString :: to_string) ) ) ;
356
+ self . cfg . push ( ( k. to_string ( ) , v. map ( ToString :: to_string) ) ) ;
357
357
self
358
358
}
359
359
@@ -811,7 +811,7 @@ impl TestGenerator {
811
811
Lang :: C => "c" ,
812
812
Lang :: CXX => "cpp" ,
813
813
} ;
814
- cfg. file ( & out. with_extension ( ext) ) ;
814
+ cfg. file ( out. with_extension ( ext) ) ;
815
815
if target. contains ( "msvc" ) {
816
816
cfg. flag ( "/W3" ) . flag ( "/Wall" ) . flag ( "/WX" )
817
817
// ignored warnings
@@ -844,7 +844,7 @@ impl TestGenerator {
844
844
cfg. flag ( flag) ;
845
845
}
846
846
847
- for & ( ref a , ref b) in & self . defines {
847
+ for ( a , b) in & self . defines {
848
848
cfg. define ( a, b. as_ref ( ) . map ( |s| & s[ ..] ) ) ;
849
849
}
850
850
for p in & self . includes {
@@ -884,7 +884,7 @@ impl TestGenerator {
884
884
. clone ( )
885
885
. unwrap_or_else ( || env:: var ( "TARGET" ) . unwrap ( ) ) ;
886
886
for ( k, v) in default_cfg ( & target) . into_iter ( ) . chain ( self . cfg . clone ( ) ) {
887
- let s = |s : & str | ast :: Name :: intern ( s) ;
887
+ let s = |s : & str | Name :: intern ( s) ;
888
888
sess. config . insert ( ( s ( & k) , v. as_ref ( ) . map ( |n| s ( n) ) ) ) ;
889
889
}
890
890
@@ -995,9 +995,7 @@ fn default_cfg(target: &str) -> Vec<(String, Option<String>)> {
995
995
( "powerpc" , "32" , "big" )
996
996
} else if target. starts_with ( "s390x" ) {
997
997
( "s390x" , "64" , "big" )
998
- } else if target. starts_with ( "sparc64" ) {
999
- ( "sparc64" , "64" , "big" )
1000
- } else if target. starts_with ( "sparcv9" ) {
998
+ } else if target. starts_with ( "sparc64" ) || target. starts_with ( "sparcv9" ) {
1001
999
( "sparc64" , "64" , "big" )
1002
1000
} else if target. starts_with ( "asmjs" ) {
1003
1001
( "asmjs" , "32" , "little" )
@@ -1092,7 +1090,7 @@ fn linkage(lang: &Lang) -> &'static str {
1092
1090
}
1093
1091
}
1094
1092
1095
- impl < ' a > Generator < ' a > {
1093
+ impl Generator < ' _ > {
1096
1094
fn rust2c_test ( & self , ty : & str ) -> bool {
1097
1095
let rustc_types = [
1098
1096
"usize" , "u8" , "u16" , "u32" , "u64" , "isize" , "i8" , "i16" , "i32" , "i64" ,
@@ -1116,7 +1114,7 @@ impl<'a> Generator<'a> {
1116
1114
1117
1115
fn rust2c ( & self , ty : & str ) -> String {
1118
1116
match ty {
1119
- "c_longdouble" | "c_long_double" => format ! ( "long double" ) ,
1117
+ "c_longdouble" | "c_long_double" => "long double" . to_string ( ) ,
1120
1118
t if t. starts_with ( "c_" ) => match & ty[ 2 ..] . replace ( "long" , " long" ) [ ..] {
1121
1119
s if s. starts_with ( 'u' ) => format ! ( "unsigned {}" , & s[ 1 ..] ) ,
1122
1120
"short" => "short" . to_string ( ) ,
@@ -1983,8 +1981,8 @@ impl<'a> Generator<'a> {
1983
1981
ast:: TyKind :: Path ( _, ref path) => {
1984
1982
let last = path. segments . last ( ) . unwrap ( ) ;
1985
1983
if last. identifier . to_string ( ) == "Option" {
1986
- match last. parameters . as_ref ( ) . map ( |p| & * * p ) {
1987
- Some ( & ast:: PathParameters :: AngleBracketed ( ref p) ) => {
1984
+ match last. parameters . as_deref ( ) {
1985
+ Some ( ast:: PathParameters :: AngleBracketed ( p) ) => {
1988
1986
self . ty2name ( & p. types [ 0 ] , rust)
1989
1987
}
1990
1988
_ => panic ! ( ) ,
@@ -2016,7 +2014,7 @@ impl<'a> Generator<'a> {
2016
2014
format ! ( "{} {modifier}*" , self . ty2name( & t. ty, rust) )
2017
2015
}
2018
2016
ast:: TyKind :: Array ( ref t, ref e) => {
2019
- let len = self . expr2str ( e) ;
2017
+ let len = Self :: expr2str ( e) ;
2020
2018
let ty = self . ty2name ( t, rust) ;
2021
2019
format ! ( "{modifier} {ty} [{len}]" )
2022
2020
}
@@ -2055,9 +2053,9 @@ impl<'a> Generator<'a> {
2055
2053
}
2056
2054
ast:: TyKind :: Array ( ref t, ref e) => {
2057
2055
if rust {
2058
- format ! ( "[{}; {}]" , self . ty2name( t, rust) , self . expr2str( e) )
2056
+ format ! ( "[{}; {}]" , self . ty2name( t, rust) , Self :: expr2str( e) )
2059
2057
} else {
2060
- let len = self . expr2str ( e) ;
2058
+ let len = Self :: expr2str ( e) ;
2061
2059
let ty = self . ty2name ( t, rust) ;
2062
2060
format ! ( "{ty} [{len}]" )
2063
2061
}
@@ -2124,8 +2122,8 @@ impl<'a> Generator<'a> {
2124
2122
if path. segments . last ( ) . unwrap ( ) . identifier . to_string ( ) == "Option" =>
2125
2123
{
2126
2124
let last = path. segments . last ( ) . unwrap ( ) ;
2127
- match last. parameters . as_ref ( ) . map ( |s| & * * s ) {
2128
- Some ( & ast:: PathParameters :: AngleBracketed ( ref p) ) => {
2125
+ match last. parameters . as_deref ( ) {
2126
+ Some ( ast:: PathParameters :: AngleBracketed ( p) ) => {
2129
2127
self . csig_returning_ptr ( & p. types [ 0 ] , sig)
2130
2128
}
2131
2129
_ => panic ! ( ) ,
@@ -2146,16 +2144,16 @@ impl<'a> Generator<'a> {
2146
2144
ast:: TyKind :: Array ( ref t2, ref e2) => format ! (
2147
2145
"{}(*{sig})[{}][{}]" ,
2148
2146
self . ty2name( t2, false ) ,
2149
- self . expr2str( e) ,
2150
- self . expr2str( e2)
2147
+ Self :: expr2str( e) ,
2148
+ Self :: expr2str( e2)
2151
2149
) ,
2152
- _ => format ! ( "{}(*{sig})[{}]" , self . ty2name( t, false ) , self . expr2str( e) ) ,
2150
+ _ => format ! ( "{}(*{sig})[{}]" , self . ty2name( t, false ) , Self :: expr2str( e) ) ,
2153
2151
} ,
2154
2152
_ => format ! ( "{}* {sig}" , self . ty2name( ty, false ) ) ,
2155
2153
}
2156
2154
}
2157
2155
2158
- fn expr2str ( & self , e : & ast:: Expr ) -> String {
2156
+ fn expr2str ( e : & ast:: Expr ) -> String {
2159
2157
match e. node {
2160
2158
ast:: ExprKind :: Lit ( ref l) => match l. node {
2161
2159
ast:: LitKind :: Int ( a, _) => a. to_string ( ) ,
@@ -2164,10 +2162,10 @@ impl<'a> Generator<'a> {
2164
2162
ast:: ExprKind :: Path ( _, ref path) => {
2165
2163
path. segments . last ( ) . unwrap ( ) . identifier . to_string ( )
2166
2164
}
2167
- ast:: ExprKind :: Cast ( ref e, _) => self . expr2str ( e) ,
2165
+ ast:: ExprKind :: Cast ( ref e, _) => Self :: expr2str ( e) ,
2168
2166
ast:: ExprKind :: Binary ( ref op, ref e1, ref e2) => {
2169
- let e1 = self . expr2str ( e1) ;
2170
- let e2 = self . expr2str ( e2) ;
2167
+ let e1 = Self :: expr2str ( e1) ;
2168
+ let e2 = Self :: expr2str ( e2) ;
2171
2169
match op. node {
2172
2170
ast:: BinOpKind :: Add => format ! ( "{e1} + {e2}" ) ,
2173
2171
ast:: BinOpKind :: Sub => format ! ( "{e1} - {e2}" ) ,
@@ -2246,7 +2244,7 @@ impl<'a> Generator<'a> {
2246
2244
}
2247
2245
}
2248
2246
2249
- impl < ' a , ' v > Visitor < ' v > for Generator < ' a > {
2247
+ impl < ' v > Visitor < ' v > for Generator < ' _ > {
2250
2248
fn visit_item ( & mut self , i : & ' v ast:: Item ) {
2251
2249
let prev_abi = self . abi ;
2252
2250
let public = i. vis == ast:: Visibility :: Public ;
@@ -2299,10 +2297,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
2299
2297
self . assert_no_generics ( i. ident , generics) ;
2300
2298
for arg in & decl. inputs {
2301
2299
if let ast:: TyKind :: Array ( _, _) = arg. ty . node {
2302
- panic ! (
2303
- "Foreign Function decl `{}` uses array in C FFI" ,
2304
- i. ident
2305
- ) ;
2300
+ panic ! ( "Foreign Function decl `{}` uses array in C FFI" , i. ident) ;
2306
2301
}
2307
2302
}
2308
2303
@@ -2314,8 +2309,8 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
2314
2309
. unwrap ( ) ;
2315
2310
}
2316
2311
ast:: ForeignItemKind :: Static ( ref ty, mutbl) => {
2317
- let rust_ty = self . ty2name ( & ty, true ) ;
2318
- let c_ty = self . ty2name ( & ty, false ) ;
2312
+ let rust_ty = self . ty2name ( ty, true ) ;
2313
+ let c_ty = self . ty2name ( ty, false ) ;
2319
2314
let c_name = attr:: first_attr_value_str_by_name ( & i. attrs , "link_name" )
2320
2315
. map ( |i| i. to_string ( ) ) ;
2321
2316
self . test_extern_static ( & i. ident . to_string ( ) , c_name, & rust_ty, & c_ty, mutbl)
@@ -2354,7 +2349,7 @@ struct MyResolver<'a> {
2354
2349
map : HashMap < Name , Rc < SyntaxExtension > > ,
2355
2350
}
2356
2351
2357
- impl < ' a > Resolver for MyResolver < ' a > {
2352
+ impl Resolver for MyResolver < ' _ > {
2358
2353
fn next_node_id ( & mut self ) -> ast:: NodeId {
2359
2354
self . id += 1 ;
2360
2355
ast:: NodeId :: new ( self . id )
@@ -2461,7 +2456,7 @@ struct MyVisitor<'b> {
2461
2456
map : & ' b mut HashMap < Name , Rc < SyntaxExtension > > ,
2462
2457
}
2463
2458
2464
- impl < ' a , ' b > Visitor < ' a > for MyVisitor < ' b > {
2459
+ impl < ' a > Visitor < ' a > for MyVisitor < ' _ > {
2465
2460
fn visit_item ( & mut self , item : & ' a ast:: Item ) {
2466
2461
if let ast:: ItemKind :: MacroDef ( ..) = item. node {
2467
2462
self . map . insert (
0 commit comments