正在載入此比較的其餘部分。

Untitled diff

建立於 差異永不過期
2 刪除
657 行
2 新增
657 行
From 552d971ea849519a743457cc52a16f8d11e57539 Mon Sep 17 00:00:00 2001
From 1864bf6a510a7e9df23777591f3389b6feb27e90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= <jana@donsz.nl>
From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= <jana@donsz.nl>
Date: Sat, 18 Oct 2025 11:25:13 +0200
Date: Sat, 18 Oct 2025 11:25:13 +0200
Subject: [PATCH 1/3] ICE when applying test to crate root
Subject: [PATCH 1/3] ICE when applying test to crate root


---
---
tests/crashes/114920.rs | 2 --
tests/crashes/114920.rs | 2 --
tests/ui/macros/test-on-crate-root.rs | 8 ++++++++
tests/ui/macros/test-on-crate-root.rs | 8 ++++++++
2 files changed, 8 insertions(+), 2 deletions(-)
2 files changed, 8 insertions(+), 2 deletions(-)
delete mode 100644 tests/crashes/114920.rs
delete mode 100644 tests/crashes/114920.rs
create mode 100644 tests/ui/macros/test-on-crate-root.rs
create mode 100644 tests/ui/macros/test-on-crate-root.rs


diff --git a/tests/crashes/114920.rs b/tests/crashes/114920.rs
diff --git a/tests/crashes/114920.rs b/tests/crashes/114920.rs
deleted file mode 100644
deleted file mode 100644
index 9aa7598e10fc3..0000000000000
index 9aa7598e10fc3..0000000000000
--- a/tests/crashes/114920.rs
--- a/tests/crashes/114920.rs
+++ /dev/null
+++ /dev/null
@@ -1,2 +0,0 @@
@@ -1,2 +0,0 @@
-//@ known-bug: #114920
-//@ known-bug: #114920
-#![core::prelude::v1::test]
-#![core::prelude::v1::test]
diff --git a/tests/ui/macros/test-on-crate-root.rs b/tests/ui/macros/test-on-crate-root.rs
diff --git a/tests/ui/macros/test-on-crate-root.rs b/tests/ui/macros/test-on-crate-root.rs
new file mode 100644
new file mode 100644
index 0000000000000..80635a458902d
index 0000000000000..80635a458902d
--- /dev/null
--- /dev/null
+++ b/tests/ui/macros/test-on-crate-root.rs
+++ b/tests/ui/macros/test-on-crate-root.rs
@@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
+// ICE when applying `#![test]` to the crate root,
+// ICE when applying `#![test]` to the crate root,
+// though only when specified with a full path. `#![test]` is not enough.
+// though only when specified with a full path. `#![test]` is not enough.
+// Fixes #114920
+// Fixes #114920
+#![core::prelude::v1::test]
+#![core::prelude::v1::test]
+
+
+
+
+
+
+fn main() {} // not important to reproduce the issue
+fn main() {} // not important to reproduce the issue


From 00b0d26f447d7c62a05414267984f7086a6df5f5 Mon Sep 17 00:00:00 2001
From 9dd3caeebefbb36f90ea13e5ec4b37048067ca59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= <jana@donsz.nl>
From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= <jana@donsz.nl>
Date: Sat, 18 Oct 2025 12:10:21 +0200
Date: Sat, 18 Oct 2025 12:10:21 +0200
Subject: [PATCH 2/3] only discard items with `#[test]` on it when target is
Subject: [PATCH 2/3] only discard items with `#[test]` on it when target is
valid
valid


---
---
compiler/rustc_builtin_macros/src/test.rs | 20 +-
compiler/rustc_builtin_macros/src/test.rs | 20 +-
.../ui/feature-gates/gating-of-test-attrs.rs | 48 +++
.../ui/feature-gates/gating-of-test-attrs.rs | 48 +++
.../feature-gates/gating-of-test-attrs.stderr | 181 +++++++++++
.../feature-gates/gating-of-test-attrs.stderr | 181 +++++++++++
.../issue-43106-gating-of-builtin-attrs.rs | 32 --
.../issue-43106-gating-of-builtin-attrs.rs | 32 --
...issue-43106-gating-of-builtin-attrs.stderr | 304 +++++++++---------
...issue-43106-gating-of-builtin-attrs.stderr | 304 +++++++++---------
tests/ui/macros/attr-empty-expr.rs | 11 -
tests/ui/macros/attr-empty-expr.rs | 11 -
tests/ui/macros/attr-empty-expr.stderr | 20 --
tests/ui/macros/attr-empty-expr.stderr | 20 --
tests/ui/macros/issue-111749.rs | 4 +-
tests/ui/macros/issue-111749.rs | 4 +-
tests/ui/macros/issue-111749.stderr | 16 +-
tests/ui/macros/issue-111749.stderr | 16 +-
tests/ui/macros/test-on-crate-root.rs | 3 +-
tests/ui/macros/test-on-crate-root.rs | 3 +-
tests/ui/macros/test-on-crate-root.stderr | 25 ++
tests/ui/macros/test-on-crate-root.stderr | 25 ++
11 files changed, 431 insertions(+), 233 deletions(-)
11 files changed, 431 insertions(+), 233 deletions(-)
create mode 100644 tests/ui/feature-gates/gating-of-test-attrs.rs
create mode 100644 tests/ui/feature-gates/gating-of-test-attrs.rs
create mode 100644 tests/ui/feature-gates/gating-of-test-attrs.stderr
create mode 100644 tests/ui/feature-gates/gating-of-test-attrs.stderr
delete mode 100644 tests/ui/macros/attr-empty-expr.rs
delete mode 100644 tests/ui/macros/attr-empty-expr.rs
delete mode 100644 tests/ui/macros/attr-empty-expr.stderr
delete mode 100644 tests/ui/macros/attr-empty-expr.stderr
create mode 100644 tests/ui/macros/test-on-crate-root.stderr
create mode 100644 tests/ui/macros/test-on-crate-root.stderr


diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
index 532539f893aed..8f6244e418fdb 100644
index 532539f893aed..8f6244e418fdb 100644
--- a/compiler/rustc_builtin_macros/src/test.rs
--- a/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
@@ -34,10 +34,6 @@ pub(crate) fn expand_test_case(
@@ -34,10 +34,6 @@ pub(crate) fn expand_test_case(
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
- if !ecx.ecfg.should_test {
- if !ecx.ecfg.should_test {
- return vec![];
- return vec![];
- }
- }
-
-
let sp = ecx.with_def_site_ctxt(attr_sp);
let sp = ecx.with_def_site_ctxt(attr_sp);
let (mut item, is_stmt) = match anno_item {
let (mut item, is_stmt) = match anno_item {
Annotatable::Item(item) => (item, false),
Annotatable::Item(item) => (item, false),
@@ -54,6 +50,10 @@ pub(crate) fn expand_test_case(
@@ -54,6 +50,10 @@ pub(crate) fn expand_test_case(
}
}
};
};
+ if !ecx.ecfg.should_test {
+ if !ecx.ecfg.should_test {
+ return vec![];
+ return vec![];
+ }
+ }
+
+
// `#[test_case]` is valid on functions, consts, and statics. Only modify
// `#[test_case]` is valid on functions, consts, and statics. Only modify
// the item in those cases.
// the item in those cases.
match &mut item.kind {
match &mut item.kind {
@@ -113,11 +113,6 @@ pub(crate) fn expand_test_or_bench(
@@ -113,11 +113,6 @@ pub(crate) fn expand_test_or_bench(
item: Annotatable,
item: Annotatable,
is_bench: bool,
is_bench: bool,
) -> Vec<Annotatable> {
) -> Vec<Annotatable> {
- // If we're not in test configuration, remove the annotated item
- // If we're not in test configuration, remove the annotated item
- if !cx.ecfg.should_test {
- if !cx.ecfg.should_test {
- return vec![];
- return vec![];
- }
- }
-
-
let (item, is_stmt) = match item {
let (item, is_stmt) = match item {
Annotatable::Item(i) => (i, false),
Annotatable::Item(i) => (i, false),
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
@@ -136,6 +131,11 @@ pub(crate) fn expand_test_or_bench(
@@ -136,6 +131,11 @@ pub(crate) fn expand_test_or_bench(
};
};