Skip to content

Commit f6d1d12

Browse files
committed
Cap lints at warn when cargo installing
1 parent dc83ead commit f6d1d12

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::command_prelude::*;
22

33
use cargo::core::{GitReference, SourceId};
4+
use cargo::core::compiler::LintLevel;
45
use cargo::ops;
56
use cargo::util::ToUrl;
67

@@ -84,6 +85,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
8485

8586
compile_opts.build_config.release = !args.is_present("debug");
8687

88+
// Cap lints at warn, so crates with deny or forbid clauses can be installed
89+
compile_opts.build_config.cap_lints = Some(LintLevel::Warn);
90+
8791
let krates = args
8892
.values_of("crate")
8993
.unwrap_or_default()

src/cargo/core/compiler/build_config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct BuildConfig {
2929
pub extra_rustc_env: Vec<(String, String)>,
3030
/// Extra args to inject into rustc commands.
3131
pub extra_rustc_args: Vec<String>,
32+
pub cap_lints: Option<LintLevel>,
3233
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
3334
}
3435

@@ -91,6 +92,7 @@ impl BuildConfig {
9192
cargo_as_rustc_wrapper: false,
9293
extra_rustc_env: Vec::new(),
9394
extra_rustc_args: Vec::new(),
95+
cap_lints: None,
9496
rustfix_diagnostic_server: RefCell::new(None),
9597
})
9698
}
@@ -211,3 +213,8 @@ impl CompileMode {
211213
&ALL
212214
}
213215
}
216+
217+
#[derive(Debug)]
218+
pub enum LintLevel {
219+
Allow, Warn, Deny, Forbid,
220+
}

src/cargo/core/compiler/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::util::errors::{CargoResult, CargoResultExt, Internal, ProcessError};
2929
use crate::util::paths;
3030
use crate::util::{self, machine_message, process, Freshness, ProcessBuilder};
3131
use crate::util::{internal, join_paths, profile};
32-
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
32+
pub use self::build_config::{BuildConfig, CompileMode, LintLevel, MessageFormat};
3333
pub use self::build_context::{BuildContext, FileFlavor, TargetConfig, TargetInfo};
3434
use self::build_plan::BuildPlan;
3535
pub use self::compilation::{Compilation, Doctest};
@@ -717,6 +717,15 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>, cmd: &mut ProcessB
717717
// don't fail compilation.
718718
} else if !unit.pkg.package_id().source_id().is_path() {
719719
cmd.arg("--cap-lints").arg("warn");
720+
721+
// If we have a BuildConfig-wide lint cap set, use that.
722+
} else if let Some(cap_lints) = &bcx.build_config.cap_lints {
723+
cmd.arg("--cap-lints").arg(match cap_lints {
724+
LintLevel::Allow => "allow",
725+
LintLevel::Warn => "warn",
726+
LintLevel::Deny => "deny",
727+
LintLevel::Forbid => "forbid",
728+
});
720729
}
721730
}
722731

0 commit comments

Comments
 (0)