@@ -44,6 +44,7 @@ pub fn get_cargo_metadata() -> &'static CargoMetadata {
4444}
4545
4646/// Returns the cargo workspace for the manifest
47+ #[ must_use]
4748pub fn get_cargo_workspace ( ) -> & ' static std:: path:: Path {
4849 & get_cargo_metadata ( ) . workspace_root
4950}
@@ -129,11 +130,11 @@ impl TestOpts {
129130 } )
130131 // Specify chip - note: may match multiple
131132 . 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 ( ) {
135134 // Don't run failable tests unless wanted
136135 self . bad_tests || t. should_pass
136+ } else {
137+ self . chip . iter ( ) . any ( |c| WildMatch :: new ( c) . matches ( & t. chip ) )
137138 }
138139 } )
139140 . collect :: < Vec < _ > > ( ) ;
@@ -190,10 +191,10 @@ impl TestOpts {
190191 read_file ( stderr, & mut buf) ;
191192 buf
192193 }
193- _ => "" . into ( ) ,
194+ _ => String :: new ( ) ,
194195 }
195196 } else {
196- "" . into ( )
197+ String :: new ( )
197198 } ;
198199 tracing:: error!(
199200 "Failed: {} - {} seconds. {:?}{}" ,
@@ -253,38 +254,39 @@ pub struct Opts {
253254}
254255
255256impl Opts {
256- fn use_rustfmt ( & self ) -> bool {
257+ const fn use_rustfmt ( & self ) -> bool {
257258 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,
261262 }
262263 }
263264
264- fn use_form ( & self ) -> bool {
265+ const fn use_form ( & self ) -> bool {
265266 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 {
268269 form_split : form_lib,
269270 ..
270- } ) => form_lib ,
271- Subcommand :: Ci ( Ci { form_lib, .. } ) => form_lib,
271+ } )
272+ | Subcommand :: Ci ( Ci { form_lib, .. } ) => form_lib,
272273 }
273274 }
274275}
275276
276277/// Hack to use ci/tests.yml as default value when running as `cargo run`
277278fn 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| {
280282 e. extend ( [ std:: ffi:: OsStr :: new ( "/tests.yml" ) ] ) ;
281283 std:: path:: PathBuf :: from ( e)
282284 . strip_prefix ( std:: env:: current_dir ( ) . unwrap ( ) )
283285 . unwrap ( )
284286 . to_owned ( )
285287 . into_os_string ( )
286- } )
287- . unwrap_or_else ( || std :: ffi :: OsString :: from ( "tests.yml" . to_owned ( ) ) )
288+ } ,
289+ )
288290}
289291
290292fn default_svd2rust ( ) -> std:: ffi:: OsString {
@@ -326,9 +328,7 @@ fn validate_tests(tests: &[tests::TestCase]) {
326328 }
327329 }
328330
329- if fail {
330- panic ! ( "Tests failed validation" ) ;
331- }
331+ assert ! ( !fail, "Tests failed validation" ) ;
332332}
333333
334334fn read_file ( path : & PathBuf , buf : & mut String ) {
@@ -376,9 +376,10 @@ fn main() -> Result<(), anyhow::Error> {
376376 }
377377 ( & None , true ) => {
378378 // 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+ ) ;
382383 if let Some ( default_rustfmt) = default_rustfmt {
383384 RUSTFMT . get_or_init ( || default_rustfmt) ;
384385 }
0 commit comments