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

Error when unstable lints are specified but not enabled #13805

Merged
merged 3 commits into from
May 1, 2024
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
11 changes: 8 additions & 3 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl FromStr for Edition {
}
}

#[derive(PartialEq)]
#[derive(Debug, PartialEq)]
enum Status {
Stable,
Unstable,
Expand Down Expand Up @@ -387,11 +387,11 @@ macro_rules! features {
$(
$(#[$attr])*
#[doc = concat!("\n\n\nSee <https://doc.rust-lang.org/nightly/cargo/", $docs, ">.")]
pub fn $feature() -> &'static Feature {
pub const fn $feature() -> &'static Feature {
fn get(features: &Features) -> bool {
stab!($stab) == Status::Stable || features.$feature
}
static FEAT: Feature = Feature {
const FEAT: Feature = Feature {
name: stringify!($feature),
stability: stab!($stab),
version: $version,
Expand All @@ -406,6 +406,10 @@ macro_rules! features {
fn is_enabled(&self, features: &Features) -> bool {
(self.get)(features)
}

pub(crate) fn name(&self) -> &str {
self.name
}
}

impl Features {
Expand Down Expand Up @@ -512,6 +516,7 @@ features! {
}

/// Status and metadata for a single unstable feature.
#[derive(Debug)]
pub struct Feature {
/// Feature name. This is valid Rust identifier so no dash only underscore.
name: &'static str,
Expand Down
24 changes: 23 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
use crate::util::edit_distance;
use crate::util::errors::{CargoResult, ManifestError};
use crate::util::interning::InternedString;
use crate::util::lints::{check_im_a_teapot, check_implicit_features, unused_dependencies};
use crate::util::lints::{
analyze_cargo_lints_table, check_im_a_teapot, check_implicit_features, unused_dependencies,
};
use crate::util::toml::{read_manifest, InheritableFields};
use crate::util::{
context::CargoResolverConfig, context::CargoResolverPrecedence, context::ConfigRelativePath,
Expand Down Expand Up @@ -1227,6 +1229,26 @@ impl<'gctx> Workspace<'gctx> {
.is_some_and(|l| l.workspace)
.then(|| ws_cargo_lints);

let ws_contents = match self.root_maybe() {
MaybePackage::Package(pkg) => pkg.manifest().contents(),
MaybePackage::Virtual(v) => v.contents(),
};

let ws_document = match self.root_maybe() {
MaybePackage::Package(pkg) => pkg.manifest().document(),
MaybePackage::Virtual(v) => v.document(),
};

analyze_cargo_lints_table(
pkg,
&path,
&normalized_lints,
ws_cargo_lints,
ws_contents,
ws_document,
self.root_manifest(),
self.gctx,
)?;
check_im_a_teapot(
pkg,
&path,
Expand Down
Loading