Skip to content

Commit cb435b9

Browse files
authored
Rollup merge of #150964 - list_all_attrs, r=jdonszelmann
Completely list all unparsed attributes Also introduce a `SPECIAL_ATTRIBUTES` list, since `cfg` was incorrectly being detected as an unparsed attribute in `check_attr`. I will also update #131229 (comment) r? @jdonszelmann
2 parents 78ad9f3 + eac7bda commit cb435b9

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,17 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
442442

443443
/// Returns whether there is a parser for an attribute with this name
444444
pub fn is_parsed_attribute(path: &[Symbol]) -> bool {
445-
Late::parsers().accepters.contains_key(path) || EARLY_PARSED_ATTRIBUTES.contains(&path)
445+
/// The list of attributes that are parsed attributes,
446+
/// even though they don't have a parser in `Late::parsers()`
447+
const SPECIAL_ATTRIBUTES: &[&[Symbol]] = &[
448+
// Cfg attrs are removed after being early-parsed, so don't need to be in the parser list
449+
&[sym::cfg],
450+
&[sym::cfg_attr],
451+
];
452+
453+
Late::parsers().accepters.contains_key(path)
454+
|| EARLY_PARSED_ATTRIBUTES.contains(&path)
455+
|| SPECIAL_ATTRIBUTES.contains(&path)
446456
}
447457

448458
fn lower_attr_args(&self, args: &ast::AttrArgs, lower_span: impl Fn(Span) -> Span) -> AttrArgs {

compiler/rustc_passes/src/check_attr.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
336336
| sym::warn
337337
| sym::deny
338338
| sym::forbid
339-
| sym::cfg
340-
| sym::cfg_attr
341339
// need to be fixed
342340
| sym::patchable_function_entry // FIXME(patchable_function_entry)
343341
| sym::deprecated_safe // FIXME(deprecated_safe)
@@ -346,7 +344,54 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
346344
| sym::panic_handler
347345
| sym::lang
348346
| sym::needs_allocator
349-
| sym::default_lib_allocator,
347+
| sym::default_lib_allocator
348+
| sym::rustc_diagnostic_item
349+
| sym::rustc_no_mir_inline
350+
| sym::rustc_insignificant_dtor
351+
| sym::rustc_nonnull_optimization_guaranteed
352+
| sym::rustc_intrinsic
353+
| sym::rustc_inherit_overflow_checks
354+
| sym::rustc_intrinsic_const_stable_indirect
355+
| sym::rustc_trivial_field_reads
356+
| sym::rustc_on_unimplemented
357+
| sym::rustc_do_not_const_check
358+
| sym::rustc_reservation_impl
359+
| sym::rustc_doc_primitive
360+
| sym::rustc_allocator
361+
| sym::rustc_deallocator
362+
| sym::rustc_reallocator
363+
| sym::rustc_conversion_suggestion
364+
| sym::rustc_allocator_zeroed
365+
| sym::rustc_allocator_zeroed_variant
366+
| sym::rustc_deprecated_safe_2024
367+
| sym::rustc_test_marker
368+
| sym::rustc_abi
369+
| sym::rustc_layout
370+
| sym::rustc_proc_macro_decls
371+
| sym::rustc_dump_def_parents
372+
| sym::rustc_never_type_options
373+
| sym::rustc_autodiff
374+
| sym::rustc_capture_analysis
375+
| sym::rustc_regions
376+
| sym::rustc_strict_coherence
377+
| sym::rustc_dump_predicates
378+
| sym::rustc_variance
379+
| sym::rustc_variance_of_opaques
380+
| sym::rustc_hidden_type_of_opaques
381+
| sym::rustc_mir
382+
| sym::rustc_dump_user_args
383+
| sym::rustc_effective_visibility
384+
| sym::rustc_outlives
385+
| sym::rustc_symbol_name
386+
| sym::rustc_evaluate_where_clauses
387+
| sym::rustc_dump_vtable
388+
| sym::rustc_delayed_bug_from_inside_query
389+
| sym::rustc_dump_item_bounds
390+
| sym::rustc_def_path
391+
| sym::rustc_partition_reused
392+
| sym::rustc_partition_codegened
393+
| sym::rustc_expected_cgu_reuse
394+
| sym::rustc_nounwind,
350395
..
351396
] => {}
352397
[name, rest@..] => {
@@ -361,15 +406,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
361406
continue
362407
}
363408

364-
// FIXME: differentiate between unstable and internal attributes just
365-
// like we do with features instead of just accepting `rustc_`
366-
// attributes by name. That should allow trimming the above list, too.
367-
if !name.as_str().starts_with("rustc_") {
368-
span_bug!(
369-
attr.span(),
370-
"builtin attribute {name:?} not handled by `CheckAttrVisitor`"
371-
)
372-
}
409+
span_bug!(
410+
attr.span(),
411+
"builtin attribute {name:?} not handled by `CheckAttrVisitor`"
412+
)
373413
}
374414
None => (),
375415
}

0 commit comments

Comments
 (0)