Skip to content

Commit 818040c

Browse files
committed
Port #[rustc_std_internal_symbol] to the new attribute system
1 parent 467d2da commit 818040c

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ pub enum AttributeKind {
318318
span: Span,
319319
},
320320

321+
/// Represents `#[rustc_std_internal_symbol]`.
322+
StdInternalSymbol(Span),
323+
321324
/// Represents `#[target_feature(enable = "...")]`
322325
TargetFeature(ThinVec<(Symbol, Span)>, Span),
323326

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl AttributeKind {
4646
RustcObjectLifetimeDefault => No,
4747
SkipDuringMethodDispatch { .. } => No,
4848
Stability { .. } => Yes,
49+
StdInternalSymbol(..) => No,
4950
TargetFeature(..) => No,
5051
TrackCaller(..) => Yes,
5152
Used { .. } => No,

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for FfiPureParser {
8080
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
8181
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiPure;
8282
}
83+
84+
pub(crate) struct StdInternalSymbolParser;
85+
impl<S: Stage> NoArgsAttributeParser<S> for StdInternalSymbolParser {
86+
const PATH: &[Symbol] = &[sym::rustc_std_internal_symbol];
87+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
88+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::StdInternalSymbol;
89+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2525
use crate::attributes::link_attrs::{
2626
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkSectionParser,
27+
StdInternalSymbolParser,
2728
};
2829
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2930
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
@@ -148,6 +149,7 @@ attribute_parsers!(
148149
Single<WithoutArgs<MayDangleParser>>,
149150
Single<WithoutArgs<NoMangleParser>>,
150151
Single<WithoutArgs<PubTransparentParser>>,
152+
Single<WithoutArgs<StdInternalSymbolParser>>,
151153
Single<WithoutArgs<TrackCallerParser>>,
152154
// tidy-alphabetical-end
153155
];

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
215215
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
216216
}
217217
AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
218+
AttributeKind::StdInternalSymbol(_) => {
219+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
220+
}
218221
_ => {}
219222
}
220223
}
@@ -231,9 +234,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
231234
sym::rustc_allocator_zeroed => {
232235
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
233236
}
234-
sym::rustc_std_internal_symbol => {
235-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
236-
}
237237
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
238238
sym::linkage => {
239239
if let Some(val) = attr.value_str() {

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
222222
Attribute::Parsed(AttributeKind::Used { span: attr_span, .. }) => {
223223
self.check_used(*attr_span, target, span);
224224
}
225+
&Attribute::Parsed(AttributeKind::StdInternalSymbol(attr_span)) => {
226+
self.check_rustc_std_internal_symbol(attr_span, span, target)
227+
}
225228
Attribute::Unparsed(attr_item) => {
226229
style = Some(attr_item.style);
227230
match attr.path().as_slice() {
@@ -248,9 +251,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
248251
),
249252
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
250253
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
251-
[sym::rustc_std_internal_symbol, ..] => {
252-
self.check_rustc_std_internal_symbol(attr, span, target)
253-
}
254254
[sym::rustc_no_implicit_autorefs, ..] => {
255255
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
256256
}
@@ -2189,13 +2189,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
21892189
}
21902190
}
21912191

2192-
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) {
2192+
fn check_rustc_std_internal_symbol(&self, attr_span: Span, span: Span, target: Target) {
21932193
match target {
21942194
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {}
21952195
_ => {
2196-
self.tcx
2197-
.dcx()
2198-
.emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span(), span });
2196+
self.tcx.dcx().emit_err(errors::RustcStdInternalSymbol { attr_span, span });
21992197
}
22002198
}
22012199
}

0 commit comments

Comments
 (0)