Skip to content

Commit 8a73841

Browse files
committed
Auto merge of #13853 - Muscraft:beta-revert-seperating-lints, r=epage
[beta-1.79] Prevent inheritance from bring exposed for published packages Beta backports: - #13852 In order to make CI pass, the following PRs are also cherry-picked: -
2 parents b60a155 + 599ca24 commit 8a73841

File tree

4 files changed

+28
-71
lines changed

4 files changed

+28
-71
lines changed

src/cargo/core/workspace.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,21 +1180,6 @@ impl<'gctx> Workspace<'gctx> {
11801180
}
11811181

11821182
pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
1183-
let ws_lints = self
1184-
.root_maybe()
1185-
.workspace_config()
1186-
.inheritable()
1187-
.and_then(|i| i.lints().ok())
1188-
.unwrap_or_default();
1189-
1190-
let ws_cargo_lints = ws_lints
1191-
.get("cargo")
1192-
.cloned()
1193-
.unwrap_or_default()
1194-
.into_iter()
1195-
.map(|(k, v)| (k.replace('-', "_"), v))
1196-
.collect();
1197-
11981183
let mut error_count = 0;
11991184
let toml_lints = pkg
12001185
.manifest()
@@ -1212,30 +1197,9 @@ impl<'gctx> Workspace<'gctx> {
12121197
.map(|(name, lint)| (name.replace('-', "_"), lint))
12131198
.collect();
12141199

1215-
check_im_a_teapot(
1216-
pkg,
1217-
&path,
1218-
&normalized_lints,
1219-
&ws_cargo_lints,
1220-
&mut error_count,
1221-
self.gctx,
1222-
)?;
1223-
check_implicit_features(
1224-
pkg,
1225-
&path,
1226-
&normalized_lints,
1227-
&ws_cargo_lints,
1228-
&mut error_count,
1229-
self.gctx,
1230-
)?;
1231-
unused_dependencies(
1232-
pkg,
1233-
&path,
1234-
&normalized_lints,
1235-
&ws_cargo_lints,
1236-
&mut error_count,
1237-
self.gctx,
1238-
)?;
1200+
check_im_a_teapot(pkg, &path, &normalized_lints, &mut error_count, self.gctx)?;
1201+
check_implicit_features(pkg, &path, &normalized_lints, &mut error_count, self.gctx)?;
1202+
unused_dependencies(pkg, &path, &normalized_lints, &mut error_count, self.gctx)?;
12391203
if error_count > 0 {
12401204
Err(crate::util::errors::AlreadyPrintedError::new(anyhow!(
12411205
"encountered {error_count} errors(s) while running lints"

src/cargo/util/lints.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl Lint {
8888
pub fn level(
8989
&self,
9090
pkg_lints: &TomlToolLints,
91-
ws_lints: &TomlToolLints,
9291
edition: Edition,
9392
) -> (LintLevel, LintLevelReason) {
9493
self.groups
@@ -101,7 +100,6 @@ impl Lint {
101100
g.default_level,
102101
g.edition_lint_opts,
103102
pkg_lints,
104-
ws_lints,
105103
edition,
106104
),
107105
)
@@ -113,7 +111,6 @@ impl Lint {
113111
self.default_level,
114112
self.edition_lint_opts,
115113
pkg_lints,
116-
ws_lints,
117114
edition,
118115
),
119116
)))
@@ -169,7 +166,6 @@ pub enum LintLevelReason {
169166
Default,
170167
Edition(Edition),
171168
Package,
172-
Workspace,
173169
}
174170

175171
impl Display for LintLevelReason {
@@ -178,7 +174,6 @@ impl Display for LintLevelReason {
178174
LintLevelReason::Default => write!(f, "by default"),
179175
LintLevelReason::Edition(edition) => write!(f, "in edition {}", edition),
180176
LintLevelReason::Package => write!(f, "in `[lints]`"),
181-
LintLevelReason::Workspace => write!(f, "in `[workspace.lints]`"),
182177
}
183178
}
184179
}
@@ -188,7 +183,6 @@ fn level_priority(
188183
default_level: LintLevel,
189184
edition_lint_opts: Option<(Edition, LintLevel)>,
190185
pkg_lints: &TomlToolLints,
191-
ws_lints: &TomlToolLints,
192186
edition: Edition,
193187
) -> (LintLevel, LintLevelReason, i8) {
194188
let (unspecified_level, reason) = if let Some(level) = edition_lint_opts
@@ -211,12 +205,6 @@ fn level_priority(
211205
LintLevelReason::Package,
212206
defined_level.priority(),
213207
)
214-
} else if let Some(defined_level) = ws_lints.get(name) {
215-
(
216-
defined_level.level().into(),
217-
LintLevelReason::Workspace,
218-
defined_level.priority(),
219-
)
220208
} else {
221209
(unspecified_level, reason, 0)
222210
}
@@ -234,12 +222,11 @@ pub fn check_im_a_teapot(
234222
pkg: &Package,
235223
path: &Path,
236224
pkg_lints: &TomlToolLints,
237-
ws_lints: &TomlToolLints,
238225
error_count: &mut usize,
239226
gctx: &GlobalContext,
240227
) -> CargoResult<()> {
241228
let manifest = pkg.manifest();
242-
let (lint_level, reason) = IM_A_TEAPOT.level(pkg_lints, ws_lints, manifest.edition());
229+
let (lint_level, reason) = IM_A_TEAPOT.level(pkg_lints, manifest.edition());
243230
if lint_level == LintLevel::Allow {
244231
return Ok(());
245232
}
@@ -306,7 +293,6 @@ pub fn check_implicit_features(
306293
pkg: &Package,
307294
path: &Path,
308295
pkg_lints: &TomlToolLints,
309-
ws_lints: &TomlToolLints,
310296
error_count: &mut usize,
311297
gctx: &GlobalContext,
312298
) -> CargoResult<()> {
@@ -317,7 +303,7 @@ pub fn check_implicit_features(
317303
return Ok(());
318304
}
319305

320-
let (lint_level, reason) = IMPLICIT_FEATURES.level(pkg_lints, ws_lints, edition);
306+
let (lint_level, reason) = IMPLICIT_FEATURES.level(pkg_lints, edition);
321307
if lint_level == LintLevel::Allow {
322308
return Ok(());
323309
}
@@ -390,7 +376,6 @@ pub fn unused_dependencies(
390376
pkg: &Package,
391377
path: &Path,
392378
pkg_lints: &TomlToolLints,
393-
ws_lints: &TomlToolLints,
394379
error_count: &mut usize,
395380
gctx: &GlobalContext,
396381
) -> CargoResult<()> {
@@ -400,7 +385,7 @@ pub fn unused_dependencies(
400385
return Ok(());
401386
}
402387

403-
let (lint_level, reason) = UNUSED_OPTIONAL_DEPENDENCY.level(pkg_lints, ws_lints, edition);
388+
let (lint_level, reason) = UNUSED_OPTIONAL_DEPENDENCY.level(pkg_lints, edition);
404389
if lint_level == LintLevel::Allow {
405390
return Ok(());
406391
}

src/cargo/util/toml/mod.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,15 @@ fn resolve_toml(
449449
}
450450
resolved_toml.target = (!resolved_target.is_empty()).then_some(resolved_target);
451451

452-
resolved_toml.lints = original_toml.lints.clone();
452+
let resolved_lints = original_toml
453+
.lints
454+
.clone()
455+
.map(|value| lints_inherit_with(value, || inherit()?.lints()))
456+
.transpose()?;
457+
resolved_toml.lints = resolved_lints.map(|lints| manifest::InheritableLints {
458+
workspace: false,
459+
lints,
460+
});
453461

454462
let resolved_badges = original_toml
455463
.badges
@@ -1283,18 +1291,18 @@ fn to_real_manifest(
12831291
}
12841292
}
12851293

1286-
let resolved_lints = resolved_toml
1287-
.lints
1288-
.clone()
1289-
.map(|value| {
1290-
lints_inherit_with(value, || {
1291-
load_inheritable_fields(gctx, manifest_file, &workspace_config)?.lints()
1292-
})
1293-
})
1294-
.transpose()?;
1295-
1296-
verify_lints(resolved_lints.as_ref(), gctx, warnings)?;
1297-
let rustflags = lints_to_rustflags(&resolved_lints.unwrap_or_default());
1294+
verify_lints(
1295+
resolved_toml.resolved_lints().expect("previously resolved"),
1296+
gctx,
1297+
warnings,
1298+
)?;
1299+
let default = manifest::TomlLints::default();
1300+
let rustflags = lints_to_rustflags(
1301+
resolved_toml
1302+
.resolved_lints()
1303+
.expect("previously resolved")
1304+
.unwrap_or(&default),
1305+
);
12981306

12991307
let metadata = ManifestMetadata {
13001308
description: resolved_package

tests/testsuite/lints_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ error: `im_a_teapot` is specified
977977
13 | im-a-teapot = true
978978
| ^^^^^^^^^^^^^^^^^^
979979
|
980-
= note: `cargo::im_a_teapot` is set to `forbid` in `[workspace.lints]`
980+
= note: `cargo::im_a_teapot` is set to `forbid` in `[lints]`
981981
",
982982
)
983983
.run();

0 commit comments

Comments
 (0)