1- use core:: hint:: black_box;
2-
3- use super :: * ;
4- use crate :: collections:: { BTreeSet , HashSet } ;
5- use crate :: hash:: DefaultHasher ;
6- use crate :: mem:: MaybeUninit ;
7- use crate :: ptr;
1+ #![ feature(
2+ clone_to_uninit,
3+ path_add_extension,
4+ path_file_prefix,
5+ maybe_uninit_slice,
6+ os_string_pathbuf_leak
7+ ) ]
8+
9+ use std:: clone:: CloneToUninit ;
10+ use std:: ffi:: OsStr ;
11+ use std:: hash:: { DefaultHasher , Hash , Hasher } ;
12+ use std:: mem:: MaybeUninit ;
13+ use std:: path:: * ;
14+ use std:: ptr;
15+ use std:: rc:: Rc ;
16+ use std:: sync:: Arc ;
817
918#[ allow( unknown_lints, unused_macro_rules) ]
1019macro_rules! t (
@@ -110,7 +119,7 @@ macro_rules! t (
110119
111120#[ test]
112121fn into ( ) {
113- use crate :: borrow:: Cow ;
122+ use std :: borrow:: Cow ;
114123
115124 let static_path = Path :: new ( "/home/foo" ) ;
116125 let static_cow_path: Cow < ' static , Path > = static_path. into ( ) ;
@@ -1525,7 +1534,7 @@ pub fn test_with_added_extension() {
15251534
15261535#[ test]
15271536fn test_eq_receivers ( ) {
1528- use crate :: borrow:: Cow ;
1537+ use std :: borrow:: Cow ;
15291538
15301539 let borrowed: & Path = Path :: new ( "foo/bar" ) ;
15311540 let mut owned: PathBuf = PathBuf :: new ( ) ;
@@ -1550,7 +1559,7 @@ fn test_eq_receivers() {
15501559
15511560#[ test]
15521561pub fn test_compare ( ) {
1553- use crate :: hash:: { DefaultHasher , Hash , Hasher } ;
1562+ use std :: hash:: { DefaultHasher , Hash , Hasher } ;
15541563
15551564 fn hash < T : Hash > ( t : T ) -> u64 {
15561565 let mut s = DefaultHasher :: new ( ) ;
@@ -1867,12 +1876,12 @@ fn test_ord() {
18671876#[ test]
18681877#[ cfg( any( unix, target_os = "wasi" ) ) ]
18691878fn test_unix_absolute ( ) {
1870- use crate :: path:: absolute;
1879+ use std :: path:: absolute;
18711880
18721881 assert ! ( absolute( "" ) . is_err( ) ) ;
18731882
18741883 let relative = "a/b" ;
1875- let mut expected = crate :: env:: current_dir ( ) . unwrap ( ) ;
1884+ let mut expected = std :: env:: current_dir ( ) . unwrap ( ) ;
18761885 expected. push ( relative) ;
18771886 assert_eq ! ( absolute( relative) . unwrap( ) . as_os_str( ) , expected. as_os_str( ) ) ;
18781887
@@ -1888,20 +1897,20 @@ fn test_unix_absolute() {
18881897 ) ;
18891898
18901899 // Test leading `.` and `..` components
1891- let curdir = crate :: env:: current_dir ( ) . unwrap ( ) ;
1900+ let curdir = std :: env:: current_dir ( ) . unwrap ( ) ;
18921901 assert_eq ! ( absolute( "./a" ) . unwrap( ) . as_os_str( ) , curdir. join( "a" ) . as_os_str( ) ) ;
18931902 assert_eq ! ( absolute( "../a" ) . unwrap( ) . as_os_str( ) , curdir. join( "../a" ) . as_os_str( ) ) ; // return /pwd/../a
18941903}
18951904
18961905#[ test]
18971906#[ cfg( windows) ]
18981907fn test_windows_absolute ( ) {
1899- use crate :: path:: absolute;
1908+ use std :: path:: absolute;
19001909 // An empty path is an error.
19011910 assert ! ( absolute( "" ) . is_err( ) ) ;
19021911
19031912 let relative = r"a\b" ;
1904- let mut expected = crate :: env:: current_dir ( ) . unwrap ( ) ;
1913+ let mut expected = std :: env:: current_dir ( ) . unwrap ( ) ;
19051914 expected. push ( relative) ;
19061915 assert_eq ! ( absolute( relative) . unwrap( ) . as_os_str( ) , expected. as_os_str( ) ) ;
19071916
@@ -1953,116 +1962,6 @@ fn test_extension_path_sep_alternate() {
19531962 assert_eq ! ( path, Path :: new( "path/to/file.d\\ test" ) ) ;
19541963}
19551964
1956- #[ bench]
1957- #[ cfg_attr( miri, ignore) ] // Miri isn't fast...
1958- fn bench_path_cmp_fast_path_buf_sort ( b : & mut test:: Bencher ) {
1959- let prefix = "my/home" ;
1960- let mut paths: Vec < _ > =
1961- ( 0 ..1000 ) . map ( |num| PathBuf :: from ( prefix) . join ( format ! ( "file {num}.rs" ) ) ) . collect ( ) ;
1962-
1963- paths. sort ( ) ;
1964-
1965- b. iter ( || {
1966- black_box ( paths. as_mut_slice ( ) ) . sort_unstable ( ) ;
1967- } ) ;
1968- }
1969-
1970- #[ bench]
1971- #[ cfg_attr( miri, ignore) ] // Miri isn't fast...
1972- fn bench_path_cmp_fast_path_long ( b : & mut test:: Bencher ) {
1973- let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/" ;
1974- let paths: Vec < _ > =
1975- ( 0 ..1000 ) . map ( |num| PathBuf :: from ( prefix) . join ( format ! ( "file {num}.rs" ) ) ) . collect ( ) ;
1976-
1977- let mut set = BTreeSet :: new ( ) ;
1978-
1979- paths. iter ( ) . for_each ( |p| {
1980- set. insert ( p. as_path ( ) ) ;
1981- } ) ;
1982-
1983- b. iter ( || {
1984- set. remove ( paths[ 500 ] . as_path ( ) ) ;
1985- set. insert ( paths[ 500 ] . as_path ( ) ) ;
1986- } ) ;
1987- }
1988-
1989- #[ bench]
1990- #[ cfg_attr( miri, ignore) ] // Miri isn't fast...
1991- fn bench_path_cmp_fast_path_short ( b : & mut test:: Bencher ) {
1992- let prefix = "my/home" ;
1993- let paths: Vec < _ > =
1994- ( 0 ..1000 ) . map ( |num| PathBuf :: from ( prefix) . join ( format ! ( "file {num}.rs" ) ) ) . collect ( ) ;
1995-
1996- let mut set = BTreeSet :: new ( ) ;
1997-
1998- paths. iter ( ) . for_each ( |p| {
1999- set. insert ( p. as_path ( ) ) ;
2000- } ) ;
2001-
2002- b. iter ( || {
2003- set. remove ( paths[ 500 ] . as_path ( ) ) ;
2004- set. insert ( paths[ 500 ] . as_path ( ) ) ;
2005- } ) ;
2006- }
2007-
2008- #[ bench]
2009- #[ cfg_attr( miri, ignore) ] // Miri isn't fast...
2010- fn bench_path_hashset ( b : & mut test:: Bencher ) {
2011- let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/" ;
2012- let paths: Vec < _ > =
2013- ( 0 ..1000 ) . map ( |num| PathBuf :: from ( prefix) . join ( format ! ( "file {num}.rs" ) ) ) . collect ( ) ;
2014-
2015- let mut set = HashSet :: new ( ) ;
2016-
2017- paths. iter ( ) . for_each ( |p| {
2018- set. insert ( p. as_path ( ) ) ;
2019- } ) ;
2020-
2021- b. iter ( || {
2022- set. remove ( paths[ 500 ] . as_path ( ) ) ;
2023- set. insert ( black_box ( paths[ 500 ] . as_path ( ) ) )
2024- } ) ;
2025- }
2026-
2027- #[ bench]
2028- #[ cfg_attr( miri, ignore) ] // Miri isn't fast...
2029- fn bench_path_hashset_miss ( b : & mut test:: Bencher ) {
2030- let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/" ;
2031- let paths: Vec < _ > =
2032- ( 0 ..1000 ) . map ( |num| PathBuf :: from ( prefix) . join ( format ! ( "file {num}.rs" ) ) ) . collect ( ) ;
2033-
2034- let mut set = HashSet :: new ( ) ;
2035-
2036- paths. iter ( ) . for_each ( |p| {
2037- set. insert ( p. as_path ( ) ) ;
2038- } ) ;
2039-
2040- let probe = PathBuf :: from ( prefix) . join ( "other" ) ;
2041-
2042- b. iter ( || set. remove ( black_box ( probe. as_path ( ) ) ) ) ;
2043- }
2044-
2045- #[ bench]
2046- fn bench_hash_path_short ( b : & mut test:: Bencher ) {
2047- let mut hasher = DefaultHasher :: new ( ) ;
2048- let path = Path :: new ( "explorer.exe" ) ;
2049-
2050- b. iter ( || black_box ( path) . hash ( & mut hasher) ) ;
2051-
2052- black_box ( hasher. finish ( ) ) ;
2053- }
2054-
2055- #[ bench]
2056- fn bench_hash_path_long ( b : & mut test:: Bencher ) {
2057- let mut hasher = DefaultHasher :: new ( ) ;
2058- let path =
2059- Path :: new ( "/aaaaa/aaaaaa/./../aaaaaaaa/bbbbbbbbbbbbb/ccccccccccc/ddddddddd/eeeeeee.fff" ) ;
2060-
2061- b. iter ( || black_box ( path) . hash ( & mut hasher) ) ;
2062-
2063- black_box ( hasher. finish ( ) ) ;
2064- }
2065-
20661965#[ test]
20671966fn clone_to_uninit ( ) {
20681967 let a = Path :: new ( "hello.txt" ) ;
0 commit comments