diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 969f4e4373a..df0462203a9 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -307,8 +307,9 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { // Try to elide redundant long paths fn shorten(path: &Path) -> ~str { let filename = path.filename(); - let dir = path.pop().filename(); - fmt!("%s/%s", dir.unwrap_or_default(~""), filename.unwrap_or_default(~"")) + let p = path.pop(); + let dir = p.filename(); + fmt!("%s/%s", dir.unwrap_or_default(""), filename.unwrap_or_default("")) } test::DynTestName(fmt!("[%s] %s", diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index ea94ce662ac..6e2f62f8706 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -880,7 +880,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) { let dirs = os::list_dir_path(&Path(tstr)); for file in dirs.iter() { - if (file.filetype() == Some(~".so")) { + if (file.filetype() == Some(".so")) { let copy_result = procsrv::run("", config.adb_path, [~"push", file.to_str(), config.adb_test_dir.clone()], diff --git a/src/librust/rust.rs b/src/librust/rust.rs index a20e864e292..b44fb100000 100644 --- a/src/librust/rust.rs +++ b/src/librust/rust.rs @@ -162,7 +162,8 @@ fn cmd_help(args: &[~str]) -> ValidUsage { fn cmd_test(args: &[~str]) -> ValidUsage { match args { [ref filename] => { - let test_exec = Path(*filename).filestem().unwrap() + "test~"; + let p = Path(*filename); + let test_exec = p.filestem().unwrap() + "test~"; invoke("rustc", &[~"--test", filename.to_owned(), ~"-o", test_exec.to_owned()], rustc::main_args); let exit_code = run::process_status(~"./" + test_exec, []); @@ -175,7 +176,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage { fn cmd_run(args: &[~str]) -> ValidUsage { match args { [ref filename, ..prog_args] => { - let exec = Path(*filename).filestem().unwrap() + "~"; + let p = Path(*filename); + let exec = p.filestem().unwrap() + "~"; invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()], rustc::main_args); let exit_code = run::process_status(~"./"+exec, prog_args); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 6422290eec5..e2ef1f2282d 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -952,13 +952,13 @@ pub fn link_args(sess: Session, let cstore = sess.cstore; let r = cstore::get_used_crate_files(cstore); for cratepath in r.iter() { - if cratepath.filetype() == Some(~".rlib") { + if cratepath.filetype() == Some(".rlib") { args.push(cratepath.to_str()); loop; } let dir = cratepath.dirname(); if dir != ~"" { args.push(~"-L" + dir); } - let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap()); + let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned()); args.push(~"-l" + libarg); } diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index 7c3cde65517..984527eb56a 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -19,7 +19,8 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool { for p in workspaces.iter() { let binfiles = os::list_dir(&p.push("bin")); for exec in binfiles.iter() { - let exec_path = Path(*exec).filestem(); + let p = Path(*exec); + let exec_path = p.filestem(); do exec_path.iter().advance |s| { f(&PkgId::new(*s)) }; @@ -49,8 +50,8 @@ pub fn has_library(p: &Path) -> Option<~str> { let files = os::list_dir(p); for q in files.iter() { let as_path = Path(*q); - if as_path.filetype() == Some(os::consts::DLL_SUFFIX.to_owned()) { - let stuff : ~str = as_path.filestem().expect("has_library: weird path"); + if as_path.filetype() == Some(os::consts::DLL_SUFFIX) { + let stuff : &str = as_path.filestem().expect("has_library: weird path"); let mut stuff2 = stuff.split_str_iter(&"-"); let stuff3: ~[&str] = stuff2.collect(); // argh diff --git a/src/librustpkg/package_id.rs b/src/librustpkg/package_id.rs index 2b56bb3885c..ce1da58a2cb 100644 --- a/src/librustpkg/package_id.rs +++ b/src/librustpkg/package_id.rs @@ -68,7 +68,7 @@ impl PkgId { if path.components.len() < 1 { return cond.raise((path, ~"0-length pkgid")); } - let short_name = path.clone().filestem().expect(fmt!("Strange path! %s", s)); + let short_name = path.filestem().expect(fmt!("Strange path! %s", s)); let version = match given_version { Some(v) => v, @@ -83,8 +83,8 @@ impl PkgId { debug!("path = %s", path.to_str()); PkgId { - path: path, - short_name: short_name, + path: path.clone(), + short_name: short_name.to_owned(), version: version } } diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 8f2d8877cf9..c20091158c4 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -119,7 +119,7 @@ impl PkgSrc { return Some(local); } - if (self.id.path.clone()).components().len() < 2 { + if self.id.path.components().len() < 2 { // If a non-URL, don't bother trying to fetch return None; } @@ -157,7 +157,7 @@ impl PkgSrc { /// True if the given path's stem is self's pkg ID's stem fn stem_matches(&self, p: &Path) -> bool { - p.filestem().map_default(false, |p| { p == &self.id.short_name }) + p.filestem().map_default(false, |p| { p == &self.id.short_name.as_slice() }) } fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) { @@ -182,10 +182,10 @@ impl PkgSrc { do os::walk_dir(&dir) |pth| { let maybe_known_crate_set = match pth.filename() { Some(filename) => match filename { - ~"lib.rs" => Some(&mut self.libs), - ~"main.rs" => Some(&mut self.mains), - ~"test.rs" => Some(&mut self.tests), - ~"bench.rs" => Some(&mut self.benchs), + "lib.rs" => Some(&mut self.libs), + "main.rs" => Some(&mut self.mains), + "test.rs" => Some(&mut self.tests), + "bench.rs" => Some(&mut self.benchs), _ => None }, _ => None diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index af70a79f93d..cbe6c8f65c4 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -234,14 +234,14 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target, Some(j) => { debug!("Maybe %s equals %s", f_name.slice(0, j), lib_prefix); if f_name.slice(0, j) == lib_prefix { - result_filename = Some(p_path); + result_filename = Some(p_path.clone()); } break; } None => break } } - _ => { f_name = f_name.slice(0, i).to_owned(); } + _ => { f_name = f_name.slice(0, i); } } } None => break diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 4f8e80f56d5..5226036802e 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -396,7 +396,7 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) { let pkg_src_dir = workspace.push("src").push(pkgid.to_str()); let contents = os::list_dir_path(&pkg_src_dir); for p in contents.iter() { - if p.filetype() == Some(~".rs") { + if p.filetype() == Some(".rs") { // should be able to do this w/o a process if run::process_output("touch", [p.to_str()]).status != 0 { let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path")); @@ -413,7 +413,7 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId) { let contents = os::list_dir_path(&pkg_src_dir); let mut maybe_p = None; for p in contents.iter() { - if p.filetype() == Some(~".rs") { + if p.filetype() == Some(".rs") { maybe_p = Some(p); break; } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 858098409e9..d95c7b65101 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -28,7 +28,7 @@ use option::{None, Option, Some}; use str::{OwnedStr, Str, StrSlice, StrVector}; use to_str::ToStr; use ascii::{AsciiCast, AsciiStr}; -use vec::{OwnedVector, ImmutableVector, OwnedCopyableVector}; +use vec::{Vector, OwnedVector, ImmutableVector, OwnedCopyableVector}; #[cfg(windows)] pub use Path = self::WindowsPath; @@ -65,17 +65,17 @@ pub trait GenericPath { fn dirname(&self) -> ~str; /// Returns the file component of `self`, as a string option. /// Returns None if `self` names a directory. - fn filename(&self) -> Option<~str>; + fn filename<'a>(&'a self) -> Option<&'a str>; /// Returns the stem of the file component of `self`, as a string option. /// The stem is the slice of a filename starting at 0 and ending just before /// the last '.' in the name. /// Returns None if `self` names a directory. - fn filestem(&self) -> Option<~str>; + fn filestem<'a>(&'a self) -> Option<&'a str>; /// Returns the type of the file component of `self`, as a string option. /// The file type is the slice of a filename starting just after the last /// '.' in the name and ending at the last index in the filename. /// Returns None if `self` names a directory. - fn filetype(&self) -> Option<~str>; + fn filetype<'a>(&'a self) -> Option<&'a str>; /// Returns a new path consisting of `self` with the parent directory component replaced /// with the given string. @@ -163,7 +163,7 @@ pub trait GenericPath { result } - fn components(self) -> ~[~str]; + fn components<'a>(&'a self) -> &'a [~str]; } #[cfg(target_os = "linux")] @@ -600,31 +600,31 @@ impl GenericPath for PosixPath { } } - fn filename(&self) -> Option<~str> { + fn filename<'a>(&'a self) -> Option<&'a str> { match self.components.len() { 0 => None, - n => Some(self.components[n - 1].clone()), + n => Some(self.components[n - 1].as_slice()), } } - fn filestem(&self) -> Option<~str> { + fn filestem<'a>(&'a self) -> Option<&'a str> { match self.filename() { None => None, Some(ref f) => { match f.rfind('.') { - Some(p) => Some(f.slice_to(p).to_owned()), - None => Some((*f).clone()), + Some(p) => Some(f.slice_to(p)), + None => Some((*f)), } } } } - fn filetype(&self) -> Option<~str> { + fn filetype<'a>(&'a self) -> Option<&'a str> { match self.filename() { None => None, Some(ref f) => { match f.rfind('.') { - Some(p) if p < f.len() => Some(f.slice_from(p).to_owned()), + Some(p) if p < f.len() => Some(f.slice_from(p)), _ => None, } } @@ -670,7 +670,7 @@ impl GenericPath for PosixPath { fn file_path(&self) -> PosixPath { let cs = match self.filename() { None => ~[], - Some(ref f) => ~[(*f).clone()] + Some(ref f) => ~[(*f).to_owned()] }; PosixPath { is_absolute: false, @@ -756,7 +756,7 @@ impl GenericPath for PosixPath { self.is_ancestor_of(&other.pop())) } - fn components(self) -> ~[~str] { self.components } + fn components<'a>(&'a self) -> &'a [~str] { self.components.as_slice() } } @@ -842,31 +842,31 @@ impl GenericPath for WindowsPath { } } - fn filename(&self) -> Option<~str> { + fn filename<'a>(&'a self) -> Option<&'a str> { match self.components.len() { 0 => None, - n => Some(self.components[n - 1].clone()), + n => Some(self.components[n - 1].as_slice()), } } - fn filestem(&self) -> Option<~str> { + fn filestem<'a>(&'a self) -> Option<&'a str> { match self.filename() { None => None, Some(ref f) => { match f.rfind('.') { - Some(p) => Some(f.slice_to(p).to_owned()), - None => Some((*f).clone()), + Some(p) => Some(f.slice_to(p)), + None => Some((*f)), } } } } - fn filetype(&self) -> Option<~str> { + fn filetype<'a>(&'a self) -> Option<&'a str> { match self.filename() { None => None, Some(ref f) => { match f.rfind('.') { - Some(p) if p < f.len() => Some(f.slice_from(p).to_owned()), + Some(p) if p < f.len() => Some(f.slice_from(p)), _ => None, } } @@ -916,7 +916,7 @@ impl GenericPath for WindowsPath { is_absolute: false, components: match self.filename() { None => ~[], - Some(ref f) => ~[(*f).clone()], + Some(ref f) => ~[(*f).to_owned()], } } } @@ -1049,7 +1049,7 @@ impl GenericPath for WindowsPath { self.is_ancestor_of(&other.pop())) } - fn components(self) -> ~[~str] { self.components } + fn components<'a>(&'a self) -> &'a [~str] { self.components.as_slice() } } pub fn normalize(components: &[~str]) -> ~[~str] { @@ -1143,10 +1143,10 @@ mod tests { #[test] fn test_filetype_foo_bar() { let wp = PosixPath("foo.bar"); - assert_eq!(wp.filetype(), Some(~".bar")); + assert_eq!(wp.filetype(), Some(".bar")); let wp = WindowsPath("foo.bar"); - assert_eq!(wp.filetype(), Some(~".bar")); + assert_eq!(wp.filetype(), Some(".bar")); } #[test]