@@ -40,12 +40,10 @@ impl<'b, T: Write + 'b> Session<'b, T> {
40
40
rustc_span:: create_session_if_not_set_then ( self . config . edition ( ) . into ( ) , |_| {
41
41
if self . config . disable_all_formatting ( ) {
42
42
// 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
+ } ;
49
47
}
50
48
51
49
let config = & self . config . clone ( ) ;
@@ -94,6 +92,13 @@ fn should_skip_module<T: FormatHandler>(
94
92
false
95
93
}
96
94
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
+
97
102
// Format an entire crate (or subset of the module tree).
98
103
fn format_project < T : FormatHandler > (
99
104
input : Input ,
@@ -136,7 +141,8 @@ fn format_project<T: FormatHandler>(
136
141
. visit_crate ( & krate) ?
137
142
. into_iter ( )
138
143
. 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)
140
146
} )
141
147
. collect :: < Vec < _ > > ( ) ;
142
148
@@ -146,6 +152,14 @@ fn format_project<T: FormatHandler>(
146
152
context. parse_session . set_silent_emitter ( ) ;
147
153
148
154
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
+ }
149
163
should_emit_verbose ( input_is_stdin, config, || println ! ( "Formatting {}" , path) ) ;
150
164
context. format_file ( path, & module, is_macro_def) ?;
151
165
}
0 commit comments