Skip to content

Commit c0c2dde

Browse files
committed
feat(im-a-teapot): Error if specified but not enabled
1 parent 8b25a84 commit c0c2dde

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/cargo/util/lints.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,39 @@ pub fn check_im_a_teapot(
247247
gctx: &GlobalContext,
248248
) -> CargoResult<()> {
249249
let manifest = pkg.manifest();
250+
let manifest_path = rel_cwd_manifest_path(path, gctx);
250251
let (lint_level, reason) = IM_A_TEAPOT.level(pkg_lints, ws_lints, manifest.edition());
251252

252253
if IM_A_TEAPOT.is_feature_gated(manifest) {
254+
if reason == LintLevelReason::Package || reason == LintLevelReason::Workspace {
255+
*error_count += 1;
256+
let span = get_span(
257+
manifest.document(),
258+
&["lints", "cargo", "im-a-teapot"],
259+
false,
260+
)
261+
.or(get_span(
262+
manifest.document(),
263+
&["lints", "cargo", "im_a_teapot"],
264+
false,
265+
))
266+
.unwrap();
267+
let message = Level::Error
268+
.title("use of unstable lint `im-a-teapot`")
269+
.snippet(
270+
Snippet::source(manifest.contents())
271+
.origin(&manifest_path)
272+
.annotation(Level::Error.span(span))
273+
.fold(true),
274+
);
275+
let renderer = Renderer::styled().term_width(
276+
gctx.shell()
277+
.err_width()
278+
.diagnostic_terminal_width()
279+
.unwrap_or(annotate_snippets::renderer::DEFAULT_TERM_WIDTH),
280+
);
281+
writeln!(gctx.shell().err(), "{}", renderer.render(message))?;
282+
}
253283
return Ok(());
254284
}
255285

@@ -266,7 +296,6 @@ pub fn check_im_a_teapot(
266296
*error_count += 1;
267297
}
268298
let level = lint_level.to_diagnostic_level();
269-
let manifest_path = rel_cwd_manifest_path(path, gctx);
270299
let emitted_reason = format!(
271300
"`cargo::{}` is set to `{lint_level}` {reason}",
272301
IM_A_TEAPOT.name

tests/testsuite/lints_table.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,11 +1100,15 @@ im-a-teapot = "warn"
11001100

11011101
p.cargo("check -Zcargo-lints")
11021102
.masquerade_as_nightly_cargo(&["cargo-lints"])
1103-
.with_status(0)
1103+
.with_status(101)
11041104
.with_stderr(
11051105
"\
1106-
[CHECKING] foo v0.0.1 ([CWD])
1107-
[FINISHED] [..]
1106+
error: use of unstable lint `im-a-teapot`
1107+
--> Cargo.toml:9:1
1108+
|
1109+
9 | im-a-teapot = \"warn\"
1110+
| ^^^^^^^^^^^
1111+
|
11081112
",
11091113
)
11101114
.run();

0 commit comments

Comments
 (0)