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(test)]
#![feature(core)]
#![feature(path)]
#![feature(io)]
#![feature(net)]
#![feature(path_ext)]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,9 +37,9 @@
#![feature(unicode)]
#![feature(str_words)]
#![feature(io)]
#![feature(path)]
#![feature(file_path)]
#![feature(path_ext)]
#![feature(path_relative_from)]
extern crate arena;
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.
///
/// 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 {
let mut default_passes = !matches.opt_present("no-defaults");
let mut passes = matches.opt_strs("passes");

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@
use prelude::v1::*;
use iter::IntoIterator;
use error::Error;
use ffi::{OsString, AsOsStr};
use fmt;
@ -338,9 +339,9 @@ pub struct JoinPathsError {
/// ```
#[stable(feature = "env", since = "1.0.0")]
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 }
})
}

View File

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

View File

@ -571,18 +571,8 @@ pub fn create_dir<P: AsPath + ?Sized>(path: &P) -> io::Result<()> {
pub fn create_dir_all<P: AsPath + ?Sized>(path: &P) -> io::Result<()> {
let path = path.as_path();
if path.is_dir() { return Ok(()) }
match path.parent() {
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)
}
if let Some(p) = path.parent() { try!(create_dir_all(p)) }
create_dir(path)
}
/// Remove an existing, empty directory

View File

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

View File

@ -29,6 +29,7 @@
#![allow(missing_docs)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(deprecated)]
use self::MemoryMapKind::*;
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 ffi::CString;
use num::Int;
#[allow(deprecated)]
use old_path::BytesContainer;
use collections;
pub mod backtrace;
@ -120,6 +123,7 @@ pub trait FromInner<Inner> {
}
#[doc(hidden)]
#[allow(deprecated)]
pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
fn program(&self) -> &CString;
fn args(&self) -> &[CString];

View File

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

View File

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

View File

@ -23,6 +23,7 @@
//! this takes the route of using StackWalk64 in order to walk the stack.
#![allow(dead_code)]
#![allow(deprecated)] // for old path for dynamic lib
use dynamic_lib::DynamicLibrary;
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() }
}
// Windows-specific extensions to `OsString`.
/// Windows-specific extensions to `OsString`.
pub trait OsStringExt {
/// 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 {
/// 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;
}

View File

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

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(deprecated)]
#![allow(deprecated)] // this module itself is essentially deprecated
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
if !arg.is_absolute() {
let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp));
if cu.parent().is_some() {
cu.pop();
} else {
cu = PathBuf::new("");
}
cu.pop();
cu.push(arg);
cu
} else {

View File

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

View File

@ -5254,13 +5254,7 @@ impl<'a> Parser<'a> {
-> (ast::Item_, Vec<ast::Attribute> ) {
let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm
.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();
} else {
prefix = PathBuf::new("");
}
prefix.pop();
let mut dir_path = prefix;
for part in &self.mod_path_stack {
dir_path.push(&**part);

View File

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

View File

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

View File

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

View File

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

View File

@ -23,4 +23,4 @@ pub fn generic_function<T: Clone>(val: T) -> (T, T) {
}
#[inline(never)]
fn zzz() {()}
fn zzz() {()}

View File

@ -11,4 +11,4 @@
#[foo] //~ ERROR The attribute `foo`
fn main() {
}
}