Skip to content

Commit b927b76

Browse files
Rollup merge of #152570 - Ozzy1423:attr-parse, r=JonathanBrouwer
Port #[rustc_test_marker] to the attribute parser Tracking issue: #131229 Targets: Const is for normal tests (const test::TestDescAndFn is inserted before the test fn) Const/Static/Fn is for custom_test_framework's #[test_case] e.g. tests/ui/custom_test_frameworks/full.rs r? @JonathanBrouwer Again I left the use-sites as is since they are early uses.
2 parents 82ef932 + 250ce84 commit b927b76

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,36 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
257257
Some(AttributeKind::TestRunner(meta.path().0.clone()))
258258
}
259259
}
260+
261+
pub(crate) struct RustcTestMarkerParser;
262+
263+
impl<S: Stage> SingleAttributeParser<S> for RustcTestMarkerParser {
264+
const PATH: &[Symbol] = &[sym::rustc_test_marker];
265+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
266+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
267+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
268+
Allow(Target::Const),
269+
Allow(Target::Fn),
270+
Allow(Target::Static),
271+
]);
272+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "test_path");
273+
274+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
275+
let Some(name_value) = args.name_value() else {
276+
cx.expected_name_value(cx.attr_span, Some(sym::rustc_test_marker));
277+
return None;
278+
};
279+
280+
let Some(value_str) = name_value.value_as_str() else {
281+
cx.expected_string_literal(name_value.value_span, None);
282+
return None;
283+
};
284+
285+
if value_str.as_str().trim().is_empty() {
286+
cx.expected_non_empty_string_literal(name_value.value_span);
287+
return None;
288+
}
289+
290+
Some(AttributeKind::RustcTestMarker(value_str))
291+
}
292+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ attribute_parsers!(
216216
Single<RustcScalableVectorParser>,
217217
Single<RustcSimdMonomorphizeLaneLimitParser>,
218218
Single<RustcSymbolName>,
219+
Single<RustcTestMarkerParser>,
219220
Single<SanitizeParser>,
220221
Single<ShouldPanicParser>,
221222
Single<SkipDuringMethodDispatchParser>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,9 @@ pub enum AttributeKind {
13321332
/// Represents `#[rustc_symbol_name]`
13331333
RustcSymbolName(Span),
13341334

1335+
/// Represents `#[rustc_test_marker]`
1336+
RustcTestMarker(Symbol),
1337+
13351338
/// Represents `#[rustc_then_this_would_need]`
13361339
RustcThenThisWouldNeed(Span, ThinVec<Ident>),
13371340

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl AttributeKind {
169169
RustcStdInternalSymbol(..) => No,
170170
RustcStrictCoherence(..) => Yes,
171171
RustcSymbolName(..) => Yes,
172+
RustcTestMarker(..) => No,
172173
RustcThenThisWouldNeed(..) => No,
173174
RustcTrivialFieldReads => Yes,
174175
RustcUnsafeSpecializationMarker(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
360360
| AttributeKind::RustcStdInternalSymbol (..)
361361
| AttributeKind::RustcStrictCoherence(..)
362362
| AttributeKind::RustcSymbolName(..)
363+
| AttributeKind::RustcTestMarker(..)
363364
| AttributeKind::RustcThenThisWouldNeed(..)
364365
| AttributeKind::RustcTrivialFieldReads
365366
| AttributeKind::RustcUnsafeSpecializationMarker(..)
@@ -402,7 +403,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
402403
| sym::rustc_on_unimplemented
403404
| sym::rustc_do_not_const_check
404405
| sym::rustc_doc_primitive
405-
| sym::rustc_test_marker
406406
| sym::rustc_layout
407407
| sym::rustc_proc_macro_decls
408408
| sym::rustc_autodiff

0 commit comments

Comments
 (0)