mirror of https://github.com/rust-lang/cargo
Compare commits
7 Commits
e99d43fbd0
...
3c14e55639
Author | SHA1 | Date |
---|---|---|
Ed Page | 3c14e55639 | |
bors | eee4ea2f5a | |
bors | c4e19cc890 | |
Eric Huss | 06fb65e753 | |
Scott Schafer | cf197fc499 | |
Scott Schafer | c3b104e11e | |
Ed Page | 0ccb9e582d |
|
@ -51,7 +51,7 @@ pub struct TomlManifest {
|
|||
pub replace: Option<BTreeMap<String, TomlDependency>>,
|
||||
pub patch: Option<BTreeMap<String, BTreeMap<PackageName, TomlDependency>>>,
|
||||
pub workspace: Option<TomlWorkspace>,
|
||||
pub badges: Option<InheritableBtreeMap>,
|
||||
pub badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
pub lints: Option<InheritableLints>,
|
||||
|
||||
/// Report unused keys (see also nested `_unused_keys`)
|
||||
|
@ -106,12 +106,6 @@ impl TomlManifest {
|
|||
self.features.as_ref()
|
||||
}
|
||||
|
||||
pub fn resolved_badges(
|
||||
&self,
|
||||
) -> Result<Option<&BTreeMap<String, BTreeMap<String, String>>>, UnresolvedError> {
|
||||
self.badges.as_ref().map(|l| l.resolved()).transpose()
|
||||
}
|
||||
|
||||
pub fn resolved_lints(&self) -> Result<Option<&TomlLints>, UnresolvedError> {
|
||||
self.lints.as_ref().map(|l| l.resolved()).transpose()
|
||||
}
|
||||
|
|
|
@ -1147,11 +1147,26 @@ impl<'gctx> Workspace<'gctx> {
|
|||
}
|
||||
|
||||
pub fn emit_warnings(&self) -> CargoResult<()> {
|
||||
let ws_lints = self
|
||||
.root_maybe()
|
||||
.workspace_config()
|
||||
.inheritable()
|
||||
.and_then(|i| i.lints().ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
let ws_cargo_lints = ws_lints
|
||||
.get("cargo")
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.replace('-', "_"), v))
|
||||
.collect();
|
||||
|
||||
for (path, maybe_pkg) in &self.packages.packages {
|
||||
let path = path.join("Cargo.toml");
|
||||
if let MaybePackage::Package(pkg) = maybe_pkg {
|
||||
if self.gctx.cli_unstable().cargo_lints {
|
||||
self.emit_lints(pkg, &path)?
|
||||
self.emit_lints(pkg, &path, &ws_cargo_lints)?
|
||||
}
|
||||
}
|
||||
let warnings = match maybe_pkg {
|
||||
|
@ -1179,22 +1194,12 @@ impl<'gctx> Workspace<'gctx> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
|
||||
let ws_lints = self
|
||||
.root_maybe()
|
||||
.workspace_config()
|
||||
.inheritable()
|
||||
.and_then(|i| i.lints().ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
let ws_cargo_lints = ws_lints
|
||||
.get("cargo")
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.replace('-', "_"), v))
|
||||
.collect();
|
||||
|
||||
pub fn emit_lints(
|
||||
&self,
|
||||
pkg: &Package,
|
||||
path: &Path,
|
||||
ws_cargo_lints: &manifest::TomlToolLints,
|
||||
) -> CargoResult<()> {
|
||||
let mut error_count = 0;
|
||||
let toml_lints = pkg
|
||||
.manifest()
|
||||
|
@ -1212,11 +1217,21 @@ impl<'gctx> Workspace<'gctx> {
|
|||
.map(|(name, lint)| (name.replace('-', "_"), lint))
|
||||
.collect();
|
||||
|
||||
// We should only be using workspace lints if the `[lints]` table is
|
||||
// present in the manifest, and `workspace` is set to `true`
|
||||
let ws_cargo_lints = pkg
|
||||
.manifest()
|
||||
.resolved_toml()
|
||||
.lints
|
||||
.as_ref()
|
||||
.is_some_and(|l| l.workspace)
|
||||
.then(|| ws_cargo_lints);
|
||||
|
||||
check_im_a_teapot(
|
||||
pkg,
|
||||
&path,
|
||||
&normalized_lints,
|
||||
&ws_cargo_lints,
|
||||
ws_cargo_lints,
|
||||
&mut error_count,
|
||||
self.gctx,
|
||||
)?;
|
||||
|
@ -1224,7 +1239,7 @@ impl<'gctx> Workspace<'gctx> {
|
|||
pkg,
|
||||
&path,
|
||||
&normalized_lints,
|
||||
&ws_cargo_lints,
|
||||
ws_cargo_lints,
|
||||
&mut error_count,
|
||||
self.gctx,
|
||||
)?;
|
||||
|
@ -1232,7 +1247,7 @@ impl<'gctx> Workspace<'gctx> {
|
|||
pkg,
|
||||
&path,
|
||||
&normalized_lints,
|
||||
&ws_cargo_lints,
|
||||
ws_cargo_lints,
|
||||
&mut error_count,
|
||||
self.gctx,
|
||||
)?;
|
||||
|
|
|
@ -88,7 +88,7 @@ impl Lint {
|
|||
pub fn level(
|
||||
&self,
|
||||
pkg_lints: &TomlToolLints,
|
||||
ws_lints: &TomlToolLints,
|
||||
ws_lints: Option<&TomlToolLints>,
|
||||
edition: Edition,
|
||||
) -> (LintLevel, LintLevelReason) {
|
||||
self.groups
|
||||
|
@ -188,7 +188,7 @@ fn level_priority(
|
|||
default_level: LintLevel,
|
||||
edition_lint_opts: Option<(Edition, LintLevel)>,
|
||||
pkg_lints: &TomlToolLints,
|
||||
ws_lints: &TomlToolLints,
|
||||
ws_lints: Option<&TomlToolLints>,
|
||||
edition: Edition,
|
||||
) -> (LintLevel, LintLevelReason, i8) {
|
||||
let (unspecified_level, reason) = if let Some(level) = edition_lint_opts
|
||||
|
@ -211,7 +211,7 @@ fn level_priority(
|
|||
LintLevelReason::Package,
|
||||
defined_level.priority(),
|
||||
)
|
||||
} else if let Some(defined_level) = ws_lints.get(name) {
|
||||
} else if let Some(defined_level) = ws_lints.and_then(|l| l.get(name)) {
|
||||
(
|
||||
defined_level.level().into(),
|
||||
LintLevelReason::Workspace,
|
||||
|
@ -234,7 +234,7 @@ pub fn check_im_a_teapot(
|
|||
pkg: &Package,
|
||||
path: &Path,
|
||||
pkg_lints: &TomlToolLints,
|
||||
ws_lints: &TomlToolLints,
|
||||
ws_lints: Option<&TomlToolLints>,
|
||||
error_count: &mut usize,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<()> {
|
||||
|
@ -306,7 +306,7 @@ pub fn check_implicit_features(
|
|||
pkg: &Package,
|
||||
path: &Path,
|
||||
pkg_lints: &TomlToolLints,
|
||||
ws_lints: &TomlToolLints,
|
||||
ws_lints: Option<&TomlToolLints>,
|
||||
error_count: &mut usize,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<()> {
|
||||
|
@ -390,7 +390,7 @@ pub fn unused_dependencies(
|
|||
pkg: &Package,
|
||||
path: &Path,
|
||||
pkg_lints: &TomlToolLints,
|
||||
ws_lints: &TomlToolLints,
|
||||
ws_lints: Option<&TomlToolLints>,
|
||||
error_count: &mut usize,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<()> {
|
||||
|
|
|
@ -90,13 +90,15 @@ impl<T> SleepTracker<T> {
|
|||
#[test]
|
||||
fn returns_in_order() {
|
||||
let mut s = SleepTracker::new();
|
||||
s.push(3, 3);
|
||||
s.push(30_000, 30_000);
|
||||
s.push(1, 1);
|
||||
s.push(6, 6);
|
||||
s.push(5, 5);
|
||||
s.push(2, 2);
|
||||
s.push(10000, 10000);
|
||||
assert_eq!(s.len(), 6);
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
assert_eq!(s.to_retry(), &[1, 2, 3, 5, 6]);
|
||||
assert_eq!(s.len(), 2);
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
assert_eq!(s.to_retry(), &[1]);
|
||||
assert!(s.to_retry().is_empty());
|
||||
let next = s.time_to_next().expect("should be next");
|
||||
assert!(
|
||||
next < Duration::from_millis(30_000),
|
||||
"{next:?} should be less than 30s"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -451,12 +451,7 @@ fn resolve_toml(
|
|||
|
||||
resolved_toml.lints = original_toml.lints.clone();
|
||||
|
||||
let resolved_badges = original_toml
|
||||
.badges
|
||||
.clone()
|
||||
.map(|mw| field_inherit_with(mw, "badges", || inherit()?.badges()))
|
||||
.transpose()?;
|
||||
resolved_toml.badges = resolved_badges.map(manifest::InheritableField::Value);
|
||||
resolved_toml.badges = original_toml.badges.clone();
|
||||
} else {
|
||||
for field in original_toml.requires_package() {
|
||||
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
|
||||
|
@ -799,7 +794,6 @@ impl InheritableFields {
|
|||
package_field_getter! {
|
||||
// Please keep this list lexicographically ordered.
|
||||
("authors", authors -> Vec<String>),
|
||||
("badges", badges -> BTreeMap<String, BTreeMap<String, String>>),
|
||||
("categories", categories -> Vec<String>),
|
||||
("description", description -> String),
|
||||
("documentation", documentation -> String),
|
||||
|
@ -1340,11 +1334,7 @@ fn to_real_manifest(
|
|||
.expect("previously resolved")
|
||||
.cloned()
|
||||
.unwrap_or_default(),
|
||||
badges: resolved_toml
|
||||
.resolved_badges()
|
||||
.expect("previously resolved")
|
||||
.cloned()
|
||||
.unwrap_or_default(),
|
||||
badges: resolved_toml.badges.clone().unwrap_or_default(),
|
||||
links: resolved_package.links.clone(),
|
||||
rust_version: rust_version.clone(),
|
||||
};
|
||||
|
|
|
@ -30,9 +30,6 @@ fn permit_additional_workspace_fields() {
|
|||
exclude = ["foo.txt"]
|
||||
include = ["bar.txt", "**/*.rs", "Cargo.toml", "LICENSE", "README.md"]
|
||||
|
||||
[workspace.package.badges]
|
||||
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
|
||||
|
||||
[workspace.dependencies]
|
||||
dep = "0.1"
|
||||
"#,
|
||||
|
@ -117,8 +114,6 @@ fn inherit_own_workspace_fields() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
badges.workspace = true
|
||||
|
||||
[package]
|
||||
name = "foo"
|
||||
version.workspace = true
|
||||
|
@ -153,8 +148,6 @@ fn inherit_own_workspace_fields() {
|
|||
rust-version = "1.60"
|
||||
exclude = ["foo.txt"]
|
||||
include = ["bar.txt", "**/*.rs", "Cargo.toml"]
|
||||
[workspace.package.badges]
|
||||
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
|
@ -186,9 +179,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
|
|||
r#"
|
||||
{
|
||||
"authors": ["Rustaceans"],
|
||||
"badges": {
|
||||
"gitlab": { "branch": "master", "repository": "https://gitlab.com/rust-lang/rust" }
|
||||
},
|
||||
"badges": {},
|
||||
"categories": ["development-tools"],
|
||||
"deps": [],
|
||||
"description": "This is a crate",
|
||||
|
@ -240,10 +231,6 @@ keywords = ["cli"]
|
|||
categories = ["development-tools"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/example/example"
|
||||
|
||||
[badges.gitlab]
|
||||
branch = "master"
|
||||
repository = "https://gitlab.com/rust-lang/rust"
|
||||
"#,
|
||||
cargo::core::manifest::MANIFEST_PREAMBLE
|
||||
),
|
||||
|
@ -665,15 +652,12 @@ fn inherit_workspace_fields() {
|
|||
rust-version = "1.60"
|
||||
exclude = ["foo.txt"]
|
||||
include = ["bar.txt", "**/*.rs", "Cargo.toml", "LICENSE", "README.md"]
|
||||
[workspace.package.badges]
|
||||
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.file(
|
||||
"bar/Cargo.toml",
|
||||
r#"
|
||||
badges.workspace = true
|
||||
[package]
|
||||
name = "bar"
|
||||
workspace = ".."
|
||||
|
@ -731,9 +715,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
|
|||
r#"
|
||||
{
|
||||
"authors": ["Rustaceans"],
|
||||
"badges": {
|
||||
"gitlab": { "branch": "master", "repository": "https://gitlab.com/rust-lang/rust" }
|
||||
},
|
||||
"badges": {},
|
||||
"categories": ["development-tools"],
|
||||
"deps": [],
|
||||
"description": "This is a crate",
|
||||
|
@ -791,10 +773,6 @@ categories = ["development-tools"]
|
|||
license = "MIT"
|
||||
license-file = "LICENSE"
|
||||
repository = "https://github.com/example/example"
|
||||
|
||||
[badges.gitlab]
|
||||
branch = "master"
|
||||
repository = "https://gitlab.com/rust-lang/rust"
|
||||
"#,
|
||||
cargo::core::manifest::MANIFEST_PREAMBLE
|
||||
),
|
||||
|
@ -1715,8 +1693,6 @@ fn warn_inherit_unused_manifest_key_package() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
badges = { workspace = true, xyz = "abc"}
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
[workspace.package]
|
||||
|
@ -1734,8 +1710,6 @@ fn warn_inherit_unused_manifest_key_package() {
|
|||
rust-version = "1.60"
|
||||
exclude = ["foo.txt"]
|
||||
include = ["bar.txt", "**/*.rs", "Cargo.toml"]
|
||||
[workspace.package.badges]
|
||||
gitlab = { repository = "https://gitlab.com/rust-lang/rust", branch = "master" }
|
||||
|
||||
[package]
|
||||
name = "bar"
|
||||
|
|
|
@ -982,3 +982,43 @@ error: `im_a_teapot` is specified
|
|||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn dont_always_inherit_workspace_lints() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[workspace]
|
||||
members = ["foo"]
|
||||
|
||||
[workspace.lints.cargo]
|
||||
im-a-teapot = "warn"
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo/Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["test-dummy-unstable"]
|
||||
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
edition = "2015"
|
||||
authors = []
|
||||
im-a-teapot = true
|
||||
"#,
|
||||
)
|
||||
.file("foo/src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("check -Zcargo-lints")
|
||||
.masquerade_as_nightly_cargo(&["cargo-lints"])
|
||||
.with_stderr(
|
||||
"\
|
||||
[CHECKING] foo v0.0.1 ([CWD]/foo)
|
||||
[FINISHED] [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue