@@ -40,12 +40,10 @@ impl<'b, T: Write + 'b> Session<'b, T> {
4040 rustc_span:: create_session_if_not_set_then ( self . config . edition ( ) . into ( ) , |_| {
4141 if self . config . disable_all_formatting ( ) {
4242 // When the input is from stdin, echo back the input.
43- if let Input :: Text ( ref buf) = input {
44- if let Err ( e) = io:: stdout ( ) . write_all ( buf. as_bytes ( ) ) {
45- return Err ( From :: from ( e) ) ;
46- }
47- }
48- return Ok ( FormatReport :: new ( ) ) ;
43+ return match input {
44+ Input :: Text ( ref buf) => echo_back_stdin ( buf) ,
45+ _ => Ok ( FormatReport :: new ( ) ) ,
46+ } ;
4947 }
5048
5149 let config = & self . config . clone ( ) ;
@@ -94,6 +92,13 @@ fn should_skip_module<T: FormatHandler>(
9492 false
9593}
9694
95+ fn echo_back_stdin ( input : & str ) -> Result < FormatReport , ErrorKind > {
96+ if let Err ( e) = io:: stdout ( ) . write_all ( input. as_bytes ( ) ) {
97+ return Err ( From :: from ( e) ) ;
98+ }
99+ Ok ( FormatReport :: new ( ) )
100+ }
101+
97102// Format an entire crate (or subset of the module tree).
98103fn format_project < T : FormatHandler > (
99104 input : Input ,
@@ -136,7 +141,8 @@ fn format_project<T: FormatHandler>(
136141 . visit_crate ( & krate) ?
137142 . into_iter ( )
138143 . filter ( |( path, module) | {
139- !should_skip_module ( config, & context, input_is_stdin, & main_file, path, module)
144+ input_is_stdin
145+ || !should_skip_module ( config, & context, input_is_stdin, & main_file, path, module)
140146 } )
141147 . collect :: < Vec < _ > > ( ) ;
142148
@@ -146,6 +152,14 @@ fn format_project<T: FormatHandler>(
146152 context. parse_session . set_silent_emitter ( ) ;
147153
148154 for ( path, module) in files {
155+ if input_is_stdin && contains_skip ( module. attrs ( ) ) {
156+ return echo_back_stdin (
157+ context
158+ . parse_session
159+ . snippet_provider ( module. span )
160+ . entire_snippet ( ) ,
161+ ) ;
162+ }
149163 should_emit_verbose ( input_is_stdin, config, || println ! ( "Formatting {}" , path) ) ;
150164 context. format_file ( path, & module, is_macro_def) ?;
151165 }
0 commit comments