Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap lints at warn when cargo installing #6647

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub cap_lints: Option<LintLevel>,
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
}

Expand Down Expand Up @@ -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),
})
}
Expand Down Expand Up @@ -211,3 +213,8 @@ impl CompileMode {
&ALL
}
}

#[derive(Debug)]
pub enum LintLevel {
Allow, Warn, Deny, Forbid,
}
11 changes: 10 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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",
});
}
}

Expand Down