Skip to content

Commit 98baef0

Browse files
committed
doc: link to GlobalContext item
1 parent d090365 commit 98baef0

File tree

10 files changed

+46
-37
lines changed

10 files changed

+46
-37
lines changed

src/bin/cargo/cli.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
2525

2626
// Update the process-level notion of cwd
2727
if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") {
28-
// This is a temporary hack. This cannot access `Config`, so this is a bit messy.
28+
// This is a temporary hack.
29+
// This cannot access `GlobalContext`, so this is a bit messy.
2930
// This does not properly parse `-Z` flags that appear after the subcommand.
3031
// The error message is not as helpful as the standard one.
3132
let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev");

src/bin/cargo/commands/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
111111
// In general, we try to avoid normalizing paths in Cargo,
112112
// but in these particular cases we need it to fix rust-lang/cargo#10283.
113113
// (Handle `SourceId::for_path` and `Workspace::new`,
114-
// but not `Config::reload_rooted_at` which is always cwd)
114+
// but not `GlobalContext::reload_rooted_at` which is always cwd)
115115
let path = path.map(|p| paths::normalize_path(&p));
116116

117117
let version = args.get_one::<VersionReq>("version");

src/cargo/core/compiler/job_queue/job_state.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ pub struct JobState<'a, 'gctx> {
2828
/// output messages are processed on the same thread as they are sent from. `output`
2929
/// defines where to output in this case.
3030
///
31-
/// Currently the `Shell` inside `Config` is wrapped in a `RefCell` and thus can't be passed
32-
/// between threads. This means that it isn't possible for multiple output messages to be
33-
/// interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case
31+
/// Currently the [`Shell`] inside [`GlobalContext`] is wrapped in a `RefCell` and thus can't
32+
/// be passed between threads. This means that it isn't possible for multiple output messages
33+
/// to be interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case
3434
/// interleaving is still prevented as the lock would be held for the whole printing of an
3535
/// output message.
36+
///
37+
/// [`Shell`]: crate::core::Shell
38+
/// [`GlobalContext`]: crate::GlobalContext
3639
output: Option<&'a DiagDedupe<'gctx>>,
3740

3841
/// The job id that this state is associated with, used when sending

src/cargo/sources/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'gctx> SourceConfigMap<'gctx> {
120120
Ok(base)
121121
}
122122

123-
/// Returns the `Config` this source config map is associated with.
123+
/// Returns the [`GlobalContext`] this source config map is associated with.
124124
pub fn gctx(&self) -> &'gctx GlobalContext {
125125
self.gctx
126126
}

src/cargo/util/cache_lock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! There is a global [`CacheLocker`] held inside cargo's venerable
1010
//! [`GlobalContext`]. The `CacheLocker` manages creating and tracking the locks
11-
//! being held. There are methods on `Config` for managing the locks:
11+
//! being held. There are methods on [`GlobalContext`] for managing the locks:
1212
//!
1313
//! - [`GlobalContext::acquire_package_cache_lock`] --- Acquires a lock. May block if
1414
//! another process holds a lock.
@@ -468,7 +468,7 @@ pub struct CacheLocker {
468468
/// The state of the locker.
469469
///
470470
/// [`CacheLocker`] uses interior mutability because it is stuffed inside
471-
/// the global `Config`, which does not allow mutation.
471+
/// [`GlobalContext`], which does not allow mutation.
472472
state: RefCell<CacheState>,
473473
}
474474

src/cargo/util/config/de.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::HashSet;
88
use std::vec;
99

1010
/// Serde deserializer used to convert config values to a target type using
11-
/// `Config::get`.
11+
/// [`GlobalContext::get`].
1212
#[derive(Clone)]
1313
pub(super) struct Deserializer<'gctx> {
1414
pub(super) gctx: &'gctx GlobalContext,

src/cargo/util/config/environment.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ fn make_case_insensitive_and_normalized_env(
2828
(case_insensitive_env, normalized_env)
2929
}
3030

31-
/// A snapshot of the environment variables available to [`super::GlobalContext`].
31+
/// A snapshot of the environment variables available to [`GlobalContext`].
3232
///
33-
/// Currently, the [`Context`](super::GlobalContext) supports lookup of environment variables
33+
/// Currently, the [`GlobalContext`] supports lookup of environment variables
3434
/// through two different means:
3535
///
36-
/// - [`Context::get_env`](super::GlobalContext::get_env)
37-
/// and [`Context::get_env_os`](super::GlobalContext::get_env_os)
36+
/// - [`GlobalContext::get_env`](super::GlobalContext::get_env)
37+
/// and [`GlobalContext::get_env_os`](super::GlobalContext::get_env_os)
3838
/// for process environment variables (similar to [`std::env::var`] and [`std::env::var_os`]),
39-
/// - Typed Config Value API via [`Context::get`](super::GlobalContext::get).
39+
/// - Typed Config Value API via [`GlobalContext::get`](super::GlobalContext::get).
4040
/// This is only available for `CARGO_` prefixed environment keys.
4141
///
4242
/// This type contains the env var snapshot and helper methods for both APIs.
43+
///
44+
/// [`GlobalContext`]: super::GlobalContext
4345
#[derive(Debug)]
4446
pub struct Env {
4547
/// A snapshot of the process's environment variables.
@@ -68,8 +70,8 @@ impl Env {
6870
pub fn new() -> Self {
6971
// ALLOWED: This is the only permissible usage of `std::env::vars{_os}`
7072
// within cargo. If you do need access to individual variables without
71-
// interacting with `Config` system, please use `std::env::var{_os}`
72-
// and justify the validity of the usage.
73+
// interacting with the config system in [`GlobalContext`], please use
74+
// `std::env::var{_os}` and justify the validity of the usage.
7375
#[allow(clippy::disallowed_methods)]
7476
let env: HashMap<_, _> = std::env::vars_os().collect();
7577
let (case_insensitive_env, normalized_env) = make_case_insensitive_and_normalized_env(&env);
@@ -105,9 +107,10 @@ impl Env {
105107
self.env.keys().filter_map(|k| k.to_str())
106108
}
107109

108-
/// Get the value of environment variable `key` through the `Config` snapshot.
110+
/// Get the value of environment variable `key` through the snapshot in
111+
/// [`GlobalContext`](super::GlobalContext).
109112
///
110-
/// This can be used similarly to `std::env::var_os`.
113+
/// This can be used similarly to [`std::env::var_os`].
111114
/// On Windows, we check for case mismatch since environment keys are case-insensitive.
112115
pub fn get_env_os(&self, key: impl AsRef<OsStr>) -> Option<OsString> {
113116
match self.env.get(key.as_ref()) {
@@ -152,7 +155,7 @@ impl Env {
152155
/// Get the value of environment variable `key` as a `&str`.
153156
/// Returns `None` if `key` is not in `self.env` or if the value is not valid UTF-8.
154157
///
155-
/// This is intended for use in private methods of `Config`,
158+
/// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext),
156159
/// and does not check for env key case mismatch.
157160
///
158161
/// This is case-sensitive on Windows (even though environment keys on Windows are usually
@@ -172,7 +175,7 @@ impl Env {
172175

173176
/// Check if the environment contains `key`.
174177
///
175-
/// This is intended for use in private methods of `Config`,
178+
/// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext),
176179
/// and does not check for env key case mismatch.
177180
/// See the docstring of [`Env::get_str`] for more context.
178181
pub(super) fn contains_key(&self, key: impl AsRef<OsStr>) -> bool {

src/cargo/util/config/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Cargo's config system.
22
//!
3-
//! The `Config` object contains general information about the environment,
3+
//! The [`GlobalContext`] object contains general information about the environment,
44
//! and provides access to Cargo's configuration files.
55
//!
66
//! ## Config value API
77
//!
88
//! The primary API for fetching user-defined config values is the
9-
//! `Config::get` method. It uses `serde` to translate config values to a
9+
//! [`GlobalContext::get`] method. It uses `serde` to translate config values to a
1010
//! target type.
1111
//!
1212
//! There are a variety of helper types for deserializing some common formats:
@@ -329,7 +329,7 @@ impl GlobalContext {
329329
}
330330
}
331331

332-
/// Creates a new Config instance, with all default settings.
332+
/// Creates a new instance, with all default settings.
333333
///
334334
/// This does only minimal initialization. In particular, it does not load
335335
/// any config files from disk. Those will be loaded lazily as-needed.
@@ -811,16 +811,18 @@ impl GlobalContext {
811811
}
812812
}
813813

814-
/// Get the value of environment variable `key` through the `Config` snapshot.
814+
/// Get the value of environment variable `key` through the snapshot in
815+
/// [`GlobalContext`](super::GlobalContext).
815816
///
816-
/// This can be used similarly to `std::env::var`.
817+
/// This can be used similarly to [`std::env::var`].
817818
pub fn get_env(&self, key: impl AsRef<OsStr>) -> CargoResult<String> {
818819
self.env.get_env(key)
819820
}
820821

821-
/// Get the value of environment variable `key` through the `Config` snapshot.
822+
/// Get the value of environment variable `key` through the snapshot in
823+
/// [`GlobalContext`](super::GlobalContext).
822824
///
823-
/// This can be used similarly to `std::env::var_os`.
825+
/// This can be used similarly to [`std::env::var_os`].
824826
pub fn get_env_os(&self, key: impl AsRef<OsStr>) -> Option<OsString> {
825827
self.env.get_env_os(key)
826828
}
@@ -1001,7 +1003,7 @@ impl GlobalContext {
10011003
.map_err(|e| anyhow!("invalid configuration for key `{}`\n{}", key, e))
10021004
}
10031005

1004-
/// Update the Config instance based on settings typically passed in on
1006+
/// Update the instance based on settings typically passed in on
10051007
/// the command-line.
10061008
///
10071009
/// This may also load the config from disk if it hasn't already been
@@ -1646,7 +1648,7 @@ impl GlobalContext {
16461648
///
16471649
/// The credentials are loaded into a separate field to enable them
16481650
/// to be lazy-loaded after the main configuration has been loaded,
1649-
/// without requiring `mut` access to the `Config`.
1651+
/// without requiring `mut` access to the [`GlobalContext`].
16501652
///
16511653
/// If the credentials are already loaded, this function does nothing.
16521654
pub fn load_credentials(&self) -> CargoResult<()> {

src/doc/contrib/src/implementation/console.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Console Output
22

33
All of Cargo's output should go through the [`Shell`] struct. You can normally
4-
obtain the `Shell` instance from the [`Config`] struct. Do **not** use the std
5-
`println!` macros.
4+
obtain the `Shell` instance from the [`GlobalContext`] struct. Do **not** use
5+
the std `println!` macros.
66

77
Most of Cargo's output goes to stderr. When running in JSON mode, the output
88
goes to stdout.
@@ -17,7 +17,7 @@ if they are unable to be displayed. This is generally automatically handled in
1717
the [`JobQueue`] as it processes each message.
1818

1919
[`Shell`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/shell.rs
20-
[`Config`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/config/mod.rs
20+
[`GlobalContext`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/config/mod.rs
2121
[`drop_print`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/src/cargo/util/config/mod.rs#L1820-L1848
2222
[`JobQueue`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/job_queue/mod.rs
2323

tests/testsuite/config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ impl GlobalContextBuilder {
8080
/// Sets the test root directory.
8181
///
8282
/// This generally should not be necessary. It is only useful if you want
83-
/// to create a `Config` from within a thread. Since Cargo's testsuite
84-
/// uses thread-local storage, this can be used to avoid accessing that
85-
/// thread-local storage.
83+
/// to create a [`GlobalContext`] from within a thread. Since Cargo's
84+
/// testsuite uses thread-local storage, this can be used to avoid accessing
85+
/// that thread-local storage.
8686
///
8787
/// Default is [`paths::root`].
8888
pub fn root(&mut self, path: impl Into<PathBuf>) -> &mut Self {
8989
self.root = Some(path.into());
9090
self
9191
}
9292

93-
/// Creates the `Config`.
93+
/// Creates the [`GlobalContext`].
9494
pub fn build(&self) -> GlobalContext {
9595
self.build_err().unwrap()
9696
}
9797

98-
/// Creates the `Config`, returning a Result.
98+
/// Creates the [`GlobalContext`], returning a Result.
9999
pub fn build_err(&self) -> CargoResult<GlobalContext> {
100100
let root = self.root.clone().unwrap_or_else(|| paths::root());
101101
let output = Box::new(fs::File::create(root.join("shell.out")).unwrap());

0 commit comments

Comments
 (0)