diff options
| author | bors <bors@rust-lang.org> | 2014-11-03 12:12:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-11-03 12:12:24 +0000 |
| commit | b9b396cd7506c2e2aa6737adfa80f3404ed81b9d (patch) | |
| tree | e623507b5799ba153b33c059e6b15a15cd5806ac | |
| parent | 851799d09e48e06f3fd0c4c6f694af51fc655f9a (diff) | |
| parent | fe256f81401e7af5fb3a3ec069427fd9c52073a9 (diff) | |
| download | rust-b9b396cd7506c2e2aa6737adfa80f3404ed81b9d.tar.gz rust-b9b396cd7506c2e2aa6737adfa80f3404ed81b9d.zip | |
auto merge of #18463 : japaric/rust/bytes2, r=alexcrichton
- The `BytesContainer::container_into_owned_bytes` method has been removed
- Methods that used to take `BytesContainer` implementors by value, now take them by reference. In particular, this breaks some uses of Path:
``` rust
Path::new("foo") // Still works
path.join(another_path) -> path.join(&another_path)
```
[breaking-change]
---
Re: `container_into_owned_bytes`, I've removed it because
- Nothing in the whole repository uses it
- Takes `self` by value, which is incompatible with unsized types (`str`)
The alternative to removing this method is to split `BytesContainer` into `BytesContainer for Sized?` and `SizedBytesContainer: BytesContainer + Sized`, where the second trait only contains the `container_into_owned_bytes` method. I tried this alternative [in another branch](https://github.com/japaric/rust/commits/bytes) and it works, but it seemed better not to create a new trait for an unused method.
Re: Breakage of `Path` methods
We could use the idea that @alexcrichton proposed in #18457 (add blanket `impl BytesContainer for &T where T: BytesContainer` + keep taking `T: BytesContainer` by value in `Path` methods) to avoid breaking any code.
r? @aturon
cc #16918
| -rw-r--r-- | src/compiletest/runtest.rs | 2 | ||||
| -rw-r--r-- | src/librustc/driver/session.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 55 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 11 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 19 | ||||
| -rw-r--r-- | src/libterm/terminfo/searcher.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/process-spawn-with-unicode-params.rs | 2 |
8 files changed, 36 insertions, 59 deletions
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 283ca46a49f..55247792921 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -627,7 +627,7 @@ fn find_rust_src_root(config: &Config) -> Option<Path> { let path_postfix = Path::new("src/etc/lldb_batchmode.py"); while path.pop() { - if path.join(path_postfix.clone()).is_file() { + if path.join(&path_postfix).is_file() { return Some(path); } } diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 55e07321c71..f8e778ce15f 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -231,7 +231,7 @@ pub fn build_session_(sopts: config::Options, if path.is_absolute() { path.clone() } else { - os::getcwd().join(path.clone()) + os::getcwd().join(&path) } ); diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 4e5f8822acb..312a4c41ac9 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -918,7 +918,7 @@ mod tests { let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap(); let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); - let child_dir = Path::new(output.as_slice().trim().into_string()); + let child_dir = Path::new(output.as_slice().trim()); let parent_stat = parent_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap(); diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 62105c0d90e..8949a881c9d 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -67,6 +67,7 @@ println!("path exists: {}", path.exists()); #![experimental] +use core::kinds::Sized; use c_str::CString; use clone::Clone; use fmt; @@ -626,7 +627,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn push_many<T: BytesContainer>(&mut self, paths: &[T]) { - let t: Option<T> = None; + let t: Option<&T> = None; if BytesContainer::is_str(t) { for p in paths.iter() { self.push(p.container_as_str().unwrap()) @@ -791,14 +792,9 @@ pub trait GenericPath: Clone + GenericPathUnsafe { } /// A trait that represents something bytes-like (e.g. a &[u8] or a &str) -pub trait BytesContainer { +pub trait BytesContainer for Sized? { /// Returns a &[u8] representing the receiver fn container_as_bytes<'a>(&'a self) -> &'a [u8]; - /// Consumes the receiver and converts it into Vec<u8> - #[inline] - fn container_into_owned_bytes(self) -> Vec<u8> { - self.container_as_bytes().to_vec() - } /// Returns the receiver interpreted as a utf-8 string, if possible #[inline] fn container_as_str<'a>(&'a self) -> Option<&'a str> { @@ -807,7 +803,7 @@ pub trait BytesContainer { /// Returns whether .container_as_str() is guaranteed to not fail // FIXME (#8888): Remove unused arg once ::<for T> works #[inline] - fn is_str(_: Option<Self>) -> bool { false } + fn is_str(_: Option<&Self>) -> bool { false } } /// A trait that represents the unsafe operations on GenericPaths @@ -859,48 +855,44 @@ impl<'a, P: GenericPath> Display<'a, P> { } } -impl<'a> BytesContainer for &'a str { +impl BytesContainer for str { #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + fn container_as_bytes(&self) -> &[u8] { self.as_bytes() } #[inline] - fn container_as_str<'a>(&'a self) -> Option<&'a str> { - Some(*self) + fn container_as_str(&self) -> Option<&str> { + Some(self) } #[inline] - fn is_str(_: Option<&'a str>) -> bool { true } + fn is_str(_: Option<&str>) -> bool { true } } impl BytesContainer for String { #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + fn container_as_bytes(&self) -> &[u8] { self.as_bytes() } #[inline] - fn container_as_str<'a>(&'a self) -> Option<&'a str> { + fn container_as_str(&self) -> Option<&str> { Some(self.as_slice()) } #[inline] - fn is_str(_: Option<String>) -> bool { true } + fn is_str(_: Option<&String>) -> bool { true } } -impl<'a> BytesContainer for &'a [u8] { +impl BytesContainer for [u8] { #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - *self + fn container_as_bytes(&self) -> &[u8] { + self } } impl BytesContainer for Vec<u8> { #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { + fn container_as_bytes(&self) -> &[u8] { self.as_slice() } - #[inline] - fn container_into_owned_bytes(self) -> Vec<u8> { - self - } } impl BytesContainer for CString { @@ -920,7 +912,20 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> { Some(self.as_slice()) } #[inline] - fn is_str(_: Option<str::MaybeOwned>) -> bool { true } + fn is_str(_: Option<&str::MaybeOwned>) -> bool { true } +} + +impl<'a, Sized? T: BytesContainer> BytesContainer for &'a T { + #[inline] + fn container_as_bytes(&self) -> &[u8] { + (**self).container_as_bytes() + } + #[inline] + fn container_as_str(&self) -> Option<&str> { + (**self).container_as_str() + } + #[inline] + fn is_str(_: Option<& &'a T>) -> bool { BytesContainer::is_str(None::<&T>) } } #[inline(always)] diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index e090d9d7098..60cfa7a13de 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -117,17 +117,6 @@ impl BytesContainer for Path { fn container_as_bytes<'a>(&'a self) -> &'a [u8] { self.as_vec() } - #[inline] - fn container_into_owned_bytes(self) -> Vec<u8> { - self.into_vec() - } -} - -impl<'a> BytesContainer for &'a Path { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_vec() - } } impl GenericPathUnsafe for Path { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index f0d1ecf9d24..3ef142a2e82 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -149,28 +149,11 @@ impl BytesContainer for Path { self.as_vec() } #[inline] - fn container_into_owned_bytes(self) -> Vec<u8> { - self.into_vec() - } - #[inline] - fn container_as_str<'a>(&'a self) -> Option<&'a str> { - self.as_str() - } - #[inline] - fn is_str(_: Option<Path>) -> bool { true } -} - -impl<'a> BytesContainer for &'a Path { - #[inline] - fn container_as_bytes<'a>(&'a self) -> &'a [u8] { - self.as_vec() - } - #[inline] fn container_as_str<'a>(&'a self) -> Option<&'a str> { self.as_str() } #[inline] - fn is_str(_: Option<&'a Path>) -> bool { true } + fn is_str(_: Option<&Path>) -> bool { true } } impl GenericPathUnsafe for Path { diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index a89afab505b..61ff88a2fa3 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -41,7 +41,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> { if i == "" { dirs_to_search.push(Path::new("/usr/share/terminfo")); } else { - dirs_to_search.push(Path::new(i.to_string())); + dirs_to_search.push(Path::new(i)); } }, // Found nothing in TERMINFO_DIRS, use the default paths: diff --git a/src/test/run-pass/process-spawn-with-unicode-params.rs b/src/test/run-pass/process-spawn-with-unicode-params.rs index 9716d79f4c8..490614ef121 100644 --- a/src/test/run-pass/process-spawn-with-unicode-params.rs +++ b/src/test/run-pass/process-spawn-with-unicode-params.rs @@ -48,7 +48,7 @@ fn main() { let child_filestem = Path::new(child_name); let child_filename = child_filestem.with_extension(my_ext); - let child_path = cwd.join(child_filename.clone()); + let child_path = cwd.join(child_filename); // make a separate directory for the child drop(fs::mkdir(&cwd, io::USER_RWX).is_ok()); |
