Skip to content

Commit ec211c5

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 d244f65 + 250ce84 commit ec211c5

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
@@ -1329,6 +1329,9 @@ pub enum AttributeKind {
13291329
/// Represents `#[rustc_symbol_name]`
13301330
RustcSymbolName(Span),
13311331

1332+
/// Represents `#[rustc_test_marker]`
1333+
RustcTestMarker(Symbol),
1334+
13321335
/// Represents `#[rustc_then_this_would_need]`
13331336
RustcThenThisWouldNeed(Span, ThinVec<Ident>),
13341337

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

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

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
359359
| AttributeKind::RustcStdInternalSymbol (..)
360360
| AttributeKind::RustcStrictCoherence(..)
361361
| AttributeKind::RustcSymbolName(..)
362+
| AttributeKind::RustcTestMarker(..)
362363
| AttributeKind::RustcThenThisWouldNeed(..)
363364
| AttributeKind::RustcTrivialFieldReads
364365
| 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)