2121//! - libunwind may have platform-specific code.
2222//! - other crates in the std facade may not.
2323//! - std may have platform-specific code in the following places:
24- //! - `sys/unix/`
25- //! - `sys/windows/`
24+ //! - `sys/`
2625//! - `os/`
2726//!
2827//! `std/sys_common` should _not_ contain platform-specific code.
@@ -36,34 +35,30 @@ use std::path::Path;
3635
3736// Paths that may contain platform-specific code.
3837const EXCEPTION_PATHS : & [ & str ] = & [
39- // std crates
4038 "library/panic_abort" ,
4139 "library/panic_unwind" ,
4240 "library/unwind" ,
43- "library/std/src/sys/" , // Platform-specific code for std lives here.
44- // This has the trailing slash so that sys_common is not excepted.
45- "library/std/src/os" , // Platform-specific public interfaces
46- "library/rtstartup" , // Not sure what to do about this. magic stuff for mingw
47- // Integration test for platform-specific run-time feature detection:
48- "library/std/tests/run-time-detect.rs" ,
49- "library/std/src/net/test.rs" ,
50- "library/std/src/net/addr" ,
51- "library/std/src/net/udp" ,
52- "library/std/src/sys_common/remutex.rs" ,
53- "library/std/src/sync/mutex.rs" ,
54- "library/std/src/sync/rwlock.rs" ,
55- "library/term" , // Not sure how to make this crate portable, but test crate needs it.
56- "library/test" , // Probably should defer to unstable `std::sys` APIs.
57- // std testing crates, okay for now at least
58- "library/core/tests" ,
59- "library/alloc/tests/lib.rs" ,
60- "library/alloc/benches/lib.rs" ,
41+ "library/rtstartup" , // Not sure what to do about this. magic stuff for mingw
42+ "library/term" , // Not sure how to make this crate portable, but test crate needs it.
43+ "library/test" , // Probably should defer to unstable `std::sys` APIs.
6144 // The `VaList` implementation must have platform specific code.
6245 // The Windows implementation of a `va_list` is always a character
6346 // pointer regardless of the target architecture. As a result,
6447 // we must use `#[cfg(windows)]` to conditionally compile the
6548 // correct `VaList` structure for windows.
6649 "library/core/src/ffi.rs" ,
50+ "library/std/src/sys/" , // Platform-specific code for std lives here.
51+ "library/std/src/os" , // Platform-specific public interfaces
52+ // Temporary `std` exceptions
53+ // FIXME: platform-specific code should be moved to `sys`
54+ "library/std/src/io/copy.rs" ,
55+ "library/std/src/io/stdio.rs" ,
56+ "library/std/src/f32.rs" ,
57+ "library/std/src/f64.rs" ,
58+ "library/std/src/path.rs" ,
59+ "library/std/src/thread/available_concurrency.rs" ,
60+ "library/std/src/sys_common" , // Should only contain abstractions over platforms
61+ "library/std/src/net/test.rs" , // Utility helpers for tests
6762] ;
6863
6964pub fn check ( path : & Path , bad : & mut bool ) {
@@ -82,6 +77,11 @@ pub fn check(path: &Path, bad: &mut bool) {
8277 return ;
8378 }
8479
80+ // exclude tests and benchmarks as some platforms do not support all tests
81+ if filestr. contains ( "tests" ) || filestr. contains ( "benches" ) {
82+ return ;
83+ }
84+
8585 check_cfgs ( contents, & file, bad, & mut saw_target_arch, & mut saw_cfg_bang) ;
8686 } ) ;
8787
@@ -96,9 +96,6 @@ fn check_cfgs(
9696 saw_target_arch : & mut bool ,
9797 saw_cfg_bang : & mut bool ,
9898) {
99- // For now it's ok to have platform-specific code after 'mod tests'.
100- let mod_tests_idx = find_test_mod ( contents) ;
101- let contents = & contents[ ..mod_tests_idx] ;
10299 // Pull out all `cfg(...)` and `cfg!(...)` strings.
103100 let cfgs = parse_cfgs ( contents) ;
104101
@@ -149,39 +146,22 @@ fn check_cfgs(
149146 continue ;
150147 }
151148
152- err ( idx, cfg) ;
153- }
154- }
155-
156- fn find_test_mod ( contents : & str ) -> usize {
157- if let Some ( mod_tests_idx) = contents. find ( "mod tests" ) {
158- // Also capture a previous line indicating that "mod tests" is cfg'd out.
159- let prev_newline_idx = contents[ ..mod_tests_idx] . rfind ( '\n' ) . unwrap_or ( mod_tests_idx) ;
160- let prev_newline_idx = contents[ ..prev_newline_idx] . rfind ( '\n' ) ;
161- if let Some ( nl) = prev_newline_idx {
162- let prev_line = & contents[ nl + 1 ..mod_tests_idx] ;
163- if prev_line. contains ( "cfg(all(test, not(target_os" )
164- || prev_line. contains ( "cfg(all(test, not(any(target_os" )
165- {
166- nl
167- } else {
168- mod_tests_idx
169- }
170- } else {
171- mod_tests_idx
149+ // exclude tests as some platforms do not support all tests
150+ if cfg. contains ( "test" ) {
151+ continue ;
172152 }
173- } else {
174- contents . len ( )
153+
154+ err ( idx , cfg ) ;
175155 }
176156}
177157
178- fn parse_cfgs < ' a > ( contents : & ' a str ) -> Vec < ( usize , & ' a str ) > {
158+ fn parse_cfgs ( contents : & str ) -> Vec < ( usize , & str ) > {
179159 let candidate_cfgs = contents. match_indices ( "cfg" ) ;
180160 let candidate_cfg_idxs = candidate_cfgs. map ( |( i, _) | i) ;
181161 // This is puling out the indexes of all "cfg" strings
182162 // that appear to be tokens followed by a parenthesis.
183163 let cfgs = candidate_cfg_idxs. filter ( |i| {
184- let pre_idx = i. saturating_sub ( * i ) ;
164+ let pre_idx = i. saturating_sub ( 1 ) ;
185165 let succeeds_non_ident = !contents
186166 . as_bytes ( )
187167 . get ( pre_idx)
0 commit comments