@@ -18,15 +18,17 @@ pub struct Rustflags {
18
18
19
19
impl Rustflags {
20
20
pub fn hash < H > ( & self , hasher : & mut H )
21
- where H : Hasher
21
+ where
22
+ H : Hasher ,
22
23
{
23
24
let mut flags = self . flags . iter ( ) ;
24
25
25
26
while let Some ( flag) = flags. next ( ) {
26
27
if flag == "-C" {
27
28
if let Some ( next) = flags. next ( ) {
28
29
if next. starts_with ( "link-arg=" ) ||
29
- next. starts_with ( "link-args=" ) {
30
+ next. starts_with ( "link-args=" )
31
+ {
30
32
// don't hash linker arguments
31
33
} else {
32
34
flag. hash ( hasher) ;
@@ -74,35 +76,41 @@ impl Rustdocflags {
74
76
}
75
77
}
76
78
77
- pub fn rustdocflags ( config : Option < & Config > ,
78
- target : & str )
79
- -> Result < Rustdocflags > {
79
+ pub fn rustdocflags (
80
+ config : Option < & Config > ,
81
+ target : & str ,
82
+ ) -> Result < Rustdocflags > {
80
83
flags ( config, target, "rustdocflags" ) . map ( |fs| Rustdocflags { flags : fs } )
81
84
}
82
85
83
86
84
87
/// Returns the flags for `tool` (e.g. rustflags)
85
88
///
86
89
/// This looks into the environment and into `.cargo/config`
87
- fn flags ( config : Option < & Config > ,
88
- target : & str ,
89
- tool : & str )
90
- -> Result < Vec < String > > {
90
+ fn flags (
91
+ config : Option < & Config > ,
92
+ target : & str ,
93
+ tool : & str ,
94
+ ) -> Result < Vec < String > > {
91
95
if let Some ( t) = env:: var_os ( tool. to_uppercase ( ) ) {
92
- return Ok ( t. to_string_lossy ( )
93
- . split_whitespace ( )
94
- . map ( |w| w. to_owned ( ) )
95
- . collect ( ) ) ;
96
+ return Ok (
97
+ t. to_string_lossy ( )
98
+ . split_whitespace ( )
99
+ . map ( |w| w. to_owned ( ) )
100
+ . collect ( ) ,
101
+ ) ;
96
102
}
97
103
98
104
if let Some ( config) = config. as_ref ( ) {
99
105
let mut build = false ;
100
- if let Some ( array) = config. table
106
+ if let Some ( array) = config
107
+ . table
101
108
. lookup ( & format ! ( "target.{}.{}" , target, tool) )
102
109
. or_else ( || {
103
110
build = true ;
104
111
config. table . lookup ( & format ! ( "build.{}" , tool) )
105
- } ) {
112
+ } )
113
+ {
106
114
let mut flags = vec ! [ ] ;
107
115
108
116
let mut error = false ;
@@ -121,14 +129,18 @@ fn flags(config: Option<&Config>,
121
129
122
130
if error {
123
131
if build {
124
- Err ( format ! ( ".cargo/config: build.{} must be an array \
132
+ Err ( format ! (
133
+ ".cargo/config: build.{} must be an array \
125
134
of strings",
126
- tool) ) ?
135
+ tool
136
+ ) ) ?
127
137
} else {
128
- Err ( format ! ( ".cargo/config: target.{}.{} must be an \
138
+ Err ( format ! (
139
+ ".cargo/config: target.{}.{} must be an \
129
140
array of strings",
130
- target,
131
- tool) ) ?
141
+ target,
142
+ tool
143
+ ) ) ?
132
144
}
133
145
} else {
134
146
Ok ( flags)
@@ -142,7 +154,9 @@ fn flags(config: Option<&Config>,
142
154
}
143
155
144
156
pub fn run ( args : & Args , verbose : bool ) -> Result < ExitStatus > {
145
- Command :: new ( "cargo" ) . args ( args. all ( ) ) . run_and_get_status ( verbose)
157
+ Command :: new ( "cargo" ) . args ( args. all ( ) ) . run_and_get_status (
158
+ verbose,
159
+ )
146
160
}
147
161
148
162
pub struct Config {
@@ -152,22 +166,26 @@ pub struct Config {
152
166
impl Config {
153
167
pub fn target ( & self ) -> Result < Option < & str > > {
154
168
if let Some ( v) = self . table . lookup ( "build.target" ) {
155
- Ok ( Some ( v. as_str ( )
156
- . ok_or_else ( || {
157
- format ! ( ".cargo/config: build.target must be a string" )
158
- } ) ?) )
169
+ Ok ( Some (
170
+ v. as_str ( ) . ok_or_else (
171
+ || format ! ( ".cargo/config: build.target must be a string" ) ,
172
+ ) ?,
173
+ ) )
159
174
} else {
160
175
Ok ( None )
161
176
}
162
177
}
163
178
}
164
179
165
180
pub fn config ( ) -> Result < Option < Config > > {
166
- let cd =
167
- env:: current_dir ( ) . chain_err ( || "couldn't get the current directory" ) ?;
181
+ let cd = env:: current_dir ( ) . chain_err (
182
+ || "couldn't get the current directory" ,
183
+ ) ?;
168
184
169
185
if let Some ( p) = util:: search ( & cd, ".cargo/config" ) {
170
- Ok ( Some ( Config { table : util:: parse ( & p. join ( ".cargo/config" ) ) ? } ) )
186
+ Ok ( Some (
187
+ Config { table : util:: parse ( & p. join ( ".cargo/config" ) ) ? } ,
188
+ ) )
171
189
} else {
172
190
Ok ( None )
173
191
}
@@ -179,7 +197,8 @@ pub struct Profile<'t> {
179
197
180
198
impl < ' t > Profile < ' t > {
181
199
pub fn hash < H > ( & self , hasher : & mut H )
182
- where H : Hasher
200
+ where
201
+ H : Hasher ,
183
202
{
184
203
let mut v = self . table . clone ( ) ;
185
204
@@ -218,7 +237,9 @@ pub struct Toml {
218
237
impl Toml {
219
238
/// `profile.release` part of `Cargo.toml`
220
239
pub fn profile ( & self ) -> Option < Profile > {
221
- self . table . lookup ( "profile.release" ) . map ( |t| Profile { table : t } )
240
+ self . table . lookup ( "profile.release" ) . map (
241
+ |t| Profile { table : t } ,
242
+ )
222
243
}
223
244
}
224
245
@@ -237,10 +258,13 @@ impl Root {
237
258
}
238
259
239
260
pub fn root ( ) -> Result < Option < Root > > {
240
- let cd =
241
- env:: current_dir ( ) . chain_err ( || "couldn't get the current directory" ) ?;
261
+ let cd = env:: current_dir ( ) . chain_err (
262
+ || "couldn't get the current directory" ,
263
+ ) ?;
242
264
243
- Ok ( util:: search ( & cd, "Cargo.toml" ) . map ( |p| Root { path : p. to_owned ( ) } ) )
265
+ Ok (
266
+ util:: search ( & cd, "Cargo.toml" ) . map ( |p| Root { path : p. to_owned ( ) } ) ,
267
+ )
244
268
}
245
269
246
270
#[ derive( Clone , Copy , PartialEq ) ]
0 commit comments