From fb195600541c67f91cd6aed5c1d00aa4668ad9c3 Mon Sep 17 00:00:00 2001 From: Dylan Maccora Date: Thu, 18 May 2017 18:26:47 +1000 Subject: std::env docs --- src/libstd/env.rs | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 64eb52e28bc..061525205ef 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -13,6 +13,13 @@ //! This module contains functions to inspect various aspects such as //! environment variables, process arguments, the current directory, and various //! other important directories. +//! +//! There are several functions and structs in this module that have a +//! counterpart ending in `os`. Those ending in `os` will return an [`OsString`] +//! and those without will be returning a [`String`]. +//! +//! [`OsString`]: ../../std/ffi/struct.OsString.html +//! [`String`]: ../string/struct.String.html #![stable(feature = "env", since = "1.0.0")] @@ -71,7 +78,8 @@ pub fn set_current_dir>(p: P) -> io::Result<()> { /// An iterator over a snapshot of the environment variables of this process. /// -/// This structure is created through the [`std::env::vars`] function. +/// This structure is created by the [`std::env::vars`] function. See its +/// documentation for more. /// /// [`std::env::vars`]: fn.vars.html #[stable(feature = "env", since = "1.0.0")] @@ -79,7 +87,8 @@ pub struct Vars { inner: VarsOs } /// An iterator over a snapshot of the environment variables of this process. /// -/// This structure is created through the [`std::env::vars_os`] function. +/// This structure is created by the [`std::env::vars_os`] function. See +/// its documentation for more. /// /// [`std::env::vars_os`]: fn.vars_os.html #[stable(feature = "env", since = "1.0.0")] @@ -173,12 +182,10 @@ impl fmt::Debug for VarsOs { /// Fetches the environment variable `key` from the current process. /// -/// The returned result is [`Ok(s)`] if the environment variable is present and is -/// valid unicode. If the environment variable is not present, or it is not -/// valid unicode, then [`Err`] will be returned. +/// # Errors /// -/// [`Ok(s)`]: ../result/enum.Result.html#variant.Ok -/// [`Err`]: ../result/enum.Result.html#variant.Err +/// * Environment variable is not present +/// * Environment variable is not valid unicode /// /// # Examples /// @@ -230,7 +237,8 @@ fn _var_os(key: &OsStr) -> Option { }) } -/// Possible errors from the [`env::var`] function. +/// The error type for operations interacting with environment variables. +/// Possibly returned from the [`env::var`] function. /// /// [`env::var`]: fn.var.html #[derive(Debug, PartialEq, Eq, Clone)] @@ -353,10 +361,13 @@ fn _remove_var(k: &OsStr) { }) } -/// An iterator over `PathBuf` instances for parsing an environment variable -/// according to platform-specific conventions. +/// An iterator that splits an environment variable into paths according to +/// platform-specific conventions. /// -/// This structure is returned from `std::env::split_paths`. +/// This structure is created by the [`std::env::split_paths`] function See its +/// documentation for more. +/// +/// [`std::env::split_paths`]: fn.split_paths.html #[stable(feature = "env", since = "1.0.0")] pub struct SplitPaths<'a> { inner: os_imp::SplitPaths<'a> } @@ -399,8 +410,10 @@ impl<'a> fmt::Debug for SplitPaths<'a> { } } -/// Error type returned from `std::env::join_paths` when paths fail to be -/// joined. +/// The error type for operations on the `PATH` variable. Possibly returned from +/// the [`env::join_paths`] function. +/// +/// [`env::join_paths`]: fn.join_paths.html #[derive(Debug)] #[stable(feature = "env", since = "1.0.0")] pub struct JoinPathsError { @@ -410,15 +423,15 @@ pub struct JoinPathsError { /// Joins a collection of [`Path`]s appropriately for the `PATH` /// environment variable. /// -/// Returns an [`OsString`] on success. +/// # Errors /// -/// Returns an [`Err`][err] (containing an error message) if one of the input +/// Returns an [`Err`] (containing an error message) if one of the input /// [`Path`]s contains an invalid character for constructing the `PATH` /// variable (a double quote on Windows or a colon on Unix). /// /// [`Path`]: ../../std/path/struct.Path.html /// [`OsString`]: ../../std/ffi/struct.OsString.html -/// [err]: ../../std/result/enum.Result.html#variant.Err +/// [`Err`]: ../../std/result/enum.Result.html#variant.Err /// /// # Examples /// @@ -490,12 +503,16 @@ pub fn home_dir() -> Option { /// Returns the path of a temporary directory. /// -/// On Unix, returns the value of the `TMPDIR` environment variable if it is +/// # Unix +/// +/// Returns the value of the `TMPDIR` environment variable if it is /// set, otherwise for non-Android it returns `/tmp`. If Android, since there /// is no global temporary folder (it is usually allocated per-app), it returns /// `/data/local/tmp`. /// -/// On Windows, returns the value of, in order, the `TMP`, `TEMP`, +/// # Windows +/// +/// Returns the value of, in order, the `TMP`, `TEMP`, /// `USERPROFILE` environment variable if any are set and not the empty /// string. Otherwise, `temp_dir` returns the path of the Windows directory. /// This behavior is identical to that of [`GetTempPath`][msdn], which this -- cgit 1.4.1-3-g733a5 From b69b6413afc770a8652096e8753d77eeb99b23bb Mon Sep 17 00:00:00 2001 From: Dylan Maccora Date: Sat, 20 May 2017 08:32:10 +1000 Subject: Fixed link issue. --- src/libstd/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 061525205ef..40ed5b5e1c0 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -425,13 +425,13 @@ pub struct JoinPathsError { /// /// # Errors /// -/// Returns an [`Err`] (containing an error message) if one of the input +/// Returns an [`Err`][err] (containing an error message) if one of the input /// [`Path`]s contains an invalid character for constructing the `PATH` /// variable (a double quote on Windows or a colon on Unix). /// /// [`Path`]: ../../std/path/struct.Path.html /// [`OsString`]: ../../std/ffi/struct.OsString.html -/// [`Err`]: ../../std/result/enum.Result.html#variant.Err +/// [err]: ../../std/result/enum.Result.html#variant.Err /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 6119f9856cd7ed514656c19b56da65ea7bd7dd0a Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Sat, 20 May 2017 15:32:11 -0400 Subject: Remove unused lifetimes. --- src/libstd/ffi/os_str.rs | 2 +- src/libstd/path.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index eaf0502a577..f497734e249 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -530,7 +530,7 @@ impl<'a> From<&'a OsStr> for Box { } #[stable(feature = "os_string_from_box", since = "1.18.0")] -impl<'a> From> for OsString { +impl From> for OsString { fn from(boxed: Box) -> OsString { boxed.into_os_string() } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e7d8c3007f6..e128a4164d7 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1342,7 +1342,7 @@ impl<'a> From<&'a Path> for Box { } #[stable(feature = "path_buf_from_box", since = "1.18.0")] -impl<'a> From> for PathBuf { +impl From> for PathBuf { fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } -- cgit 1.4.1-3-g733a5 From e847d46bcb01c71e18610eeb30db6f2b6a7f3214 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Wed, 10 May 2017 13:13:42 -0400 Subject: migrate everything to using mem::needs_drop --- src/libarena/lib.rs | 9 ++++----- src/libstd/collections/hash/table.rs | 3 +-- src/libstd/lib.rs | 1 + src/libstd/sys/redox/fast_thread_local.rs | 7 ++++--- src/libstd/sys/unix/fast_thread_local.rs | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index c4c1635aa2a..4338ac7fd02 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -32,6 +32,7 @@ #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(generic_param_attrs)] +#![feature(needs_drop)] #![cfg_attr(stage0, feature(staged_api))] #![cfg_attr(test, feature(test))] @@ -82,7 +83,7 @@ impl TypedArenaChunk { unsafe fn destroy(&mut self, len: usize) { // The branch on needs_drop() is an -O1 performance optimization. // Without the branch, dropping TypedArena takes linear time. - if intrinsics::needs_drop::() { + if mem::needs_drop::() { let mut start = self.start(); // Destroy all allocated objects. for _ in 0..len { @@ -350,7 +351,7 @@ impl DroplessArena { #[inline] pub fn alloc(&self, object: T) -> &mut T { unsafe { - assert!(!intrinsics::needs_drop::()); + assert!(!mem::needs_drop::()); assert!(mem::size_of::() != 0); self.align_for::(); @@ -379,9 +380,7 @@ impl DroplessArena { #[inline] pub fn alloc_slice(&self, slice: &[T]) -> &mut [T] where T: Copy { - unsafe { - assert!(!intrinsics::needs_drop::()); - } + assert!(!mem::needs_drop::()); assert!(mem::size_of::() != 0); assert!(slice.len() != 0); self.align_for::(); diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index a15269cc87c..50c721db849 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -12,9 +12,8 @@ use alloc::heap::{allocate, deallocate}; use cmp; use hash::{BuildHasher, Hash, Hasher}; -use intrinsics::needs_drop; use marker; -use mem::{align_of, size_of}; +use mem::{align_of, size_of, needs_drop}; use mem; use ops::{Deref, DerefMut}; use ptr::{self, Unique, Shared}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a4c3b276efd..b0820d6f05a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -281,6 +281,7 @@ #![feature(linkage)] #![feature(macro_reexport)] #![feature(needs_panic_runtime)] +#![feature(needs_drop)] #![feature(never_type)] #![feature(num_bits_bytes)] #![feature(old_wrapping)] diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index f6414673dac..7dc61ce6654 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -12,9 +12,10 @@ #![unstable(feature = "thread_local_internals", issue = "0")] use cell::{Cell, UnsafeCell}; -use intrinsics; +use mem; use ptr; + pub struct Key { inner: UnsafeCell>, @@ -37,7 +38,7 @@ impl Key { pub fn get(&'static self) -> Option<&'static UnsafeCell>> { unsafe { - if intrinsics::needs_drop::() && self.dtor_running.get() { + if mem::needs_drop::() && self.dtor_running.get() { return None } self.register_dtor(); @@ -46,7 +47,7 @@ impl Key { } unsafe fn register_dtor(&self) { - if !intrinsics::needs_drop::() || self.dtor_registered.get() { + if !mem::needs_drop::() || self.dtor_registered.get() { return } diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index 07d76a93dd1..6b3973de84c 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -13,7 +13,7 @@ use cell::{Cell, UnsafeCell}; use fmt; -use intrinsics; +use mem; use ptr; pub struct Key { @@ -44,7 +44,7 @@ impl Key { pub fn get(&'static self) -> Option<&'static UnsafeCell>> { unsafe { - if intrinsics::needs_drop::() && self.dtor_running.get() { + if mem::needs_drop::() && self.dtor_running.get() { return None } self.register_dtor(); @@ -53,7 +53,7 @@ impl Key { } unsafe fn register_dtor(&self) { - if !intrinsics::needs_drop::() || self.dtor_registered.get() { + if !mem::needs_drop::() || self.dtor_registered.get() { return } -- cgit 1.4.1-3-g733a5