@@ -322,6 +322,24 @@ impl Config {
322
322
}
323
323
}
324
324
}
325
+
326
+ /// When using nightly options on stable channel decide whether to abort or
327
+ /// log out warnings to the user.
328
+ pub fn abort_or_warn_on_unstable_options ( & self ) -> Option < HandleUnstableOptions > {
329
+ if !self . using_unstable_options_on_stable_channel ( ) {
330
+ return None ;
331
+ }
332
+
333
+ if self . abort_on_unrecognised_options ( ) {
334
+ Some ( HandleUnstableOptions :: Abort (
335
+ self . unstable_options_abort_message ( ) . unwrap ( ) ,
336
+ ) )
337
+ } else {
338
+ Some ( HandleUnstableOptions :: Warn (
339
+ self . unstable_options_warning_message ( ) . unwrap ( ) ,
340
+ ) )
341
+ }
342
+ }
325
343
}
326
344
327
345
/// Loads a config by checking the client-supplied options and if appropriate, the
@@ -402,6 +420,29 @@ fn config_path(options: &dyn CliOptions) -> Result<Option<PathBuf>, Error> {
402
420
}
403
421
}
404
422
423
+ #[ macro_export]
424
+ macro_rules! abort_or_warn_on_unstable_options {
425
+ ( $config: expr) => {
426
+ match $config. abort_or_warn_on_unstable_options( ) {
427
+ Some ( $crate:: HandleUnstableOptions :: Abort ( message) ) => {
428
+ eprint!( "{}" , message) ;
429
+ return Ok ( 1 ) ;
430
+ }
431
+ Some ( $crate:: HandleUnstableOptions :: Warn ( message) ) => {
432
+ eprint!( "{}" , message) ;
433
+ }
434
+ None => { }
435
+ }
436
+ } ;
437
+ }
438
+
439
+ #[ allow( unreachable_pub) ]
440
+ pub use abort_or_warn_on_unstable_options;
441
+ pub enum HandleUnstableOptions {
442
+ Abort ( String ) ,
443
+ Warn ( String ) ,
444
+ }
445
+
405
446
#[ cfg( test) ]
406
447
mod test {
407
448
use super :: * ;
@@ -647,6 +688,68 @@ Set `abort_on_unrecognised_options = false` to convert this error into a warning
647
688
assert ! ( config. unstable_options_abort_message( ) . is_none( ) )
648
689
}
649
690
691
+ #[ test]
692
+ fn test_on_stable_handle_unstable_options_by_issuing_a_warning ( ) {
693
+ if crate :: is_nightly_channel!( ) {
694
+ // This test requires non-nightly
695
+ return ;
696
+ }
697
+ let toml = r#"
698
+ reorder_impl_items = true
699
+ abort_on_unrecognised_options = false
700
+ "# ;
701
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
702
+ assert ! ( matches!(
703
+ config. abort_or_warn_on_unstable_options( ) ,
704
+ Some ( HandleUnstableOptions :: Warn ( _) )
705
+ ) )
706
+ }
707
+
708
+ #[ test]
709
+ fn test_on_stable_handle_unstable_options_by_aborting ( ) {
710
+ if crate :: is_nightly_channel!( ) {
711
+ // This test requires non-nightly
712
+ return ;
713
+ }
714
+ let toml = r#"
715
+ reorder_impl_items = true
716
+ abort_on_unrecognised_options = true
717
+ "# ;
718
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
719
+ assert ! ( matches!(
720
+ config. abort_or_warn_on_unstable_options( ) ,
721
+ Some ( HandleUnstableOptions :: Abort ( _) )
722
+ ) )
723
+ }
724
+
725
+ #[ test]
726
+ fn test_on_stable_no_need_to_handle_unstable_options_since_non_are_used ( ) {
727
+ if crate :: is_nightly_channel!( ) {
728
+ // This test requires non-nightly
729
+ return ;
730
+ }
731
+ use self :: * ;
732
+ let toml = r#"
733
+ array_width = 50
734
+ "# ;
735
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
736
+ assert ! ( matches!( config. abort_or_warn_on_unstable_options( ) , None ) )
737
+ }
738
+
739
+ #[ test]
740
+ fn test_on_unstable_no_need_to_warn_or_abort_when_usinig_unstable_options ( ) {
741
+ if !crate :: is_nightly_channel!( ) {
742
+ // This test requires nightly
743
+ return ;
744
+ }
745
+ use self :: * ;
746
+ let toml = r#"
747
+ array_width = 50
748
+ "# ;
749
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
750
+ assert ! ( matches!( config. abort_or_warn_on_unstable_options( ) , None ) )
751
+ }
752
+
650
753
#[ test]
651
754
fn test_dump_default_config ( ) {
652
755
let default_config = format ! (
0 commit comments