@@ -664,26 +664,36 @@ impl ConfigCodeBlock {
664
664
665
665
fn get_block_config ( & self ) -> Config {
666
666
let mut config = Config :: default ( ) ;
667
- config. override_value (
668
- self . config_name . as_ref ( ) . unwrap ( ) ,
669
- self . config_value . as_ref ( ) . unwrap ( ) ,
670
- ) ;
667
+ if self . config_value . is_some ( ) && self . config_value . is_some ( ) {
668
+ config. override_value (
669
+ self . config_name . as_ref ( ) . unwrap ( ) ,
670
+ self . config_value . as_ref ( ) . unwrap ( ) ,
671
+ ) ;
672
+ }
671
673
config
672
674
}
673
675
674
676
fn code_block_valid ( & self ) -> bool {
675
677
// We never expect to not have a code block.
676
678
assert ! ( self . code_block. is_some( ) && self . code_block_start. is_some( ) ) ;
677
679
678
- if self . config_name . is_none ( ) {
680
+ // See if code block begins with #![rustfmt_skip].
681
+ let fmt_skip = self . code_block
682
+ . as_ref ( )
683
+ . unwrap ( )
684
+ . split ( "\n " )
685
+ . nth ( 0 )
686
+ . unwrap_or ( "" ) == "#![rustfmt_skip]" ;
687
+
688
+ if self . config_name . is_none ( ) && !fmt_skip {
679
689
write_message ( & format ! (
680
690
"No configuration name for {}:{}" ,
681
691
CONFIGURATIONS_FILE_NAME ,
682
692
self . code_block_start. unwrap( )
683
693
) ) ;
684
694
return false ;
685
695
}
686
- if self . config_value . is_none ( ) {
696
+ if self . config_value . is_none ( ) && !fmt_skip {
687
697
write_message ( & format ! (
688
698
"No configuration value for {}:{}" ,
689
699
CONFIGURATIONS_FILE_NAME ,
@@ -752,7 +762,7 @@ impl ConfigCodeBlock {
752
762
// - Rust code blocks are identifed by lines beginning with "```rust".
753
763
// - One explicit configuration setting is supported per code block.
754
764
// - Rust code blocks with no configuration setting are illegal and cause an
755
- // assertion failure.
765
+ // assertion failure, unless the snippet begins with #![rustfmt_skip] .
756
766
// - Configuration names in Configurations.md must be in the form of
757
767
// "## `NAME`".
758
768
// - Configuration values in Configurations.md must be in the form of
0 commit comments