@@ -5,6 +5,7 @@ use std::io::{self, Write};
5
5
use std:: time:: { Duration , Instant } ;
6
6
7
7
use rustc_ast:: ast;
8
+ use rustc_ast:: AstLike ;
8
9
use rustc_span:: Span ;
9
10
10
11
use self :: newline_style:: apply_newline_style;
@@ -15,7 +16,7 @@ use crate::issues::BadIssueSeeker;
15
16
use crate :: modules:: Module ;
16
17
use crate :: syntux:: parser:: { DirectoryOwnership , Parser , ParserError } ;
17
18
use crate :: syntux:: session:: ParseSess ;
18
- use crate :: utils:: count_newlines;
19
+ use crate :: utils:: { contains_skip , count_newlines} ;
19
20
use crate :: visitor:: FmtVisitor ;
20
21
use crate :: { modules, source_file, ErrorKind , FormatReport , Input , Session } ;
21
22
@@ -58,6 +59,32 @@ impl<'b, T: Write + 'b> Session<'b, T> {
58
59
}
59
60
}
60
61
62
+ /// Determine if a module should be skipped. True if the module should be skipped, false otherwise.
63
+ fn should_skip_module < T : FormatHandler > (
64
+ config : & Config ,
65
+ context : & FormatContext < ' _ , T > ,
66
+ input_is_stdin : bool ,
67
+ main_file : & FileName ,
68
+ path : & FileName ,
69
+ module : & Module < ' _ > ,
70
+ ) -> bool {
71
+ if contains_skip ( module. attrs ( ) ) {
72
+ return true ;
73
+ }
74
+
75
+ let source_file = context. parse_session . span_to_file_contents ( module. span ) ;
76
+ let src = source_file. src . as_ref ( ) . expect ( "SourceFile without src" ) ;
77
+
78
+ let should_ignore = ( !input_is_stdin && context. ignore_file ( & path) )
79
+ || ( !config. format_generated_files ( ) && is_generated_file ( src) ) ;
80
+
81
+ if ( config. skip_children ( ) && path != main_file) || should_ignore {
82
+ return true ;
83
+ }
84
+
85
+ false
86
+ }
87
+
61
88
// Format an entire crate (or subset of the module tree).
62
89
fn format_project < T : FormatHandler > (
63
90
input : Input ,
@@ -97,23 +124,19 @@ fn format_project<T: FormatHandler>(
97
124
directory_ownership. unwrap_or ( DirectoryOwnership :: UnownedViaBlock ) ,
98
125
!input_is_stdin && !config. skip_children ( ) ,
99
126
)
100
- . visit_crate ( & krate) ?;
127
+ . visit_crate ( & krate) ?
128
+ . into_iter ( )
129
+ . filter ( |( path, module) | {
130
+ !should_skip_module ( config, & context, input_is_stdin, & main_file, path, module)
131
+ } )
132
+ . collect :: < Vec < _ > > ( ) ;
101
133
102
134
timer = timer. done_parsing ( ) ;
103
135
104
136
// Suppress error output if we have to do any further parsing.
105
137
context. parse_session . set_silent_emitter ( ) ;
106
138
107
139
for ( path, module) in files {
108
- let source_file = context. parse_session . span_to_file_contents ( module. span ) ;
109
- let src = source_file. src . as_ref ( ) . expect ( "SourceFile without src" ) ;
110
-
111
- let should_ignore = ( !input_is_stdin && context. ignore_file ( & path) )
112
- || ( !config. format_generated_files ( ) && is_generated_file ( src) ) ;
113
-
114
- if ( config. skip_children ( ) && path != main_file) || should_ignore {
115
- continue ;
116
- }
117
140
should_emit_verbose ( input_is_stdin, config, || println ! ( "Formatting {}" , path) ) ;
118
141
context. format_file ( path, & module, is_macro_def) ?;
119
142
}
0 commit comments