diff --git a/crates/mdman/src/hbs.rs b/crates/mdman/src/hbs.rs index dee0a2fff39..09726b83ce7 100644 --- a/crates/mdman/src/hbs.rs +++ b/crates/mdman/src/hbs.rs @@ -167,7 +167,7 @@ impl HelperDef for ManLinkHelper<'_> { &self, h: &Helper<'rc>, _r: &'reg Handlebars<'reg>, - _gctx: &'rc Context, + _ctx: &'rc Context, _rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output, ) -> HelperResult { @@ -200,7 +200,7 @@ impl HelperDef for ManLinkHelper<'_> { fn set_decorator( d: &Decorator<'_>, _: &Handlebars<'_>, - _gctx: &Context, + _ctx: &Context, rc: &mut RenderContext<'_, '_>, ) -> Result<(), RenderError> { let data_to_set = d.hash(); diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 3203f658c35..da9d56217a8 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -25,7 +25,8 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult { // Update the process-level notion of cwd if let Some(new_cwd) = args.get_one::("directory") { - // This is a temporary hack. This cannot access `Config`, so this is a bit messy. + // This is a temporary hack. + // This cannot access `GlobalContext`, so this is a bit messy. // This does not properly parse `-Z` flags that appear after the subcommand. // The error message is not as helpful as the standard one. let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev"); diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 86146098067..e188d6a0d67 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -111,7 +111,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { // In general, we try to avoid normalizing paths in Cargo, // but in these particular cases we need it to fix rust-lang/cargo#10283. // (Handle `SourceId::for_path` and `Workspace::new`, - // but not `Config::reload_rooted_at` which is always cwd) + // but not `GlobalContext::reload_rooted_at` which is always cwd) let path = path.map(|p| paths::normalize_path(&p)); let version = args.get_one::("version"); diff --git a/src/cargo/core/compiler/job_queue/job_state.rs b/src/cargo/core/compiler/job_queue/job_state.rs index fe3a79adb98..12c04258d3e 100644 --- a/src/cargo/core/compiler/job_queue/job_state.rs +++ b/src/cargo/core/compiler/job_queue/job_state.rs @@ -28,11 +28,14 @@ pub struct JobState<'a, 'gctx> { /// output messages are processed on the same thread as they are sent from. `output` /// defines where to output in this case. /// - /// Currently the `Shell` inside `Config` is wrapped in a `RefCell` and thus can't be passed - /// between threads. This means that it isn't possible for multiple output messages to be - /// interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case + /// Currently the [`Shell`] inside [`GlobalContext`] is wrapped in a `RefCell` and thus can't + /// be passed between threads. This means that it isn't possible for multiple output messages + /// to be interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case /// interleaving is still prevented as the lock would be held for the whole printing of an /// output message. + /// + /// [`Shell`]: crate::core::Shell + /// [`GlobalContext`]: crate::GlobalContext output: Option<&'a DiagDedupe<'gctx>>, /// The job id that this state is associated with, used when sending diff --git a/src/cargo/core/gc.rs b/src/cargo/core/gc.rs index 565cc3ec2d2..5f403e73426 100644 --- a/src/cargo/core/gc.rs +++ b/src/cargo/core/gc.rs @@ -86,8 +86,8 @@ fn auto_gc_inner(gctx: &GlobalContext) -> CargoResult<()> { debug_assert!(deferred.is_empty()); let mut global_cache_tracker = gctx.global_cache_tracker()?; let mut gc = Gc::new(gctx, &mut global_cache_tracker)?; - let mut clean_gctx = CleanContext::new(gctx); - gc.auto(&mut clean_gctx)?; + let mut clean_ctx = CleanContext::new(gctx); + gc.auto(&mut clean_ctx)?; Ok(()) } @@ -256,7 +256,7 @@ impl<'a, 'gctx> Gc<'a, 'gctx> { /// /// This returns immediately without doing work if garbage collection has /// been performed recently (since `gc.auto.frequency`). - fn auto(&mut self, clean_gctx: &mut CleanContext<'gctx>) -> CargoResult<()> { + fn auto(&mut self, clean_ctx: &mut CleanContext<'gctx>) -> CargoResult<()> { if !self.gctx.cli_unstable().gc { return Ok(()); } @@ -279,20 +279,16 @@ impl<'a, 'gctx> Gc<'a, 'gctx> { } let mut gc_opts = GcOpts::default(); gc_opts.update_for_auto_gc_config(&auto_config)?; - self.gc(clean_gctx, &gc_opts)?; - if !clean_gctx.dry_run { + self.gc(clean_ctx, &gc_opts)?; + if !clean_ctx.dry_run { self.global_cache_tracker.set_last_auto_gc()?; } Ok(()) } /// Performs garbage collection based on the given options. - pub fn gc( - &mut self, - clean_gctx: &mut CleanContext<'gctx>, - gc_opts: &GcOpts, - ) -> CargoResult<()> { - self.global_cache_tracker.clean(clean_gctx, gc_opts)?; + pub fn gc(&mut self, clean_ctx: &mut CleanContext<'gctx>, gc_opts: &GcOpts) -> CargoResult<()> { + self.global_cache_tracker.clean(clean_ctx, gc_opts)?; // In the future, other gc operations go here, such as target cleaning. Ok(()) } diff --git a/src/cargo/core/global_cache_tracker.rs b/src/cargo/core/global_cache_tracker.rs index e9c4856a742..bb9385b0a6d 100644 --- a/src/cargo/core/global_cache_tracker.rs +++ b/src/cargo/core/global_cache_tracker.rs @@ -547,22 +547,18 @@ impl GlobalCacheTracker { } /// Deletes files from the global cache based on the given options. - pub fn clean( - &mut self, - clean_gctx: &mut CleanContext<'_>, - gc_opts: &GcOpts, - ) -> CargoResult<()> { - self.clean_inner(clean_gctx, gc_opts) + pub fn clean(&mut self, clean_ctx: &mut CleanContext<'_>, gc_opts: &GcOpts) -> CargoResult<()> { + self.clean_inner(clean_ctx, gc_opts) .with_context(|| "failed to clean entries from the global cache") } fn clean_inner( &mut self, - clean_gctx: &mut CleanContext<'_>, + clean_ctx: &mut CleanContext<'_>, gc_opts: &GcOpts, ) -> CargoResult<()> { let _p = crate::util::profile::start("cleaning global cache files"); - let gctx = clean_gctx.gctx; + let gctx = clean_ctx.gctx; let base = BasePaths { index: gctx.registry_index_path().into_path_unlocked(), git_db: gctx.git_db_path().into_path_unlocked(), @@ -657,9 +653,9 @@ impl GlobalCacheTracker { Self::get_registry_items_to_clean_size_both(&tx, max_size, &base, &mut delete_paths)?; } - clean_gctx.remove_paths(&delete_paths)?; + clean_ctx.remove_paths(&delete_paths)?; - if clean_gctx.dry_run { + if clean_ctx.dry_run { tx.rollback()?; } else { tx.commit()?; diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index ececee32a16..5c5cf9dc5f4 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -70,7 +70,7 @@ impl From<(PackageId, ConflictReason)> for ActivateError { } pub(super) fn activation_error( - resolver_gctx: &ResolverContext, + resolver_ctx: &ResolverContext, registry: &mut dyn Registry, parent: &Summary, dep: &Dependency, @@ -81,7 +81,7 @@ pub(super) fn activation_error( let to_resolve_err = |err| { ResolveError::new( err, - resolver_gctx + resolver_ctx .parents .path_to_bottom(&parent.package_id()) .into_iter() @@ -95,7 +95,7 @@ pub(super) fn activation_error( let mut msg = format!("failed to select a version for `{}`.", dep.package_name()); msg.push_str("\n ... required by "); msg.push_str(&describe_path_in_context( - resolver_gctx, + resolver_ctx, &parent.package_id(), )); @@ -141,7 +141,7 @@ pub(super) fn activation_error( msg.push_str("`, but it conflicts with a previous package which links to `"); msg.push_str(link); msg.push_str("` as well:\n"); - msg.push_str(&describe_path_in_context(resolver_gctx, p)); + msg.push_str(&describe_path_in_context(resolver_ctx, p)); msg.push_str("\nOnly one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. "); msg.push_str("Try to adjust your dependencies so that only one package uses the `links = \""); msg.push_str(link); @@ -210,7 +210,7 @@ pub(super) fn activation_error( for (p, r) in &conflicting_activations { if let ConflictReason::Semver = r { msg.push_str("\n\n previously selected "); - msg.push_str(&describe_path_in_context(resolver_gctx, p)); + msg.push_str(&describe_path_in_context(resolver_ctx, p)); } } } @@ -279,7 +279,7 @@ pub(super) fn activation_error( ); msg.push_str("required by "); msg.push_str(&describe_path_in_context( - resolver_gctx, + resolver_ctx, &parent.package_id(), )); @@ -364,7 +364,7 @@ pub(super) fn activation_error( msg.push_str(&format!("location searched: {}\n", dep.source_id())); msg.push_str("required by "); msg.push_str(&describe_path_in_context( - resolver_gctx, + resolver_ctx, &parent.package_id(), )); diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index d35e69c4446..32a1d4d9d47 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -40,8 +40,8 @@ pub struct CleanContext<'gctx> { pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { let mut target_dir = ws.target_dir(); let gctx = opts.gctx; - let mut clean_gctx = CleanContext::new(gctx); - clean_gctx.dry_run = opts.dry_run; + let mut clean_ctx = CleanContext::new(gctx); + clean_ctx.dry_run = opts.dry_run; if opts.doc { if !opts.spec.is_empty() { @@ -55,7 +55,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { } // If the doc option is set, we just want to delete the doc directory. target_dir = target_dir.join("doc"); - clean_gctx.remove_paths(&[target_dir.into_path_unlocked()])?; + clean_ctx.remove_paths(&[target_dir.into_path_unlocked()])?; } else { let profiles = Profiles::new(&ws, opts.requested_profile)?; @@ -73,13 +73,13 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { // Note that we don't bother grabbing a lock here as we're just going to // blow it all away anyway. if opts.spec.is_empty() { - clean_gctx.remove_paths(&[target_dir.into_path_unlocked()])?; + clean_ctx.remove_paths(&[target_dir.into_path_unlocked()])?; } else { - clean_specs(&mut clean_gctx, &ws, &profiles, &opts.targets, &opts.spec)?; + clean_specs(&mut clean_ctx, &ws, &profiles, &opts.targets, &opts.spec)?; } } - clean_gctx.display_summary()?; + clean_ctx.display_summary()?; Ok(()) } diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index 49f63185ab7..7f9e9696327 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -120,7 +120,7 @@ impl<'gctx> SourceConfigMap<'gctx> { Ok(base) } - /// Returns the `Config` this source config map is associated with. + /// Returns the [`GlobalContext`] this source config map is associated with. pub fn gctx(&self) -> &'gctx GlobalContext { self.gctx } diff --git a/src/cargo/util/cache_lock.rs b/src/cargo/util/cache_lock.rs index fb879ebcda3..6e0249cc9e6 100644 --- a/src/cargo/util/cache_lock.rs +++ b/src/cargo/util/cache_lock.rs @@ -8,7 +8,7 @@ //! //! There is a global [`CacheLocker`] held inside cargo's venerable //! [`GlobalContext`]. The `CacheLocker` manages creating and tracking the locks -//! being held. There are methods on `Config` for managing the locks: +//! being held. There are methods on [`GlobalContext`] for managing the locks: //! //! - [`GlobalContext::acquire_package_cache_lock`] --- Acquires a lock. May block if //! another process holds a lock. @@ -468,7 +468,7 @@ pub struct CacheLocker { /// The state of the locker. /// /// [`CacheLocker`] uses interior mutability because it is stuffed inside - /// the global `Config`, which does not allow mutation. + /// [`GlobalContext`], which does not allow mutation. state: RefCell, } diff --git a/src/cargo/util/config/de.rs b/src/cargo/util/config/de.rs index 7ea2d431237..bfefad91ca2 100644 --- a/src/cargo/util/config/de.rs +++ b/src/cargo/util/config/de.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; use std::vec; /// Serde deserializer used to convert config values to a target type using -/// `Config::get`. +/// [`GlobalContext::get`]. #[derive(Clone)] pub(super) struct Deserializer<'gctx> { pub(super) gctx: &'gctx GlobalContext, diff --git a/src/cargo/util/config/environment.rs b/src/cargo/util/config/environment.rs index dcf7cbcbf05..da9cd5e641c 100644 --- a/src/cargo/util/config/environment.rs +++ b/src/cargo/util/config/environment.rs @@ -28,18 +28,20 @@ fn make_case_insensitive_and_normalized_env( (case_insensitive_env, normalized_env) } -/// A snapshot of the environment variables available to [`super::GlobalContext`]. +/// A snapshot of the environment variables available to [`GlobalContext`]. /// -/// Currently, the [`Context`](super::GlobalContext) supports lookup of environment variables +/// Currently, the [`GlobalContext`] supports lookup of environment variables /// through two different means: /// -/// - [`Context::get_env`](super::GlobalContext::get_env) -/// and [`Context::get_env_os`](super::GlobalContext::get_env_os) +/// - [`GlobalContext::get_env`](super::GlobalContext::get_env) +/// and [`GlobalContext::get_env_os`](super::GlobalContext::get_env_os) /// for process environment variables (similar to [`std::env::var`] and [`std::env::var_os`]), -/// - Typed Config Value API via [`Context::get`](super::GlobalContext::get). +/// - Typed Config Value API via [`GlobalContext::get`](super::GlobalContext::get). /// This is only available for `CARGO_` prefixed environment keys. /// /// This type contains the env var snapshot and helper methods for both APIs. +/// +/// [`GlobalContext`]: super::GlobalContext #[derive(Debug)] pub struct Env { /// A snapshot of the process's environment variables. @@ -68,8 +70,8 @@ impl Env { pub fn new() -> Self { // ALLOWED: This is the only permissible usage of `std::env::vars{_os}` // within cargo. If you do need access to individual variables without - // interacting with `Config` system, please use `std::env::var{_os}` - // and justify the validity of the usage. + // interacting with the config system in [`GlobalContext`], please use + // `std::env::var{_os}` and justify the validity of the usage. #[allow(clippy::disallowed_methods)] let env: HashMap<_, _> = std::env::vars_os().collect(); let (case_insensitive_env, normalized_env) = make_case_insensitive_and_normalized_env(&env); @@ -105,9 +107,10 @@ impl Env { self.env.keys().filter_map(|k| k.to_str()) } - /// Get the value of environment variable `key` through the `Config` snapshot. + /// Get the value of environment variable `key` through the snapshot in + /// [`GlobalContext`](super::GlobalContext). /// - /// This can be used similarly to `std::env::var_os`. + /// This can be used similarly to [`std::env::var_os`]. /// On Windows, we check for case mismatch since environment keys are case-insensitive. pub fn get_env_os(&self, key: impl AsRef) -> Option { match self.env.get(key.as_ref()) { @@ -152,7 +155,7 @@ impl Env { /// Get the value of environment variable `key` as a `&str`. /// Returns `None` if `key` is not in `self.env` or if the value is not valid UTF-8. /// - /// This is intended for use in private methods of `Config`, + /// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext), /// and does not check for env key case mismatch. /// /// This is case-sensitive on Windows (even though environment keys on Windows are usually @@ -172,7 +175,7 @@ impl Env { /// Check if the environment contains `key`. /// - /// This is intended for use in private methods of `Config`, + /// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext), /// and does not check for env key case mismatch. /// See the docstring of [`Env::get_str`] for more context. pub(super) fn contains_key(&self, key: impl AsRef) -> bool { diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 30536b1adf9..c64458990f4 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1,12 +1,12 @@ //! Cargo's config system. //! -//! The `Config` object contains general information about the environment, +//! The [`GlobalContext`] object contains general information about the environment, //! and provides access to Cargo's configuration files. //! //! ## Config value API //! //! The primary API for fetching user-defined config values is the -//! `Config::get` method. It uses `serde` to translate config values to a +//! [`GlobalContext::get`] method. It uses `serde` to translate config values to a //! target type. //! //! There are a variety of helper types for deserializing some common formats: @@ -329,7 +329,7 @@ impl GlobalContext { } } - /// Creates a new Config instance, with all default settings. + /// Creates a new instance, with all default settings. /// /// This does only minimal initialization. In particular, it does not load /// any config files from disk. Those will be loaded lazily as-needed. @@ -811,16 +811,18 @@ impl GlobalContext { } } - /// Get the value of environment variable `key` through the `Config` snapshot. + /// Get the value of environment variable `key` through the snapshot in + /// [`GlobalContext`]. /// - /// This can be used similarly to `std::env::var`. + /// This can be used similarly to [`std::env::var`]. pub fn get_env(&self, key: impl AsRef) -> CargoResult { self.env.get_env(key) } - /// Get the value of environment variable `key` through the `Config` snapshot. + /// Get the value of environment variable `key` through the snapshot in + /// [`GlobalContext`]. /// - /// This can be used similarly to `std::env::var_os`. + /// This can be used similarly to [`std::env::var_os`]. pub fn get_env_os(&self, key: impl AsRef) -> Option { self.env.get_env_os(key) } @@ -1001,7 +1003,7 @@ impl GlobalContext { .map_err(|e| anyhow!("invalid configuration for key `{}`\n{}", key, e)) } - /// Update the Config instance based on settings typically passed in on + /// Update the instance based on settings typically passed in on /// the command-line. /// /// This may also load the config from disk if it hasn't already been @@ -1646,7 +1648,7 @@ impl GlobalContext { /// /// The credentials are loaded into a separate field to enable them /// to be lazy-loaded after the main configuration has been loaded, - /// without requiring `mut` access to the `Config`. + /// without requiring `mut` access to the [`GlobalContext`]. /// /// If the credentials are already loaded, this function does nothing. pub fn load_credentials(&self) -> CargoResult<()> { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 0e22ef44b17..0bead106403 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -686,7 +686,7 @@ pub fn to_real_manifest( }; fn process_dependencies( - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, new_deps: Option<&BTreeMap>, kind: Option, workspace_config: &WorkspaceConfig, @@ -699,8 +699,8 @@ pub fn to_real_manifest( let inheritable = || { inherit_cell.try_borrow_with(|| { get_ws( - manifest_gctx.gctx, - &manifest_gctx.root.join("Cargo.toml"), + manifest_ctx.gctx, + &manifest_ctx.root.join("Cargo.toml"), &workspace_config, ) }) @@ -709,14 +709,14 @@ pub fn to_real_manifest( let mut deps: BTreeMap = BTreeMap::new(); for (n, v) in dependencies.iter() { - let resolved = dependency_inherit_with(v.clone(), n, inheritable, manifest_gctx)?; - let dep = dep_to_dependency(&resolved, n, manifest_gctx, kind)?; + let resolved = dependency_inherit_with(v.clone(), n, inheritable, manifest_ctx)?; + let dep = dep_to_dependency(&resolved, n, manifest_ctx, kind)?; let name_in_toml = dep.name_in_toml().as_str(); let kind_name = match kind { Some(k) => k.kind_table(), None => "dependencies", }; - let table_in_toml = if let Some(platform) = &manifest_gctx.platform { + let table_in_toml = if let Some(platform) = &manifest_ctx.platform { format!("target.{}.{kind_name}", platform.to_string()) } else { kind_name.to_string() @@ -725,9 +725,9 @@ pub fn to_real_manifest( name_in_toml, &table_in_toml, v.unused_keys(), - manifest_gctx.warnings, + manifest_ctx.warnings, ); - manifest_gctx.deps.push(dep); + manifest_ctx.deps.push(dep); deps.insert( n.clone(), manifest::InheritableDependency::Value(resolved.clone()), @@ -1177,7 +1177,7 @@ fn to_virtual_manifest( let features = Features::new(cargo_features, gctx, &mut warnings, source_id.is_path())?; let (replace, patch) = { - let mut manifest_gctx = ManifestContext { + let mut manifest_ctx = ManifestContext { deps: &mut deps, source_id, nested_paths: &mut nested_paths, @@ -1188,8 +1188,8 @@ fn to_virtual_manifest( root, }; ( - replace(&me, &mut manifest_gctx)?, - patch(&me, &mut manifest_gctx)?, + replace(&me, &mut manifest_ctx)?, + patch(&me, &mut manifest_ctx)?, ) }; let profiles = me.profile.clone(); @@ -1244,7 +1244,7 @@ fn to_virtual_manifest( fn replace( me: &manifest::TomlManifest, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, ) -> CargoResult> { if me.patch.is_some() && me.replace.is_some() { bail!("cannot specify both [replace] and [patch]"); @@ -1270,7 +1270,7 @@ fn replace( ); } - let mut dep = dep_to_dependency(replacement, spec.name(), manifest_gctx, None)?; + let mut dep = dep_to_dependency(replacement, spec.name(), manifest_ctx, None)?; let version = spec.version().ok_or_else(|| { anyhow!( "replacements must specify a version \ @@ -1282,7 +1282,7 @@ fn replace( dep.name_in_toml().as_str(), "replace", replacement.unused_keys(), - &mut manifest_gctx.warnings, + &mut manifest_ctx.warnings, ); dep.set_version_req(OptVersionReq::exact(&version)); replace.push((spec, dep)); @@ -1292,13 +1292,13 @@ fn replace( fn patch( me: &manifest::TomlManifest, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, ) -> CargoResult>> { let mut patch = HashMap::new(); for (toml_url, deps) in me.patch.iter().flatten() { let url = match &toml_url[..] { CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), - _ => manifest_gctx + _ => manifest_ctx .gctx .get_registry_index(toml_url) .or_else(|_| toml_url.into_url()) @@ -1317,9 +1317,9 @@ fn patch( name, &format!("patch.{toml_url}",), dep.unused_keys(), - &mut manifest_gctx.warnings, + &mut manifest_ctx.warnings, ); - dep_to_dependency(dep, name, manifest_gctx, None) + dep_to_dependency(dep, name, manifest_ctx, None) }) .collect::>>()?, ); @@ -1636,12 +1636,12 @@ fn dependency_inherit_with<'a>( dependency: manifest::InheritableDependency, name: &str, inheritable: impl FnOnce() -> CargoResult<&'a InheritableFields>, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, ) -> CargoResult { match dependency { manifest::InheritableDependency::Value(value) => Ok(value), manifest::InheritableDependency::Inherit(w) => { - inner_dependency_inherit_with(w, name, inheritable, manifest_gctx).with_context(|| { + inner_dependency_inherit_with(w, name, inheritable, manifest_ctx).with_context(|| { format!( "error inheriting `{name}` from workspace root manifest's `workspace.dependencies.{name}`", ) @@ -1654,19 +1654,19 @@ fn inner_dependency_inherit_with<'a>( dependency: manifest::TomlInheritedDependency, name: &str, inheritable: impl FnOnce() -> CargoResult<&'a InheritableFields>, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, ) -> CargoResult { fn default_features_msg( label: &str, ws_def_feat: Option, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, ) { let ws_def_feat = match ws_def_feat { Some(true) => "true", Some(false) => "false", None => "not specified", }; - manifest_gctx.warnings.push(format!( + manifest_ctx.warnings.push(format!( "`default-features` is ignored for {label}, since `default-features` was \ {ws_def_feat} for `workspace.dependencies.{label}`, \ this could become a hard error in the future" @@ -1677,16 +1677,16 @@ fn inner_dependency_inherit_with<'a>( "default-features", name, "dependency", - manifest_gctx.warnings, + manifest_ctx.warnings, ); } inheritable()? - .get_dependency(name, manifest_gctx.root) + .get_dependency(name, manifest_ctx.root) .map(|d| { match d { manifest::TomlDependency::Simple(s) => { if let Some(false) = dependency.default_features() { - default_features_msg(name, None, manifest_gctx); + default_features_msg(name, None, manifest_ctx); } if dependency.optional.is_some() || dependency.features.is_some() @@ -1716,12 +1716,12 @@ fn inner_dependency_inherit_with<'a>( // workspace: default-features = true should ignore member // default-features (Some(false), Some(true)) => { - default_features_msg(name, Some(true), manifest_gctx); + default_features_msg(name, Some(true), manifest_ctx); } // member: default-features = false and // workspace: dep = "1.0" should ignore member default-features (Some(false), None) => { - default_features_msg(name, None, manifest_gctx); + default_features_msg(name, None, manifest_ctx); } _ => {} } @@ -1775,7 +1775,7 @@ pub(crate) fn to_dependency( fn dep_to_dependency( orig: &manifest::TomlDependency

, name: &str, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, kind: Option, ) -> CargoResult { match *orig { @@ -1785,11 +1785,11 @@ fn dep_to_dependency( ..Default::default() }, name, - manifest_gctx, + manifest_ctx, kind, ), manifest::TomlDependency::Detailed(ref details) => { - detailed_dep_to_dependency(details, name, manifest_gctx, kind) + detailed_dep_to_dependency(details, name, manifest_ctx, kind) } } } @@ -1797,7 +1797,7 @@ fn dep_to_dependency( fn detailed_dep_to_dependency( orig: &manifest::TomlDetailedDependency

, name_in_toml: &str, - manifest_gctx: &mut ManifestContext<'_, '_>, + manifest_ctx: &mut ManifestContext<'_, '_>, kind: Option, ) -> CargoResult { if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() { @@ -1808,12 +1808,12 @@ fn detailed_dep_to_dependency( error in future versions", name_in_toml ); - manifest_gctx.warnings.push(msg); + manifest_ctx.warnings.push(msg); } if let Some(version) = &orig.version { if version.contains('+') { - manifest_gctx.warnings.push(format!( + manifest_ctx.warnings.push(format!( "version requirement `{}` for dependency `{}` \ includes semver metadata which will be ignored, removing the \ metadata is recommended to avoid confusion", @@ -1923,14 +1923,14 @@ fn detailed_dep_to_dependency( use `rev = \"{}\"` in the dependency declaration.", fragment, name_in_toml, fragment ); - manifest_gctx.warnings.push(msg) + manifest_ctx.warnings.push(msg) } SourceId::for_git(&loc, reference)? } (None, Some(path), _, _) => { - let path = path.resolve(manifest_gctx.gctx); - manifest_gctx.nested_paths.push(path.clone()); + let path = path.resolve(manifest_ctx.gctx); + manifest_ctx.nested_paths.push(path.clone()); // If the source ID for the package we're parsing is a path // source, then we normalize the path here to get rid of // components like `..`. @@ -1939,20 +1939,20 @@ fn detailed_dep_to_dependency( // that we're depending on to ensure that builds of this package // always end up hashing to the same value no matter where it's // built from. - if manifest_gctx.source_id.is_path() { - let path = manifest_gctx.root.join(path); + if manifest_ctx.source_id.is_path() { + let path = manifest_ctx.root.join(path); let path = paths::normalize_path(&path); SourceId::for_path(&path)? } else { - manifest_gctx.source_id + manifest_ctx.source_id } } - (None, None, Some(registry), None) => SourceId::alt_registry(manifest_gctx.gctx, registry)?, + (None, None, Some(registry), None) => SourceId::alt_registry(manifest_ctx.gctx, registry)?, (None, None, None, Some(registry_index)) => { let url = registry_index.into_url()?; SourceId::for_registry(&url)? } - (None, None, None, None) => SourceId::crates_io(manifest_gctx.gctx)?, + (None, None, None, None) => SourceId::crates_io(manifest_ctx.gctx)?, }; let (pkg_name, explicit_name_in_toml) = match orig.package { @@ -1967,15 +1967,15 @@ fn detailed_dep_to_dependency( "default-features", name_in_toml, "dependency", - manifest_gctx.warnings, + manifest_ctx.warnings, ); } dep.set_features(orig.features.iter().flatten()) .set_default_features(orig.default_features().unwrap_or(true)) .set_optional(orig.optional.unwrap_or(false)) - .set_platform(manifest_gctx.platform.clone()); + .set_platform(manifest_ctx.platform.clone()); if let Some(registry) = &orig.registry { - let registry_id = SourceId::alt_registry(manifest_gctx.gctx, registry)?; + let registry_id = SourceId::alt_registry(manifest_ctx.gctx, registry)?; dep.set_registry_id(registry_id); } if let Some(registry_index) = &orig.registry_index { @@ -1992,7 +1992,7 @@ fn detailed_dep_to_dependency( } if let Some(p) = orig.public { - manifest_gctx + manifest_ctx .features .require(Feature::public_dependency())?; @@ -2008,7 +2008,7 @@ fn detailed_dep_to_dependency( orig.lib.unwrap_or(false), orig.target.as_deref(), ) { - if manifest_gctx.gctx.cli_unstable().bindeps { + if manifest_ctx.gctx.cli_unstable().bindeps { let artifact = Artifact::parse(&artifact.0, is_lib, target)?; if dep.kind() != DepKind::Build && artifact.target() == Some(ArtifactTarget::BuildDependencyAssumeTarget) diff --git a/src/doc/contrib/src/implementation/console.md b/src/doc/contrib/src/implementation/console.md index 99d31b951ae..4874a931939 100644 --- a/src/doc/contrib/src/implementation/console.md +++ b/src/doc/contrib/src/implementation/console.md @@ -1,8 +1,8 @@ # Console Output All of Cargo's output should go through the [`Shell`] struct. You can normally -obtain the `Shell` instance from the [`Config`] struct. Do **not** use the std -`println!` macros. +obtain the `Shell` instance from the [`GlobalContext`] struct. Do **not** use +the std `println!` macros. Most of Cargo's output goes to stderr. When running in JSON mode, the output goes to stdout. @@ -17,7 +17,7 @@ if they are unable to be displayed. This is generally automatically handled in the [`JobQueue`] as it processes each message. [`Shell`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/shell.rs -[`Config`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/config/mod.rs +[`GlobalContext`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/config/mod.rs [`drop_print`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/src/cargo/util/config/mod.rs#L1820-L1848 [`JobQueue`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/job_queue/mod.rs diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index e2d8d662c63..802d7e4423d 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -80,9 +80,9 @@ impl GlobalContextBuilder { /// Sets the test root directory. /// /// This generally should not be necessary. It is only useful if you want - /// to create a `Config` from within a thread. Since Cargo's testsuite - /// uses thread-local storage, this can be used to avoid accessing that - /// thread-local storage. + /// to create a [`GlobalContext`] from within a thread. Since Cargo's + /// testsuite uses thread-local storage, this can be used to avoid accessing + /// that thread-local storage. /// /// Default is [`paths::root`]. pub fn root(&mut self, path: impl Into) -> &mut Self { @@ -90,12 +90,12 @@ impl GlobalContextBuilder { self } - /// Creates the `Config`. + /// Creates the [`GlobalContext`]. pub fn build(&self) -> GlobalContext { self.build_err().unwrap() } - /// Creates the `Config`, returning a Result. + /// Creates the [`GlobalContext`], returning a Result. pub fn build_err(&self) -> CargoResult { let root = self.root.clone().unwrap_or_else(|| paths::root()); let output = Box::new(fs::File::create(root.join("shell.out")).unwrap());