Skip to content

Commit 0730678

Browse files
authored
Make annotations mandatory for internal ui tests (#14393)
Last part of #11421. Now all ui tests require annotations. The change in `ui_test` is to add `ICE:` errors. changelog: Make internals ui tests annotations mandatory r? @flip1995
2 parents 714c64c + 092a20e commit 0730678

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ anstream = "0.6.18"
3333

3434
[dev-dependencies]
3535
cargo_metadata = "0.18.1"
36-
ui_test = "0.26.4"
36+
ui_test = "0.29.2"
3737
regex = "1.5.5"
3838
serde = { version = "1.0.145", features = ["derive"] }
3939
serde_json = "1.0.122"

clippy_lints/src/utils/internal_lints/produce_ice.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ast::NodeId;
22
use rustc_ast::visit::FnKind;
3-
use rustc_lint::{EarlyContext, EarlyLintPass};
3+
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
44
use rustc_session::declare_lint_pass;
55
use rustc_span::Span;
66

@@ -24,8 +24,12 @@ declare_clippy_lint! {
2424
declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
2525

2626
impl EarlyLintPass for ProduceIce {
27-
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
28-
assert!(!is_trigger_fn(fn_kind), "Would you like some help with that?");
27+
fn check_fn(&mut self, ctx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) {
28+
if is_trigger_fn(fn_kind) {
29+
ctx.sess()
30+
.dcx()
31+
.span_delayed_bug(span, "Would you like some help with that?");
32+
}
2933
}
3034
}
3135

tests/compile-test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
1616
use ui_test::custom_flags::Flag;
1717
use ui_test::custom_flags::rustfix::RustfixMode;
1818
use ui_test::spanned::Spanned;
19-
use ui_test::{Args, CommandBuilder, Config, Match, OutputConflictHandling, status_emitter};
19+
use ui_test::{Args, CommandBuilder, Config, Match, error_on_output_conflict, status_emitter};
2020

2121
use std::collections::{BTreeMap, HashMap};
2222
use std::env::{self, set_var, var_os};
@@ -142,7 +142,7 @@ impl TestContext {
142142
fn base_config(&self, test_dir: &str, mandatory_annotations: bool) -> Config {
143143
let target_dir = PathBuf::from(var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into()));
144144
let mut config = Config {
145-
output_conflict_handling: OutputConflictHandling::Error,
145+
output_conflict_handling: error_on_output_conflict,
146146
filter_files: env::var("TESTNAME")
147147
.map(|filters| filters.split(',').map(str::to_string).collect())
148148
.unwrap_or_default(),
@@ -220,7 +220,7 @@ fn run_internal_tests(cx: &TestContext) {
220220
if !RUN_INTERNAL_TESTS {
221221
return;
222222
}
223-
let mut config = cx.base_config("ui-internal", false);
223+
let mut config = cx.base_config("ui-internal", true);
224224
config.bless_command = Some("cargo uitest --features internal -- -- --bless".into());
225225

226226
ui_test::run_tests_generic(

tests/lint_message_convention.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl Message {
4444
".*AT&T x86 assembly syntax used",
4545
"note: Clippy version: .*",
4646
"the compiler unexpectedly panicked. this is a bug.",
47+
"internal compiler error:",
4748
])
4849
.unwrap()
4950
});

tests/ui-internal/custom_ice_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
#![allow(clippy::missing_clippy_version_attribute)]
1111

1212
fn it_looks_like_you_are_trying_to_kill_clippy() {}
13+
//~^ ice: Would you like some help with that?
1314

1415
fn main() {}
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
2-
thread '<unnamed>' panicked at clippy_lints/src/utils/internal_lints/produce_ice.rs:
3-
Would you like some help with that?
4-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
5-
6-
error: the compiler unexpectedly panicked. this is a bug.
1+
note: no errors encountered even though delayed bugs were created
2+
3+
note: those delayed bugs will now be shown as internal compiler errors
4+
5+
error: internal compiler error: Would you like some help with that?
6+
--> tests/ui-internal/custom_ice_message.rs:12:1
7+
|
8+
LL | fn it_looks_like_you_are_trying_to_kill_clippy() {}
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
|
11+
note: delayed at clippy_lints/src/utils/internal_lints/produce_ice.rs - disabled backtrace
12+
--> tests/ui-internal/custom_ice_message.rs:12:1
13+
|
14+
LL | fn it_looks_like_you_are_trying_to_kill_clippy() {}
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
716

817
note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml
918

@@ -13,9 +22,5 @@ note: rustc <version> running on <target>
1322

1423
note: compiler flags: -Z ui-testing -Z deduplicate-diagnostics=no
1524

16-
query stack during panic:
17-
#0 [early_lint_checks] perform lints prior to AST lowering
18-
#1 [hir_crate] getting the crate HIR
19-
... and 3 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
2025
note: Clippy version: foo
2126

0 commit comments

Comments
 (0)