mirror of
https://github.com/rust-lang/cargo.git
synced 2026-03-12 19:40:13 +00:00
Fixes #15579 Some naming inspiration from rust-lang/rust-clippy#15092. There are several ways to go with this lint and I'm leaving the final decisions to the stabilization conversations. - Could be called `missing_lints` but that makes it sound like its needed even when there is no `workspace.lints` - The name implies it should lint for an empty `[lints]` - Naming to be specific enough is hard - We could lint on a `[lints]` without `workspace = true` but then they will have to turn this lint to `allow` when intentionally not inheriting, adding boilerplate, while we're mainly trying to cover the case of people thinking implicit inheritance is a thing.
164 lines
3.2 KiB
Rust
164 lines
3.2 KiB
Rust
use crate::prelude::*;
|
|
use cargo_test_support::project;
|
|
use cargo_test_support::str;
|
|
|
|
#[cargo_test]
|
|
fn no_lints() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[workspace]
|
|
members = ["bar"]
|
|
"#,
|
|
)
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
"#,
|
|
)
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
.build();
|
|
|
|
p.cargo("check -Zcargo-lints")
|
|
.masquerade_as_nightly_cargo(&["cargo-lints"])
|
|
.with_stderr_data(str![[r#"
|
|
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
|
|
"#]])
|
|
.run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn ws_lints() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[workspace]
|
|
members = ["bar"]
|
|
|
|
[workspace.lints.cargo]
|
|
missing_lints_inheritance = "warn"
|
|
"#,
|
|
)
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
"#,
|
|
)
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
.build();
|
|
|
|
p.cargo("check -Zcargo-lints")
|
|
.masquerade_as_nightly_cargo(&["cargo-lints"])
|
|
.with_stderr_data(str![[r#"
|
|
[WARNING] missing `[lints]` to inherit `[workspace.lints]`
|
|
--> bar/Cargo.toml
|
|
= [NOTE] `cargo::missing_lints_inheritance` is set to `warn` by default
|
|
[HELP] to inherit `workspace.lints, add:
|
|
|
|
|
5 ~ edition = "2015"
|
|
6 + [lints]
|
|
7 + workspace = true
|
|
|
|
|
[HELP] to clarify your intent to not inherit, add:
|
|
|
|
|
5 ~ edition = "2015"
|
|
6 + [lints]
|
|
|
|
|
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
|
|
"#]])
|
|
.run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn empty_pkg_lints() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[workspace]
|
|
members = ["bar"]
|
|
|
|
[workspace.lints.cargo]
|
|
missing_lints_inheritance = "warn"
|
|
"#,
|
|
)
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
|
|
[lints]
|
|
"#,
|
|
)
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
.build();
|
|
|
|
p.cargo("check -Zcargo-lints")
|
|
.masquerade_as_nightly_cargo(&["cargo-lints"])
|
|
.with_stderr_data(str![[r#"
|
|
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
|
|
"#]])
|
|
.run();
|
|
}
|
|
|
|
#[cargo_test]
|
|
fn inherit_lints() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[workspace]
|
|
members = ["bar"]
|
|
|
|
[workspace.lints.cargo]
|
|
missing_lints_inheritance = "warn"
|
|
"#,
|
|
)
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"bar/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
name = "bar"
|
|
version = "0.0.1"
|
|
edition = "2015"
|
|
|
|
[lints]
|
|
workspace = true
|
|
"#,
|
|
)
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
.build();
|
|
|
|
p.cargo("check -Zcargo-lints")
|
|
.masquerade_as_nightly_cargo(&["cargo-lints"])
|
|
.with_stderr_data(str![[r#"
|
|
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
|
|
"#]])
|
|
.run();
|
|
}
|