Stabilize std::path

This commit stabilizes essentially all of the new `std::path` API. The
API itself is changed in a couple of ways (which brings it in closer
alignment with the RFC):

* `.` components are now normalized away, unless they appear at the
  start of a path. This in turn effects the semantics of e.g. asking for
  the file name of `foo/` or `foo/.`, both of which yield `Some("foo")`
  now. This semantics is what the original RFC specified, and is also
  desirable given early experience rolling out the new API.

* The `parent` function now succeeds if, and only if, the path has at
  least one non-root/prefix component. This change affects `pop` as
  well.

* The `Prefix` component now involves a separate `PrefixComponent`
  struct, to better allow for keeping both parsed and unparsed prefix data.

In addition, the `old_path` module is now deprecated.

Closes #23264

[breaking-change]
This commit is contained in:
Aaron Turon 2015-03-09 08:49:10 -07:00
parent f899513a30
commit 42c4e481cd
36 changed files with 405 additions and 317 deletions

View File

@ -20,7 +20,6 @@
#![feature(std_misc)] #![feature(std_misc)]
#![feature(test)] #![feature(test)]
#![feature(core)] #![feature(core)]
#![feature(path)]
#![feature(io)] #![feature(io)]
#![feature(net)] #![feature(net)]
#![feature(path_ext)] #![feature(path_ext)]

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(deprecated)] // for old path, for dynamic_lib
use std::process::{ExitStatus, Command, Child, Output, Stdio}; use std::process::{ExitStatus, Command, Child, Output, Stdio};
use std::io::prelude::*; use std::io::prelude::*;
use std::dynamic_lib::DynamicLibrary; use std::dynamic_lib::DynamicLibrary;

View File

@ -40,7 +40,6 @@
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(std_misc)] #![feature(std_misc)]
#![feature(path)]
#![feature(io)] #![feature(io)]
#![feature(path_ext)] #![feature(path_ext)]
#![feature(str_words)] #![feature(str_words)]

View File

@ -18,7 +18,10 @@ use std::borrow::ToOwned;
use std::dynamic_lib::DynamicLibrary; use std::dynamic_lib::DynamicLibrary;
use std::env; use std::env;
use std::mem; use std::mem;
#[allow(deprecated)]
use std::old_path; use std::old_path;
use std::path::PathBuf; use std::path::PathBuf;
use syntax::ast; use syntax::ast;
use syntax::codemap::{Span, COMMAND_LINE_SP}; use syntax::codemap::{Span, COMMAND_LINE_SP};
@ -100,6 +103,7 @@ impl<'a> PluginLoader<'a> {
} }
// Dynamically link a registrar function into the compiler process. // Dynamically link a registrar function into the compiler process.
#[allow(deprecated)] // until #23197
fn dylink_registrar(&mut self, fn dylink_registrar(&mut self,
span: Span, span: Span,
path: PathBuf, path: PathBuf,

View File

@ -11,6 +11,7 @@
use std::io; use std::io;
use std::old_io::fs; use std::old_io::fs;
use std::old_io; use std::old_io;
#[allow(deprecated)]
use std::old_path; use std::old_path;
use std::os; use std::os;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View File

@ -42,11 +42,12 @@
#![feature(old_io)] #![feature(old_io)]
#![feature(old_path)] #![feature(old_path)]
#![feature(os)] #![feature(os)]
#![feature(path)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(rand)] #![feature(rand)]
#![feature(path_ext)] #![feature(path_ext)]
#![feature(std_misc)]
#![feature(path_relative_from)]
extern crate syntax; extern crate syntax;
extern crate serialize; extern crate serialize;

View File

@ -37,7 +37,6 @@
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(exit_status)] #![feature(exit_status)]
#![feature(path)]
#![feature(io)] #![feature(io)]
extern crate arena; extern crate arena;

View File

@ -31,7 +31,6 @@
#![feature(libc)] #![feature(libc)]
#![feature(link_args)] #![feature(link_args)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(path)]
#![cfg_attr(unix, feature(std_misc))] #![cfg_attr(unix, feature(std_misc))]
extern crate libc; extern crate libc;

View File

@ -39,10 +39,10 @@
#![feature(staged_api)] #![feature(staged_api)]
#![feature(unicode)] #![feature(unicode)]
#![feature(io)] #![feature(io)]
#![feature(path)]
#![feature(path_ext)] #![feature(path_ext)]
#![feature(fs)] #![feature(fs)]
#![feature(hash)] #![feature(hash)]
#![feature(path_relative_from)]
extern crate arena; extern crate arena;
extern crate flate; extern crate flate;

View File

@ -37,9 +37,9 @@
#![feature(unicode)] #![feature(unicode)]
#![feature(str_words)] #![feature(str_words)]
#![feature(io)] #![feature(io)]
#![feature(path)]
#![feature(file_path)] #![feature(file_path)]
#![feature(path_ext)] #![feature(path_ext)]
#![feature(path_relative_from)]
extern crate arena; extern crate arena;
extern crate getopts; extern crate getopts;
@ -362,6 +362,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
/// generated from the cleaned AST of the crate. /// generated from the cleaned AST of the crate.
/// ///
/// This form of input will run all of the plug/cleaning passes /// This form of input will run all of the plug/cleaning passes
#[allow(deprecated)] // for old Path in plugin manager
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output { fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output {
let mut default_passes = !matches.opt_present("no-defaults"); let mut default_passes = !matches.opt_present("no-defaults");
let mut passes = matches.opt_strs("passes"); let mut passes = matches.opt_strs("passes");

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(deprecated)] // old path, used for compatibility with dynamic lib
use clean; use clean;
use std::dynamic_lib as dl; use std::dynamic_lib as dl;

View File

@ -37,7 +37,6 @@ Core encoding and decoding interfaces.
#![feature(staged_api)] #![feature(staged_api)]
#![feature(std_misc)] #![feature(std_misc)]
#![feature(unicode)] #![feature(unicode)]
#![feature(path)]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(test))]
// test harness access // test harness access

View File

@ -14,6 +14,7 @@
Core encoding and decoding interfaces. Core encoding and decoding interfaces.
*/ */
#[allow(deprecated)]
use std::old_path; use std::old_path;
use std::path; use std::path;
use std::rc::Rc; use std::rc::Rc;
@ -539,12 +540,14 @@ macro_rules! tuple {
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
#[allow(deprecated)]
impl Encodable for old_path::posix::Path { impl Encodable for old_path::posix::Path {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
self.as_vec().encode(e) self.as_vec().encode(e)
} }
} }
#[allow(deprecated)]
impl Decodable for old_path::posix::Path { impl Decodable for old_path::posix::Path {
fn decode<D: Decoder>(d: &mut D) -> Result<old_path::posix::Path, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<old_path::posix::Path, D::Error> {
let bytes: Vec<u8> = try!(Decodable::decode(d)); let bytes: Vec<u8> = try!(Decodable::decode(d));
@ -552,12 +555,14 @@ impl Decodable for old_path::posix::Path {
} }
} }
#[allow(deprecated)]
impl Encodable for old_path::windows::Path { impl Encodable for old_path::windows::Path {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
self.as_vec().encode(e) self.as_vec().encode(e)
} }
} }
#[allow(deprecated)]
impl Decodable for old_path::windows::Path { impl Decodable for old_path::windows::Path {
fn decode<D: Decoder>(d: &mut D) -> Result<old_path::windows::Path, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<old_path::windows::Path, D::Error> {
let bytes: Vec<u8> = try!(Decodable::decode(d)); let bytes: Vec<u8> = try!(Decodable::decode(d));

View File

@ -14,6 +14,7 @@
#![unstable(feature = "std_misc")] #![unstable(feature = "std_misc")]
#![allow(missing_docs)] #![allow(missing_docs)]
#![allow(deprecated)] // will be addressed by #23197
use prelude::v1::*; use prelude::v1::*;

View File

@ -18,6 +18,7 @@
use prelude::v1::*; use prelude::v1::*;
use iter::IntoIterator;
use error::Error; use error::Error;
use ffi::{OsString, AsOsStr}; use ffi::{OsString, AsOsStr};
use fmt; use fmt;
@ -338,9 +339,9 @@ pub struct JoinPathsError {
/// ``` /// ```
#[stable(feature = "env", since = "1.0.0")] #[stable(feature = "env", since = "1.0.0")]
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError> pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
where I: Iterator<Item=T>, T: AsOsStr where I: IntoIterator<Item=T>, T: AsOsStr
{ {
os_imp::join_paths(paths).map_err(|e| { os_imp::join_paths(paths.into_iter()).map_err(|e| {
JoinPathsError { inner: e } JoinPathsError { inner: e }
}) })
} }

View File

@ -346,6 +346,7 @@ impl AsOsStr for String {
} }
} }
#[allow(deprecated)]
impl AsOsStr for Path { impl AsOsStr for Path {
#[cfg(unix)] #[cfg(unix)]
fn as_os_str(&self) -> &OsStr { fn as_os_str(&self) -> &OsStr {

View File

@ -571,19 +571,9 @@ pub fn create_dir<P: AsPath + ?Sized>(path: &P) -> io::Result<()> {
pub fn create_dir_all<P: AsPath + ?Sized>(path: &P) -> io::Result<()> { pub fn create_dir_all<P: AsPath + ?Sized>(path: &P) -> io::Result<()> {
let path = path.as_path(); let path = path.as_path();
if path.is_dir() { return Ok(()) } if path.is_dir() { return Ok(()) }
match path.parent() { if let Some(p) = path.parent() { try!(create_dir_all(p)) }
Some(p) if p != path => try!(create_dir_all(p)),
_ => {}
}
// If the file name of the given `path` is blank then the creation of the
// parent directory will have taken care of the whole path for us, so we're
// good to go.
if path.file_name().is_none() {
Ok(())
} else {
create_dir(path) create_dir(path)
} }
}
/// Remove an existing, empty directory /// Remove an existing, empty directory
/// ///

View File

@ -60,6 +60,7 @@
//! ``` //! ```
#![unstable(feature = "old_path")] #![unstable(feature = "old_path")]
#![deprecated(since = "1.0.0", reason = "use std::path instead")]
#![allow(deprecated)] // seriously this is all deprecated #![allow(deprecated)] // seriously this is all deprecated
#![allow(unused_imports)] #![allow(unused_imports)]

View File

@ -29,6 +29,7 @@
#![allow(missing_docs)] #![allow(missing_docs)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![allow(unused_imports)] #![allow(unused_imports)]
#![allow(deprecated)]
use self::MemoryMapKind::*; use self::MemoryMapKind::*;
use self::MapOption::*; use self::MapOption::*;

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,10 @@ use prelude::v1::*;
use sys::{last_error, retry}; use sys::{last_error, retry};
use ffi::CString; use ffi::CString;
use num::Int; use num::Int;
#[allow(deprecated)]
use old_path::BytesContainer; use old_path::BytesContainer;
use collections; use collections;
pub mod backtrace; pub mod backtrace;
@ -120,6 +123,7 @@ pub trait FromInner<Inner> {
} }
#[doc(hidden)] #[doc(hidden)]
#[allow(deprecated)]
pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> { pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
fn program(&self) -> &CString; fn program(&self) -> &CString;
fn args(&self) -> &[CString]; fn args(&self) -> &[CString];

View File

@ -10,6 +10,8 @@
//! Blocking posix-based file I/O //! Blocking posix-based file I/O
#![allow(deprecated)] // this module itself is essentially deprecated
use prelude::v1::*; use prelude::v1::*;
use ffi::{CString, CStr}; use ffi::{CString, CStr};

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(deprecated)] #![allow(deprecated)] // this module itself is essentially deprecated
use prelude::v1::*; use prelude::v1::*;
use self::Req::*; use self::Req::*;

View File

@ -23,6 +23,7 @@
//! this takes the route of using StackWalk64 in order to walk the stack. //! this takes the route of using StackWalk64 in order to walk the stack.
#![allow(dead_code)] #![allow(dead_code)]
#![allow(deprecated)] // for old path for dynamic lib
use dynamic_lib::DynamicLibrary; use dynamic_lib::DynamicLibrary;
use ffi::CStr; use ffi::CStr;

View File

@ -122,7 +122,7 @@ impl AsRawSocket for net::UdpSocket {
fn as_raw_socket(&self) -> Socket { *self.as_inner().socket().as_inner() } fn as_raw_socket(&self) -> Socket { *self.as_inner().socket().as_inner() }
} }
// Windows-specific extensions to `OsString`. /// Windows-specific extensions to `OsString`.
pub trait OsStringExt { pub trait OsStringExt {
/// Create an `OsString` from a potentially ill-formed UTF-16 slice of 16-bit code units. /// Create an `OsString` from a potentially ill-formed UTF-16 slice of 16-bit code units.
/// ///
@ -137,8 +137,12 @@ impl OsStringExt for OsString {
} }
} }
// Windows-specific extensions to `OsStr`. /// Windows-specific extensions to `OsStr`.
pub trait OsStrExt { pub trait OsStrExt {
/// Re-encode an `OsStr` as a wide character sequence,
/// i.e. potentially ill-formed UTF-16.
///
/// This is lossless. Note that the encoding does not include a final null.
fn encode_wide(&self) -> EncodeWide; fn encode_wide(&self) -> EncodeWide;
} }

View File

@ -10,6 +10,8 @@
//! Blocking Windows-based file I/O //! Blocking Windows-based file I/O
#![allow(deprecated)] // this module itself is essentially deprecated
use libc::{self, c_int}; use libc::{self, c_int};
use mem; use mem;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(deprecated)] #![allow(deprecated)] // this module itself is essentially deprecated
use prelude::v1::*; use prelude::v1::*;

View File

@ -195,11 +195,7 @@ fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> PathBuf {
// NB: relative paths are resolved relative to the compilation unit // NB: relative paths are resolved relative to the compilation unit
if !arg.is_absolute() { if !arg.is_absolute() {
let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp)); let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp));
if cu.parent().is_some() {
cu.pop(); cu.pop();
} else {
cu = PathBuf::new("");
}
cu.push(arg); cu.push(arg);
cu cu
} else { } else {

View File

@ -38,7 +38,6 @@
#![feature(staged_api)] #![feature(staged_api)]
#![feature(std_misc)] #![feature(std_misc)]
#![feature(unicode)] #![feature(unicode)]
#![feature(path)]
#![feature(io)] #![feature(io)]
#![feature(path_ext)] #![feature(path_ext)]

View File

@ -5254,13 +5254,7 @@ impl<'a> Parser<'a> {
-> (ast::Item_, Vec<ast::Attribute> ) { -> (ast::Item_, Vec<ast::Attribute> ) {
let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm
.span_to_filename(self.span)); .span_to_filename(self.span));
// FIXME(acrichto): right now "a".pop() == "a", but need to confirm with
// aturon whether this is expected or not.
if prefix.parent().is_some() {
prefix.pop(); prefix.pop();
} else {
prefix = PathBuf::new("");
}
let mut dir_path = prefix; let mut dir_path = prefix;
for part in &self.mod_path_stack { for part in &self.mod_path_stack {
dir_path.push(&**part); dir_path.push(&**part);

View File

@ -25,6 +25,7 @@ use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
#[allow(deprecated)]
use std::old_path::BytesContainer; use std::old_path::BytesContainer;
use std::rc::Rc; use std::rc::Rc;
@ -638,6 +639,7 @@ impl Deref for InternedString {
fn deref(&self) -> &str { &*self.string } fn deref(&self) -> &str { &*self.string }
} }
#[allow(deprecated)]
impl BytesContainer for InternedString { impl BytesContainer for InternedString {
fn container_as_bytes<'a>(&'a self) -> &'a [u8] { fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
// FIXME #12938: This is a workaround for the incorrect signature // FIXME #12938: This is a workaround for the incorrect signature

View File

@ -57,7 +57,6 @@
#![feature(int_uint)] #![feature(int_uint)]
#![feature(io)] #![feature(io)]
#![feature(old_io)] #![feature(old_io)]
#![feature(path)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(std_misc)] #![feature(std_misc)]

View File

@ -40,7 +40,6 @@
#![feature(core)] #![feature(core)]
#![feature(int_uint)] #![feature(int_uint)]
#![feature(old_io)] #![feature(old_io)]
#![feature(path)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(std_misc)] #![feature(std_misc)]

View File

@ -14,7 +14,6 @@
#![feature(exit_status)] #![feature(exit_status)]
#![feature(io)] #![feature(io)]
#![feature(old_io)] #![feature(old_io)]
#![feature(path)]
#![feature(rustdoc)] #![feature(rustdoc)]
#![feature(rustc_private)] #![feature(rustc_private)]