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

feat: lints feature #12148

Merged
merged 19 commits into from
May 22, 2023
Merged
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/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
//! [`Lto`] flags | ✓ | ✓
//! config settings[^5] | ✓ |
//! is_std | | ✓
//! `[lints]` table[^6] | ✓ |
//!
//! [^1]: Build script and bin dependencies are not included.
//!
Expand All @@ -86,6 +87,8 @@
//! [^5]: Config settings that are not otherwise captured anywhere else.
//! Currently, this is only `doc.extern-map`.
//!
//! [^6]: Via [`Manifest::lint_rustflags`][crate::core::Manifest::lint_rustflags]
//!
//! When deciding what should go in the Metadata vs the Fingerprint, consider
//! that some files (like dylibs) do not have a hash in their filename. Thus,
//! if a value changes, only the fingerprint will detect the change (consider,
Expand Down Expand Up @@ -1414,6 +1417,7 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
unit.mode,
cx.bcx.extra_args_for(unit),
cx.lto[unit],
unit.pkg.manifest().lint_rustflags(),
));
// Include metadata since it is exposed as environment variables.
let m = unit.pkg.manifest().metadata();
Expand Down
9 changes: 5 additions & 4 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
add_error_format_and_color(cx, &mut rustdoc);
add_allow_features(cx, &mut rustdoc);

rustdoc.args(unit.pkg.manifest().lint_rustflags());
if let Some(args) = cx.bcx.extra_args_for(unit) {
rustdoc.args(args);
}
Expand Down Expand Up @@ -1040,10 +1041,6 @@ fn build_base_args(
cmd.arg("-C").arg(&format!("opt-level={}", opt_level));
}

if !rustflags.is_empty() {
cmd.args(&rustflags);
}

if *panic != PanicStrategy::Unwind {
cmd.arg("-C").arg(format!("panic={}", panic));
}
Expand Down Expand Up @@ -1078,6 +1075,10 @@ fn build_base_args(
cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
}

cmd.args(unit.pkg.manifest().lint_rustflags());
if !rustflags.is_empty() {
cmd.args(&rustflags);
}
if let Some(args) = cx.bcx.extra_args_for(unit) {
cmd.args(args);
}
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ features! {

// Allow specifying rustflags directly in a profile
(stable, workspace_inheritance, "1.64", "reference/unstable.html#workspace-inheritance"),

// Allow specifying rustflags directly in a profile
(unstable, lints, "", "reference/unstable.html#lints"),
}

pub struct Feature {
Expand Down
8 changes: 8 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct Manifest {
default_run: Option<String>,
metabuild: Option<Vec<String>>,
resolve_behavior: Option<ResolveBehavior>,
lint_rustflags: Vec<String>,
}

/// When parsing `Cargo.toml`, some warnings should silenced
Expand Down Expand Up @@ -405,6 +406,7 @@ impl Manifest {
original: Rc<TomlManifest>,
metabuild: Option<Vec<String>>,
resolve_behavior: Option<ResolveBehavior>,
lint_rustflags: Vec<String>,
) -> Manifest {
Manifest {
summary,
Expand All @@ -430,6 +432,7 @@ impl Manifest {
default_run,
metabuild,
resolve_behavior,
lint_rustflags,
}
}

Expand Down Expand Up @@ -514,6 +517,11 @@ impl Manifest {
self.resolve_behavior
}

/// `RUSTFLAGS` from the `[lints]` table
pub fn lint_rustflags(&self) -> &[String] {
self.lint_rustflags.as_slice()
}

pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Manifest {
Manifest {
summary: self.summary.map_source(to_replace, replace_with),
Expand Down
Loading