Skip to content

Commit 0afc16a

Browse files
committed
Deprecate std::env::home_dir and fix incorrect documentation
1 parent 90c921e commit 0afc16a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/libstd/env.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -512,18 +512,20 @@ impl Error for JoinPathsError {
512512
///
513513
/// # Unix
514514
///
515-
/// Returns the value of the 'HOME' environment variable if it is set
516-
/// and not equal to the empty string. Otherwise, it tries to determine the
517-
/// home directory by invoking the `getpwuid_r` function on the UID of the
518-
/// current user.
515+
/// - Returns the value of the 'HOME' environment variable if it is set
516+
/// (including to an empty string).
517+
/// - Otherwise, it tries to determine the home directory by invoking the `getpwuid_r` function
518+
/// using the UID of the current user. An empty home directory field returned from the
519+
/// `getpwuid_r` function is considered to be a valid value.
520+
/// - Returns `None` if the current user has no entry in the /etc/passwd file.
519521
///
520522
/// # Windows
521523
///
522-
/// Returns the value of the 'HOME' environment variable if it is
523-
/// set and not equal to the empty string. Otherwise, returns the value of the
524-
/// 'USERPROFILE' environment variable if it is set and not equal to the empty
525-
/// string. If both do not exist, [`GetUserProfileDirectory`][msdn] is used to
526-
/// return the appropriate path.
524+
/// - Returns the value of the 'HOME' environment variable if it is set
525+
/// (including to an empty string).
526+
/// - Otherwise, returns the value of the 'USERPROFILE' environment variable if it is set
527+
/// (including to an empty string).
528+
/// - If both do not exist, [`GetUserProfileDirectory`][msdn] is used to return the path.
527529
///
528530
/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx
529531
///
@@ -533,10 +535,13 @@ impl Error for JoinPathsError {
533535
/// use std::env;
534536
///
535537
/// match env::home_dir() {
536-
/// Some(path) => println!("{}", path.display()),
538+
/// Some(path) => println!("Your home directory, probably: {}", path.display()),
537539
/// None => println!("Impossible to get your home dir!"),
538540
/// }
539541
/// ```
542+
#[rustc_deprecated(since = "1.29.0",
543+
reason = "This function's behavior is unexpected and probably not what you want. \
544+
Consider using the home_dir function from crates.io/crates/dirs instead.")]
540545
#[stable(feature = "env", since = "1.0.0")]
541546
pub fn home_dir() -> Option<PathBuf> {
542547
os_imp::home_dir()

0 commit comments

Comments
 (0)