@@ -44,6 +44,7 @@ pub fn get_cargo_metadata() -> &'static CargoMetadata {
44
44
}
45
45
46
46
/// Returns the cargo workspace for the manifest
47
+ #[ must_use]
47
48
pub fn get_cargo_workspace ( ) -> & ' static std:: path:: Path {
48
49
& get_cargo_metadata ( ) . workspace_root
49
50
}
@@ -129,11 +130,11 @@ impl TestOpts {
129
130
} )
130
131
// Specify chip - note: may match multiple
131
132
. filter ( |t| {
132
- if !self . chip . is_empty ( ) {
133
- self . chip . iter ( ) . any ( |c| WildMatch :: new ( c) . matches ( & t. chip ) )
134
- } else {
133
+ if self . chip . is_empty ( ) {
135
134
// Don't run failable tests unless wanted
136
135
self . bad_tests || t. should_pass
136
+ } else {
137
+ self . chip . iter ( ) . any ( |c| WildMatch :: new ( c) . matches ( & t. chip ) )
137
138
}
138
139
} )
139
140
. collect :: < Vec < _ > > ( ) ;
@@ -190,10 +191,10 @@ impl TestOpts {
190
191
read_file ( stderr, & mut buf) ;
191
192
buf
192
193
}
193
- _ => "" . into ( ) ,
194
+ _ => String :: new ( ) ,
194
195
}
195
196
} else {
196
- "" . into ( )
197
+ String :: new ( )
197
198
} ;
198
199
tracing:: error!(
199
200
"Failed: {} - {} seconds. {:?}{}" ,
@@ -253,38 +254,39 @@ pub struct Opts {
253
254
}
254
255
255
256
impl Opts {
256
- fn use_rustfmt ( & self ) -> bool {
257
+ const fn use_rustfmt ( & self ) -> bool {
257
258
match self . subcommand {
258
- Subcommand :: Tests ( TestOpts { format, .. } ) => format ,
259
- Subcommand :: Diff ( Diffing { format, .. } ) => format ,
260
- Subcommand :: Ci ( Ci { format, .. } ) => format,
259
+ Subcommand :: Tests ( TestOpts { format, .. } )
260
+ | Subcommand :: Diff ( Diffing { format, .. } )
261
+ | Subcommand :: Ci ( Ci { format, .. } ) => format,
261
262
}
262
263
}
263
264
264
- fn use_form ( & self ) -> bool {
265
+ const fn use_form ( & self ) -> bool {
265
266
match self . subcommand {
266
- Subcommand :: Tests ( TestOpts { form_lib, .. } ) => form_lib ,
267
- Subcommand :: Diff ( Diffing {
267
+ Subcommand :: Tests ( TestOpts { form_lib, .. } )
268
+ | Subcommand :: Diff ( Diffing {
268
269
form_split : form_lib,
269
270
..
270
- } ) => form_lib ,
271
- Subcommand :: Ci ( Ci { form_lib, .. } ) => form_lib,
271
+ } )
272
+ | Subcommand :: Ci ( Ci { form_lib, .. } ) => form_lib,
272
273
}
273
274
}
274
275
}
275
276
276
277
/// Hack to use ci/tests.yml as default value when running as `cargo run`
277
278
fn default_test_cases ( ) -> std:: ffi:: OsString {
278
- std:: env:: var_os ( "CARGO_MANIFEST_DIR" )
279
- . map ( |mut e| {
279
+ std:: env:: var_os ( "CARGO_MANIFEST_DIR" ) . map_or_else (
280
+ || std:: ffi:: OsString :: from ( "tests.yml" . to_owned ( ) ) ,
281
+ |mut e| {
280
282
e. extend ( [ std:: ffi:: OsStr :: new ( "/tests.yml" ) ] ) ;
281
283
std:: path:: PathBuf :: from ( e)
282
284
. strip_prefix ( std:: env:: current_dir ( ) . unwrap ( ) )
283
285
. unwrap ( )
284
286
. to_owned ( )
285
287
. into_os_string ( )
286
- } )
287
- . unwrap_or_else ( || std :: ffi :: OsString :: from ( "tests.yml" . to_owned ( ) ) )
288
+ } ,
289
+ )
288
290
}
289
291
290
292
fn default_svd2rust ( ) -> std:: ffi:: OsString {
@@ -326,9 +328,7 @@ fn validate_tests(tests: &[tests::TestCase]) {
326
328
}
327
329
}
328
330
329
- if fail {
330
- panic ! ( "Tests failed validation" ) ;
331
- }
331
+ assert ! ( !fail, "Tests failed validation" ) ;
332
332
}
333
333
334
334
fn read_file ( path : & PathBuf , buf : & mut String ) {
@@ -376,9 +376,10 @@ fn main() -> Result<(), anyhow::Error> {
376
376
}
377
377
( & None , true ) => {
378
378
// FIXME: Use Option::filter instead when stable, rust-lang/rust#45860
379
- if !default_rustfmt. iter ( ) . any ( |p| p. is_file ( ) ) {
380
- panic ! ( "No rustfmt found" ) ;
381
- }
379
+ assert ! (
380
+ default_rustfmt. iter( ) . any( |p| p. is_file( ) ) ,
381
+ "No rustfmt found"
382
+ ) ;
382
383
if let Some ( default_rustfmt) = default_rustfmt {
383
384
RUSTFMT . get_or_init ( || default_rustfmt) ;
384
385
}
0 commit comments