Revert "Add rustc_test_entrypoint_marker"
Project: rust-lang/rust | Language: Rust | Concepts: backwards-compatibility, testing-strategy, api-design | Difficulty: mid
Link: https://github.com/rust-lang/rust/pull/161931
The problem
A recent change added the unstable #[rustc_test_entrypoint_marker] attribute to test functions, but this caused two regressions on the beta channel:
- Issue #161920: Attribute count mismatches in proc-macro test introspection.
- Issue #161917: Problems when test attributes are manipulated by macros that remove or reorder spans/attributes.
The revert was needed to restore correct behavior for users and downstream tools.
Why it's non-trivial
Simply removing the attribute is not enough:
- The attribute was added in multiple places (AST, attribute parsing, symbol list, macro expansion, tests).
- Removing it required careful conflict resolution and ensuring all traces were gone.
- The revert also had to restore or add regression tests to ensure the original breakages are now caught.
The approach
1. Remove the attribute variant from the IR and all match arms
- /// Represents `#[rustc_test_entrypoint_marker]`
- RustcTestEntrypointMarker,
This removes the variant from the AttributeKind enum, so the compiler no longer recognizes the attribute.
2. Remove the parser and registration for the attribute
-pub(crate) struct RustcTestEntrypointMarkerParser;
-
-impl NoArgsAttributeParser for RustcTestEntrypointMarkerParser {
- const PATH: &[Symbol] = &[sym::rustc_test_entrypoint_marker];
- const ALLOWED_TARGETS: AllowedTargets<'_> =
- AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::Closure)]);
- const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
- const STABILITY: AttributeStability = unstable!(rustc_attrs);
- const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcTestEntrypointMarker;
-}
This removes the code that would parse and recognize the attribute in source code.
3. Remove the attribute from the macro expansion logic
- let item = {
- let mut item = item;
- item.attrs.push(cx.attr_word(sym::rustc_test_entrypoint_marker, attr_sp));
- item
- };
This ensures that the macro which generates test functions no longer adds the marker attribute.
4. Remove the attribute from the symbol table and built-in attribute lists
- sym::rustc_test_entrypoint_marker,
This cleans up the symbol list, so the compiler doesn't recognize the attribute at all.
5. Remove test code that depended on the attribute
-diff --git a/tests/ui-fulldeps/test_entrypoint_attrs.rs b/tests/ui-fulldeps/test_entrypoint_attrs.rs
-deleted file mode 100644
The test that checked for the presence of #[rustc_test_entrypoint_marker] is deleted, since the attribute no longer exists.
6. Add/restore regression tests for the original issues
New/updated tests are added to check:
- That test attributes can be manipulated by macros without causing errors.
- That proc macros see the expected number of attributes on test functions.
Example:
+#[test]
+#[test_count_attributes::assert_no_attributes]
+fn meow1() {}
This ensures that the attribute count is as expected, fixing the regression.
From the review thread
[N1ark] this is really unfortunate :( i wonder if we can fix this later; #161920 seems to just be an issue in the
test_retrymacro that needs fixing anyways, but idk what to do about #161917
[JonathanBrouwer] Yeah https://github.com/rust-lang/rust/issues/161917 is the annoying one of the two. For beta the safe thing to do is just to revert. For on nightly we might be able to re-land this as a synthetic attribute? I'd love to find a way to still have this without breakage
Takeaways
- Unstable or internal attributes can easily break downstream tools and workflows, even if they seem harmless.
- Reverting a feature often requires careful cleanup across all layers: parsing, IR, macro expansion, symbol tables, and tests.
- Regression tests should be added for any bug found during feature rollout, to prevent silent reintroduction of the same issue.