File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,27 @@ macro_rules! create_config {
190
190
Some ( output)
191
191
}
192
192
193
+ /// Returns a String explaining why rustfmt exited early when using unstable options
194
+ /// on the stable channel
195
+ #[ allow( unreachable_pub) ]
196
+ pub fn unstable_options_abort_message( & self ) -> Option <String > {
197
+ let unstable_options = self . unstable_options_set_on_stable_channel( ) ?;
198
+ let first_line = "Can't set nightly options when using stable rustfmt\n " ;
199
+ let to_warning_message = "\n Set `abort_on_unrecognised_options = false` \
200
+ to convert this error into a warning\n \n ";
201
+ // 40 = buffer we'll use for all options. Most will be less than 40 char long
202
+ let mut output = String :: with_capacity(
203
+ to_warning_message. len( ) + first_line. len( ) + unstable_options. len( ) * 40
204
+ ) ;
205
+ output. push_str( first_line) ;
206
+
207
+ for option in unstable_options {
208
+ output. push_str( & format!( " - `{}`\n " , option) ) ;
209
+ }
210
+ output. push_str( to_warning_message) ;
211
+ Some ( output)
212
+ }
213
+
193
214
fn fill_from_parsed_config( mut self , parsed: PartialConfig , dir: & Path ) -> Config {
194
215
let mut unstable_options = vec![ ] ;
195
216
$(
Original file line number Diff line number Diff line change @@ -611,6 +611,42 @@ Set `abort_on_unrecognised_options = true` to convert this warning into an error
611
611
assert ! ( config. unstable_options_warning_message( ) . is_none( ) )
612
612
}
613
613
614
+ #[ test]
615
+ fn test_abort_message_when_using_unstable_options_on_stable_channel ( ) {
616
+ if crate :: is_nightly_channel!( ) {
617
+ // This test requires non-nightly
618
+ return ;
619
+ }
620
+ let toml = r#"
621
+ reorder_impl_items = true
622
+ "# ;
623
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
624
+ let abort_message = "\
625
+ Can't set nightly options when using stable rustfmt
626
+ - `reorder_impl_items = true`
627
+
628
+ Set `abort_on_unrecognised_options = false` to convert this error into a warning
629
+
630
+ " ;
631
+ assert_eq ! (
632
+ abort_message,
633
+ config. unstable_options_abort_message( ) . unwrap( )
634
+ )
635
+ }
636
+
637
+ #[ test]
638
+ fn test_no_abort_message_when_using_unstable_options_on_nightly ( ) {
639
+ if !crate :: is_nightly_channel!( ) {
640
+ // This test requires nightly
641
+ return ;
642
+ }
643
+ let toml = r#"
644
+ reorder_impl_items = true
645
+ "# ;
646
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
647
+ assert ! ( config. unstable_options_abort_message( ) . is_none( ) )
648
+ }
649
+
614
650
#[ test]
615
651
fn test_dump_default_config ( ) {
616
652
let default_config = format ! (
You can’t perform that action at this time.
0 commit comments