Skip to content

Rollup of 8 pull requests #41383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
99f5c85
rustc: ban registering obligations during InferCtxt snapshots.
eddyb Apr 15, 2017
e56b119
rustc_typeck: keep register_infer_ok_obligations calls out of snapshots.
eddyb Apr 15, 2017
2ad1964
rustc_typeck: Autoderef::finalize is always called with one &hir::Expr.
eddyb Apr 15, 2017
516570f
rustc_typeck: move some obligation methods to Inherited.
eddyb Apr 15, 2017
3725cab
rustc_typeck: return InferOk from lookup_method_in_trait_adjusted.
eddyb Apr 15, 2017
1afe77f
Cleaned up throughout std::path's docs
Apr 15, 2017
cd64ff9
rustc_typeck: fix binops needing more type informations to coerce.
eddyb Apr 16, 2017
8c21b60
Expand and add examples to std::path::{Prefix, PrefixComponent}'s docs
Apr 16, 2017
51ca5fe
Restructure and redistribute std::path's module docs
Apr 17, 2017
32132d9
Expand std::path::Display's docs
Apr 17, 2017
d6f7577
Fix typos in std::path's docs
Apr 18, 2017
2c9d756
Run tests for the cargo submodule in tree
alexcrichton Apr 18, 2017
43d92bb
update mdbook
steveklabnik Apr 18, 2017
0a69bf4
Bump stage0 to fix ARM LLVM
cuviper Apr 18, 2017
6383de1
fixes #40013
Apr 11, 2017
8b45a21
comment out removed error codes
Apr 18, 2017
3092ac4
change note for patterns
Apr 18, 2017
cba0c6a
rustc_trans: do not treat byval as using up registers.
eddyb Apr 18, 2017
19da9bb
Add top level sections to the Unstable Book.
frewsxcv Apr 13, 2017
19851f4
Bump book and reference.
frewsxcv Apr 17, 2017
b9f5f91
Rollup merge of #41236 - cengizIO:master, r=nikomatsakis
frewsxcv Apr 18, 2017
0f38011
Rollup merge of #41295 - frewsxcv:frewsxcxv-unstability, r=steveklabnik
frewsxcv Apr 18, 2017
4882a74
Rollup merge of #41325 - eddyb:isolate-snapshots-for-good, r=arielb1
frewsxcv Apr 18, 2017
b739b56
Rollup merge of #41348 - lukaramu:std-path-docs, r=frewsxcv
frewsxcv Apr 18, 2017
c1634ba
Rollup merge of #41362 - alexcrichton:run-cargot-ests, r=aturon
frewsxcv Apr 18, 2017
1093d5e
Rollup merge of #41369 - cuviper:arm-stage0, r=alexcrichton
frewsxcv Apr 18, 2017
a919245
Rollup merge of #41374 - steveklabnik:update-mdbook, r=frewsxcv
frewsxcv Apr 18, 2017
933cf2c
Rollup merge of #41378 - eddyb:byval-is-not-like-sret, r=arielb1
frewsxcv Apr 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restructure and redistribute std::path's module docs
Part of #29368.
* Added a new summary paragraph about std::path's parsing facilities
* Slightly exanded `Component`'s docs
* removed the now redundant section on component types from the module docs
* moved the section on path normalization during parsing to the docs on
  `Path::components`
* Clarified difference between `Prefix` and `PrefixComponent` in their
  respecive summary sentences
  • Loading branch information
lukaramu committed Apr 17, 2017
commit 51ca5fe716c48b2dd4adbe4e2379d952b60afca8
119 changes: 55 additions & 64 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@

//! Cross-platform path manipulation.
//!
//! This module provides two types, [`PathBuf`] and [`Path`][`Path`] (akin to [`String`]
//! This module provides two types, [`PathBuf`] and [`Path`] (akin to [`String`]
//! and [`str`]), for working with paths abstractly. These types are thin wrappers
//! around [`OsString`] and [`OsStr`] respectively, meaning that they work directly
//! on strings according to the local platform's path syntax.
//!
//! Paths can be parsed into [`Component`]s by iterating over the structure
//! returned by the [`components`] method on [`Path`]. [`Component`]s roughly
//! correspond to the substrings between path separators (`/` or `\`). You can
//! reconstruct an equivalent path from components with the [`push`] method on
//! [`PathBuf`]; note that the paths may differ syntactically by the
//! normalization described in the documentation for the [`components`] method.
//!
//! ## Simple usage
//!
//! Path manipulation includes both parsing components from slices and building
Expand Down Expand Up @@ -50,62 +57,11 @@
//! path.set_extension("dll");
//! ```
//!
//! ## Path components and normalization
//!
//! The path APIs are built around the notion of "components", which roughly
//! correspond to the substrings between path separators (`/` and, on Windows,
//! `\`). The APIs for path parsing are largely specified in terms of the path's
//! components, so it's important to clearly understand how those are
//! determined.
//!
//! A path can always be reconstructed into an *equivalent* path by
//! putting together its components via `push`. Syntactically, the
//! paths may differ by the normalization described below.
//!
//! ### Component types
//!
//! Components come in several types:
//!
//! * Normal components are the default: standard references to files or
//! directories. The path `a/b` has two normal components, `a` and `b`.
//!
//! * Current directory components represent the `.` character. For example,
//! `./a` has a current directory component and a normal component `a`.
//!
//! * The root directory component represents a separator that designates
//! starting from root. For example, `/a/b` has a root directory component
//! followed by normal components `a` and `b`.
//!
//! On Windows, an additional component type comes into play:
//!
//! * Prefix components, of which there is a large variety. For example, `C:`
//! and `\\server\share` are prefixes. The path `C:windows` has a prefix
//! component `C:` and a normal component `windows`; the path `C:\windows` has a
//! prefix component `C:`, a root directory component, and a normal component
//! `windows`.
//!
//! ### Normalization
//!
//! Aside from splitting on the separator(s), there is a small amount of
//! "normalization":
//!
//! * Repeated separators are ignored: `a/b` and `a//b` both have components `a`
//! and `b`.
//!
//! * Occurrences of `.` are normalized away, *except* if they are at
//! the beginning of the path (in which case they are often meaningful
//! in terms of path searching). So, for example, `a/./b`, `a/b/`,
//! `/a/b/.` and `a/b` all have components `a` and `b`, but `./a/b`
//! has a leading current directory component.
//!
//! No other normalization takes place by default. In particular,
//! `a/c` and `a/b/../c` are distinct, to account for the possibility
//! that `b` is a symbolic link (so its parent isn't `a`). Further
//! normalization is possible to build on top of the components APIs,
//! and will be included in this library in the near future.
//!
//! [`Component`]: ../../std/path/enum.Component.html
//! [`components`]: ../../std/path/struct.Path.html#method.components
//! [`PathBuf`]: ../../std/path/struct.PathBuf.html
//! [`Path`]: ../../std/path/struct.Path.html
//! [`push`]: ../../std/path/struct.PathBuf.html#method.push
//! [`String`]: ../../std/string/struct.String.html
//! [`str`]: ../../std/primitive.str.html
//! [`OsString`]: ../../std/ffi/struct.OsString.html
Expand Down Expand Up @@ -143,7 +99,7 @@ use sys::path::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix};
// Windows Prefixes
////////////////////////////////////////////////////////////////////////////////

/// Path prefixes (Windows only).
/// Windows path prefixes, e.g. `C:` or `\\server\share`.
///
/// Windows uses a variety of path prefix styles, including references to drive
/// volumes (like `C:`), network shared folders (like `\\server\share`), and
Expand Down Expand Up @@ -415,7 +371,8 @@ enum State {
Done = 3,
}

/// A Windows path prefix, e.g. `C:` or `\\server\share`.
/// A structure wrapping a Windows path prefix as well as its unparsed string
/// representation.
///
/// In addition to the parsed [`Prefix`] information returned by [`kind`],
/// `PrefixComponent` also holds the raw and unparsed [`OsStr`] slice,
Expand Down Expand Up @@ -511,11 +468,11 @@ impl<'a> Hash for PrefixComponent<'a> {

/// A single component of a path.
///
/// See the module documentation for an in-depth explanation of components and
/// their role in the API.
/// A `Component` roughtly corresponds to a substring between path separators
/// (`/` or `\`).
///
/// This `enum` is created from iterating over the [`path::Components`]
/// `struct`.
/// This `enum` is created by iterating over [`Components`], which in turn is
/// created by the [`components`][`Path::components`] method on [`Path`].
///
/// # Examples
///
Expand All @@ -532,19 +489,28 @@ impl<'a> Hash for PrefixComponent<'a> {
/// ]);
/// ```
///
/// [`path::Components`]: struct.Components.html
/// [`Components`]: struct.Components.html
/// [`Path`]: struct.Path.html
/// [`Path::components`]: struct.Path.html#method.components
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Component<'a> {
/// A Windows path prefix, e.g. `C:` or `\\server\share`.
///
/// There is a large variety of prefix types, see [`Prefix`]'s documentation
/// for more.
///
/// Does not occur on Unix.
///
/// [`Prefix`]: enum.Prefix.html
#[stable(feature = "rust1", since = "1.0.0")]
Prefix(
#[stable(feature = "rust1", since = "1.0.0")] PrefixComponent<'a>
),

/// The root directory component, appears after any prefix and before anything else.
///
/// It represents a deperator that designates that a path starts from root.
#[stable(feature = "rust1", since = "1.0.0")]
RootDir,

Expand All @@ -557,6 +523,9 @@ pub enum Component<'a> {
ParentDir,

/// A normal component, e.g. `a` and `b` in `a/b`.
///
/// This variant is the most common one, it represents references to files
/// or directories.
#[stable(feature = "rust1", since = "1.0.0")]
Normal(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr),
}
Expand Down Expand Up @@ -1992,7 +1961,21 @@ impl Path {
buf
}

/// Produces an iterator over the components of the path.
/// Produces an iterator over the [`Component`]s of the path.
///
/// When parsing the path, there is a small amount of normalization:
///
/// * Repeated seperators are ignored, so `a/b` and `a//b` both have
/// `a` and `b` as components.
///
/// * Occurentces of `.` are normalized away, exept if they are at the
/// beginning of the path. For example, `a/./b`, `a/b/`, `a/b/.` and
/// `a/b` all have `a` and `b` as components, but `./a/b` starts with
/// an additional [`CurDir`] component.
///
/// Note that no other normalization takes place; in particular, `a/c`
/// and `a/b/../c` are distinct, to account for the possibility that `b`
/// is a symbolic link (so its parent isn't `a`).
///
/// # Examples
///
Expand All @@ -2007,6 +1990,9 @@ impl Path {
/// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
/// assert_eq!(components.next(), None)
/// ```
///
/// [`Component`]: enum.Component.html
/// [`CurDir`]: enum.Component.html#variant.CurDir
#[stable(feature = "rust1", since = "1.0.0")]
pub fn components(&self) -> Components {
let prefix = parse_prefix(self.as_os_str());
Expand All @@ -2019,8 +2005,13 @@ impl Path {
}
}

/// Produces an iterator over the path's components viewed as [`OsStr`] slices.
/// Produces an iterator over the path's components viewed as [`OsStr`]
/// slices.
///
/// For more information about the particulars of how the path is separated
/// into components, see [`components`].
///
/// [`components`]: #method.components
/// [`OsStr`]: ../ffi/struct.OsStr.html
///
/// # Examples
Expand Down