diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index a0a9fdfe366..fbb5261c3c9 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -1,6 +1,7 @@ use crate::command_prelude::*; use cargo::core::{GitReference, SourceId}; +use cargo::core::compiler::LintLevel; use cargo::ops; use cargo::util::ToUrl; @@ -84,6 +85,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { compile_opts.build_config.release = !args.is_present("debug"); + // Cap lints at warn, so crates with deny or forbid clauses can be installed + compile_opts.build_config.cap_lints = Some(LintLevel::Warn); + let krates = args .values_of("crate") .unwrap_or_default() diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index dc5e6068037..3554b9d7472 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -29,6 +29,7 @@ pub struct BuildConfig { pub extra_rustc_env: Vec<(String, String)>, /// Extra args to inject into rustc commands. pub extra_rustc_args: Vec, + pub cap_lints: Option, pub rustfix_diagnostic_server: RefCell>, } @@ -91,6 +92,7 @@ impl BuildConfig { cargo_as_rustc_wrapper: false, extra_rustc_env: Vec::new(), extra_rustc_args: Vec::new(), + cap_lints: None, rustfix_diagnostic_server: RefCell::new(None), }) } @@ -211,3 +213,8 @@ impl CompileMode { &ALL } } + +#[derive(Debug)] +pub enum LintLevel { + Allow, Warn, Deny, Forbid, +} diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index af1c1250df2..11ed59d64e2 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -29,7 +29,7 @@ use crate::util::errors::{CargoResult, CargoResultExt, Internal, ProcessError}; use crate::util::paths; use crate::util::{self, machine_message, process, Freshness, ProcessBuilder}; use crate::util::{internal, join_paths, profile}; -pub use self::build_config::{BuildConfig, CompileMode, MessageFormat}; +pub use self::build_config::{BuildConfig, CompileMode, LintLevel, MessageFormat}; pub use self::build_context::{BuildContext, FileFlavor, TargetConfig, TargetInfo}; use self::build_plan::BuildPlan; pub use self::compilation::{Compilation, Doctest}; @@ -717,6 +717,15 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>, cmd: &mut ProcessB // don't fail compilation. } else if !unit.pkg.package_id().source_id().is_path() { cmd.arg("--cap-lints").arg("warn"); + + // If we have a BuildConfig-wide lint cap set, use that. + } else if let Some(cap_lints) = &bcx.build_config.cap_lints { + cmd.arg("--cap-lints").arg(match cap_lints { + LintLevel::Allow => "allow", + LintLevel::Warn => "warn", + LintLevel::Deny => "deny", + LintLevel::Forbid => "forbid", + }); } }