diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-13 03:33:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-13 03:33:41 +0100 |
| commit | 68abd9a99976a84cca6dcb5459cc3bc279470b4c (patch) | |
| tree | 7439d44a0d4713408af0226368405f54a661b57c /src/libstd/path.rs | |
| parent | fc19f0e75b57e0306a7ca9c132e27bfac0bb3e44 (diff) | |
| parent | df4ea90b39c808e858e05f3b4bb05fc29f812d26 (diff) | |
| download | rust-68abd9a99976a84cca6dcb5459cc3bc279470b4c.tar.gz rust-68abd9a99976a84cca6dcb5459cc3bc279470b4c.zip | |
Rollup merge of #59056 - scottmcm:even-fewer-lifetimes, r=sfackler
Use lifetime contravariance to elide more lifetimes in core+alloc+std
Sample:
```diff
- impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a mut A where A: PartialEq<B> {
+ impl<A: ?Sized, B: ?Sized> PartialEq<&mut B> for &mut A where A: PartialEq<B> {
#[inline]
- fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
+ fn eq(&self, other: &&mut B) -> bool { PartialEq::eq(*self, *other) }
#[inline]
- fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
+ fn ne(&self, other: &&mut B) -> bool { PartialEq::ne(*self, *other) }
}
```
[I didn't know this worked](https://internals.rust-lang.org/t/why-can-you-use-different-unconstrained-lifetimes-to-implement-traits/9544/2?u=scottmcm) until recently, but since defining methods contravariantly in their lifetimes this way has worked back to Rust 1.0, we might as well take advantage of combining it with IHLE.
Diffstat (limited to 'src/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 858a5778b81..ea3fcd8ce28 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1456,8 +1456,8 @@ impl PathBuf { } #[stable(feature = "box_from_path", since = "1.17.0")] -impl<'a> From<&'a Path> for Box<Path> { - fn from(path: &'a Path) -> Box<Path> { +impl From<&Path> for Box<Path> { + fn from(path: &Path) -> Box<Path> { let boxed: Box<OsStr> = path.inner.into(); let rw = Box::into_raw(boxed) as *mut Path; unsafe { Box::from_raw(rw) } @@ -1494,8 +1494,8 @@ impl Clone for Box<Path> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for PathBuf { - fn from(s: &'a T) -> PathBuf { +impl<T: ?Sized + AsRef<OsStr>> From<&T> for PathBuf { + fn from(s: &T) -> PathBuf { PathBuf::from(s.as_ref().to_os_string()) } } @@ -1630,7 +1630,7 @@ impl From<PathBuf> for Arc<Path> { } #[stable(feature = "shared_from_slice2", since = "1.24.0")] -impl<'a> From<&'a Path> for Arc<Path> { +impl From<&Path> for Arc<Path> { /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Arc<Path> { @@ -1650,7 +1650,7 @@ impl From<PathBuf> for Rc<Path> { } #[stable(feature = "shared_from_slice2", since = "1.24.0")] -impl<'a> From<&'a Path> for Rc<Path> { +impl From<&Path> for Rc<Path> { /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Rc<Path> { |
