Skip to content

Commit 6fc9e4b

Browse files
committed
Auto merge of #13805 - Muscraft:im-a-teapot-lint-unstable, r=epage
Error when unstable lints are specified but not enabled In [#13797, it was noted that](#13797 (comment)) the `im-a-teapot` lint should always be unstable. This PR makes it so that `im-a-teapot` is unstable, and it is an error to specify it without the `test-dummy-unstable` cargo feature. It does this by adding a `feature-gate` field to `Lint` and `LintGroup` that optionally puts the lint/lint group behind a feature. The `feature-gate` is then checked during the new `analyze_cargo_lints_table` step that runs across all lints (and groups) specified in `[lints.cargo]` or `[workspace.lints]` if the package is inheriting its lints from a workspace. The error looks like the following: No inherit ![No inherit](https://github.com/rust-lang/cargo/assets/23045215/c245af87-8623-42dc-9652-be461809bb30) Inherited ![Inhrtited](https://github.com/rust-lang/cargo/assets/23045215/5a90b7c9-0e9e-4a07-ab0e-e2e43cca8991)
2 parents 1c92c1e + 712946c commit 6fc9e4b

File tree

4 files changed

+373
-15
lines changed

4 files changed

+373
-15
lines changed

src/cargo/core/features.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl FromStr for Edition {
343343
}
344344
}
345345

346-
#[derive(PartialEq)]
346+
#[derive(Debug, PartialEq)]
347347
enum Status {
348348
Stable,
349349
Unstable,
@@ -387,11 +387,11 @@ macro_rules! features {
387387
$(
388388
$(#[$attr])*
389389
#[doc = concat!("\n\n\nSee <https://doc.rust-lang.org/nightly/cargo/", $docs, ">.")]
390-
pub fn $feature() -> &'static Feature {
390+
pub const fn $feature() -> &'static Feature {
391391
fn get(features: &Features) -> bool {
392392
stab!($stab) == Status::Stable || features.$feature
393393
}
394-
static FEAT: Feature = Feature {
394+
const FEAT: Feature = Feature {
395395
name: stringify!($feature),
396396
stability: stab!($stab),
397397
version: $version,
@@ -406,6 +406,10 @@ macro_rules! features {
406406
fn is_enabled(&self, features: &Features) -> bool {
407407
(self.get)(features)
408408
}
409+
410+
pub(crate) fn name(&self) -> &str {
411+
self.name
412+
}
409413
}
410414

411415
impl Features {
@@ -512,6 +516,7 @@ features! {
512516
}
513517

514518
/// Status and metadata for a single unstable feature.
519+
#[derive(Debug)]
515520
pub struct Feature {
516521
/// Feature name. This is valid Rust identifier so no dash only underscore.
517522
name: &'static str,

src/cargo/core/workspace.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
2424
use crate::util::edit_distance;
2525
use crate::util::errors::{CargoResult, ManifestError};
2626
use crate::util::interning::InternedString;
27-
use crate::util::lints::{check_im_a_teapot, check_implicit_features, unused_dependencies};
27+
use crate::util::lints::{
28+
analyze_cargo_lints_table, check_im_a_teapot, check_implicit_features, unused_dependencies,
29+
};
2830
use crate::util::toml::{read_manifest, InheritableFields};
2931
use crate::util::{
3032
context::CargoResolverConfig, context::CargoResolverPrecedence, context::ConfigRelativePath,
@@ -1227,6 +1229,26 @@ impl<'gctx> Workspace<'gctx> {
12271229
.is_some_and(|l| l.workspace)
12281230
.then(|| ws_cargo_lints);
12291231

1232+
let ws_contents = match self.root_maybe() {
1233+
MaybePackage::Package(pkg) => pkg.manifest().contents(),
1234+
MaybePackage::Virtual(v) => v.contents(),
1235+
};
1236+
1237+
let ws_document = match self.root_maybe() {
1238+
MaybePackage::Package(pkg) => pkg.manifest().document(),
1239+
MaybePackage::Virtual(v) => v.document(),
1240+
};
1241+
1242+
analyze_cargo_lints_table(
1243+
pkg,
1244+
&path,
1245+
&normalized_lints,
1246+
ws_cargo_lints,
1247+
ws_contents,
1248+
ws_document,
1249+
self.root_manifest(),
1250+
self.gctx,
1251+
)?;
12301252
check_im_a_teapot(
12311253
pkg,
12321254
&path,

0 commit comments

Comments
 (0)