Skip to content

Commit 86349e3

Browse files
Port #[omit_gdb_pretty_printer_section] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
1 parent 915e535 commit 86349e3

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ pub enum AttributeKind {
328328
/// Represents `#[non_exhaustive]`
329329
NonExhaustive(Span),
330330

331+
/// Represents `#[omit_gdb_pretty_printer_section]`
332+
OmitGdbPrettyPrinterSection,
333+
331334
/// Represents `#[optimize(size|speed)]`
332335
Optimize(OptimizeAttr, Span),
333336

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl AttributeKind {
5050
NoImplicitPrelude(..) => No,
5151
NoMangle(..) => No,
5252
NonExhaustive(..) => Yes,
53+
OmitGdbPrettyPrinterSection => No,
5354
Optimize(..) => No,
5455
ParenSugar(..) => No,
5556
PassByValue(..) => Yes,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,11 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
334334
features
335335
}
336336
}
337+
338+
pub(crate) struct OmitGdbPrettyPrinterSectionParser;
339+
340+
impl<S: Stage> NoArgsAttributeParser<S> for OmitGdbPrettyPrinterSectionParser {
341+
const PATH: &[Symbol] = &[sym::omit_gdb_pretty_printer_section];
342+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
343+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::OmitGdbPrettyPrinterSection;
344+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1818
use crate::attributes::codegen_attrs::{
19-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TargetFeatureParser,
20-
TrackCallerParser, UsedParser,
19+
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
20+
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
2121
};
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
@@ -171,6 +171,7 @@ attribute_parsers!(
171171
Single<WithoutArgs<NoImplicitPreludeParser>>,
172172
Single<WithoutArgs<NoMangleParser>>,
173173
Single<WithoutArgs<NonExhaustiveParser>>,
174+
Single<WithoutArgs<OmitGdbPrettyPrinterSectionParser>>,
174175
Single<WithoutArgs<ParenSugarParser>>,
175176
Single<WithoutArgs<PassByValueParser>>,
176177
Single<WithoutArgs<PubTransparentParser>>,

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// .debug_gdb_scripts binary section.
22

3-
use rustc_ast::attr;
3+
use rustc_attr_data_structures::{AttributeKind, find_attr};
44
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
55
use rustc_codegen_ssa::traits::*;
66
use rustc_hir::def_id::LOCAL_CRATE;
77
use rustc_middle::bug;
88
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
99
use rustc_session::config::{CrateType, DebugInfo};
10-
use rustc_span::sym;
1110

1211
use crate::builder::Builder;
1312
use crate::common::CodegenCx;
@@ -87,7 +86,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8786

8887
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
8988
let omit_gdb_pretty_printer_section =
90-
attr::contains_name(cx.tcx.hir_krate_attrs(), sym::omit_gdb_pretty_printer_section);
89+
find_attr!(cx.tcx.hir_krate_attrs(), AttributeKind::OmitGdbPrettyPrinterSection);
9190

9291
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
9392
// ODR violations at link time, this section will not be emitted for rlibs since

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ pub fn check_builtin_meta_item(
305305
| sym::naked
306306
| sym::no_mangle
307307
| sym::non_exhaustive
308+
| sym::omit_gdb_pretty_printer_section
308309
| sym::path
309310
| sym::ignore
310311
| sym::must_use

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
240240
AttributeKind::BodyStability { .. }
241241
| AttributeKind::ConstStabilityIndirect
242242
| AttributeKind::MacroTransparency(_)
243-
| AttributeKind::Dummy,
243+
| AttributeKind::Dummy
244+
| AttributeKind::OmitGdbPrettyPrinterSection,
244245
) => { /* do nothing */ }
245246
Attribute::Parsed(AttributeKind::AsPtr(attr_span)) => {
246247
self.check_applied_to_fn_or_method(hir_id, *attr_span, span, target)
@@ -369,7 +370,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
369370
// need to be fixed
370371
| sym::cfi_encoding // FIXME(cfi_encoding)
371372
| sym::pointee // FIXME(derive_coerce_pointee)
372-
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
373373
| sym::instruction_set // broken on stable!!!
374374
| sym::windows_subsystem // broken on stable!!!
375375
| sym::patchable_function_entry // FIXME(patchable_function_entry)

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ error[E0463]: can't find crate for `wloop`
2222
LL | extern crate wloop;
2323
| ^^^^^^^^^^^^^^^^^^^ can't find crate
2424

25-
error: malformed `omit_gdb_pretty_printer_section` attribute input
26-
--> $DIR/malformed-attrs.rs:26:1
27-
|
28-
LL | #![omit_gdb_pretty_printer_section = 1]
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![omit_gdb_pretty_printer_section]`
30-
3125
error: malformed `windows_subsystem` attribute input
3226
--> $DIR/malformed-attrs.rs:29:1
3327
|
@@ -283,6 +277,15 @@ LL | #[debugger_visualizer]
283277
= note: OR
284278
= note: expected: `gdb_script_file = "..."`
285279

280+
error[E0565]: malformed `omit_gdb_pretty_printer_section` attribute input
281+
--> $DIR/malformed-attrs.rs:26:1
282+
|
283+
LL | #![omit_gdb_pretty_printer_section = 1]
284+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^
285+
| | |
286+
| | didn't expect any arguments here
287+
| help: must be of the form: `#[omit_gdb_pretty_printer_section]`
288+
286289
error[E0539]: malformed `export_name` attribute input
287290
--> $DIR/malformed-attrs.rs:32:1
288291
|

0 commit comments

Comments
 (0)