From 700c83bc05ebeddbe3d3a10c2e309826d563b12b Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Sun, 24 Jun 2018 09:38:56 +0200 Subject: [PATCH 1/7] Document `From` implementations --- src/libstd/path.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index a153456370c6f..ab37bb7520972 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1397,6 +1397,8 @@ impl<'a> From<&'a Path> for Box { #[stable(feature = "path_buf_from_box", since = "1.18.0")] impl From> for PathBuf { + /// Converts a `Box` into a `PathBuf`. + /// This conversion does not allocate memory fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } @@ -1404,6 +1406,8 @@ impl From> for PathBuf { #[stable(feature = "box_from_path_buf", since = "1.20.0")] impl From for Box { + /// Converts a `PathBuf` into a `Box`. + /// This conversion does not allocate memory fn from(p: PathBuf) -> Box { p.into_boxed_path() } @@ -1426,6 +1430,9 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { + /// Converts a `OsString` into a `PathBuf`. + /// This conversion copies the data. + /// This conversion does allocate memory. fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1433,6 +1440,9 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { + /// Converts a `PathBuf` into a `OsString`. + /// This conversion copies the data. + /// This conversion does allocate memory. fn from(path_buf : PathBuf) -> OsString { path_buf.inner } @@ -1440,6 +1450,8 @@ impl From for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { + /// Converts a `String` into a `PathBuf`. + /// This conversion does not allocate memory fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) } @@ -1536,6 +1548,10 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { + /// Converts a `PathBuf` into a `Arc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1545,6 +1561,10 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { + /// Converts a `PathBuf` into a `Arc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1554,6 +1574,10 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { + /// Converts a `PathBuf` into a `Rc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From 072bca3ff5a3907a71c22fba041825cfa3eb321e Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Mon, 25 Jun 2018 14:24:39 +0200 Subject: [PATCH 2/7] Remove 'unsafe' comments --- src/libstd/path.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ab37bb7520972..9145eeb6063f6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1551,7 +1551,6 @@ impl From for Arc { /// Converts a `PathBuf` into a `Arc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1564,7 +1563,6 @@ impl<'a> From<&'a Path> for Arc { /// Converts a `PathBuf` into a `Arc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1577,7 +1575,6 @@ impl From for Rc { /// Converts a `PathBuf` into a `Rc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From 88a708dd6a5bb14f3a19ae98238ddf2d03cb93d3 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Mon, 25 Jun 2018 21:29:22 +0200 Subject: [PATCH 3/7] Update comments --- src/libstd/path.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9145eeb6063f6..e631bb90f5741 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1431,8 +1431,7 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { /// Converts a `OsString` into a `PathBuf`. - /// This conversion copies the data. - /// This conversion does allocate memory. + /// This conversion does not allocate memory fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1441,8 +1440,7 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { /// Converts a `PathBuf` into a `OsString`. - /// This conversion copies the data. - /// This conversion does allocate memory. + /// This conversion does not allocate memory fn from(path_buf : PathBuf) -> OsString { path_buf.inner } From 5c747eb32654401b9b6fe053c3f51399a6454f8c Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Thu, 26 Jul 2018 10:59:46 +0200 Subject: [PATCH 4/7] Update style of comments --- src/libstd/path.rs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e631bb90f5741..9f6fcad242292 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1397,7 +1397,8 @@ impl<'a> From<&'a Path> for Box { #[stable(feature = "path_buf_from_box", since = "1.18.0")] impl From> for PathBuf { - /// Converts a `Box` into a `PathBuf`. + /// Converts a `Box` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() @@ -1406,7 +1407,8 @@ impl From> for PathBuf { #[stable(feature = "box_from_path_buf", since = "1.20.0")] impl From for Box { - /// Converts a `PathBuf` into a `Box`. + /// Converts a `PathBuf` into a `Box` + /// /// This conversion does not allocate memory fn from(p: PathBuf) -> Box { p.into_boxed_path() @@ -1430,7 +1432,8 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { - /// Converts a `OsString` into a `PathBuf`. + /// Converts a `OsString` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(s: OsString) -> PathBuf { PathBuf { inner: s } @@ -1439,7 +1442,8 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { - /// Converts a `PathBuf` into a `OsString`. + /// Converts a `PathBuf` into a `OsString` + /// /// This conversion does not allocate memory fn from(path_buf : PathBuf) -> OsString { path_buf.inner @@ -1448,7 +1452,8 @@ impl From for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { - /// Converts a `String` into a `PathBuf`. + /// Converts a `String` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) @@ -1546,9 +1551,11 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { - /// Converts a `PathBuf` into a `Arc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Arc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1558,9 +1565,12 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { - /// Converts a `PathBuf` into a `Arc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Arc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory + /// #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1570,9 +1580,11 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts a `PathBuf` into a `Rc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Rc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From e8dafbaf10bf9e54854382f0aa830d219aec85bb Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 21 Nov 2018 13:06:22 +0100 Subject: [PATCH 5/7] Adjust doc comments --- src/libstd/path.rs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9f6fcad242292..2d0a2501f7e99 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1399,7 +1399,7 @@ impl<'a> From<&'a Path> for Box { impl From> for PathBuf { /// Converts a `Box` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } @@ -1409,7 +1409,8 @@ impl From> for PathBuf { impl From for Box { /// Converts a `PathBuf` into a `Box` /// - /// This conversion does not allocate memory + /// This conversion currently should not allocate memory, + // but this behavior is not guaranteed on all platforms or in all future versions. fn from(p: PathBuf) -> Box { p.into_boxed_path() } @@ -1434,7 +1435,7 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { impl From for PathBuf { /// Converts a `OsString` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1444,7 +1445,7 @@ impl From for PathBuf { impl From for OsString { /// Converts a `PathBuf` into a `OsString` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(path_buf : PathBuf) -> OsString { path_buf.inner } @@ -1454,7 +1455,7 @@ impl From for OsString { impl From for PathBuf { /// Converts a `String` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) } @@ -1551,11 +1552,7 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { - /// Converts a `PathBuf` into a `Arc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1565,12 +1562,7 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { - /// Converts a `PathBuf` into a `Arc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory - /// + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1580,11 +1572,7 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts a `PathBuf` into a `Rc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); @@ -1594,6 +1582,7 @@ impl From for Rc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Rc { + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Rc { let rc: Rc = Rc::from(s.as_os_str()); From 7933628de58851281544fe2a7b4e0d0673652e47 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 21 Nov 2018 13:57:56 +0100 Subject: [PATCH 6/7] Remove trailing whitespace --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 2d0a2501f7e99..dcd02ac59b6c8 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1409,7 +1409,7 @@ impl From> for PathBuf { impl From for Box { /// Converts a `PathBuf` into a `Box` /// - /// This conversion currently should not allocate memory, + /// This conversion currently should not allocate memory, // but this behavior is not guaranteed on all platforms or in all future versions. fn from(p: PathBuf) -> Box { p.into_boxed_path() From 450a8a6f354ac9b19d5980837ea0f34cd6c7ece6 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Tue, 4 Dec 2018 10:10:07 +0100 Subject: [PATCH 7/7] Add extra comment slash --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index dcd02ac59b6c8..9fad40c564944 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1410,7 +1410,7 @@ impl From for Box { /// Converts a `PathBuf` into a `Box` /// /// This conversion currently should not allocate memory, - // but this behavior is not guaranteed on all platforms or in all future versions. + /// but this behavior is not guaranteed on all platforms or in all future versions. fn from(p: PathBuf) -> Box { p.into_boxed_path() }