Skip to content

Commit ec49769

Browse files
committed
Port #[rustc_std_internal_symbol] to the new attribute system
1 parent ddbdb29 commit ec49769

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
@@ -324,6 +324,9 @@ pub enum AttributeKind {
324324
span: Span,
325325
},
326326

327+
/// Represents `#[rustc_std_internal_symbol]`.
328+
StdInternalSymbol(Span),
329+
327330
/// Represents `#[target_feature(enable = "...")]`
328331
TargetFeature(ThinVec<(Symbol, Span)>, Span),
329332

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl AttributeKind {
4848
RustcObjectLifetimeDefault => No,
4949
SkipDuringMethodDispatch { .. } => No,
5050
Stability { .. } => Yes,
51+
StdInternalSymbol(..) => No,
5152
TargetFeature(..) => No,
5253
TrackCaller(..) => Yes,
5354
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, PassByValueParser, PubTransparentParser};
2930
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
@@ -151,6 +152,7 @@ attribute_parsers!(
151152
Single<WithoutArgs<NoMangleParser>>,
152153
Single<WithoutArgs<PassByValueParser>>,
153154
Single<WithoutArgs<PubTransparentParser>>,
155+
Single<WithoutArgs<StdInternalSymbolParser>>,
154156
Single<WithoutArgs<TrackCallerParser>>,
155157
// tidy-alphabetical-end
156158
];

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
@@ -233,6 +233,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
233233
&Attribute::Parsed(AttributeKind::PassByValue(attr_span)) => {
234234
self.check_pass_by_value(attr_span, span, target)
235235
}
236+
&Attribute::Parsed(AttributeKind::StdInternalSymbol(attr_span)) => {
237+
self.check_rustc_std_internal_symbol(attr_span, span, target)
238+
}
236239
Attribute::Unparsed(attr_item) => {
237240
style = Some(attr_item.style);
238241
match attr.path().as_slice() {
@@ -259,9 +262,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
259262
),
260263
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
261264
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
262-
[sym::rustc_std_internal_symbol, ..] => {
263-
self.check_rustc_std_internal_symbol(attr, span, target)
264-
}
265265
[sym::rustc_no_implicit_autorefs, ..] => {
266266
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
267267
}
@@ -2218,13 +2218,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22182218
}
22192219
}
22202220

2221-
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) {
2221+
fn check_rustc_std_internal_symbol(&self, attr_span: Span, span: Span, target: Target) {
22222222
match target {
22232223
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {}
22242224
_ => {
2225-
self.tcx
2226-
.dcx()
2227-
.emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span(), span });
2225+
self.tcx.dcx().emit_err(errors::RustcStdInternalSymbol { attr_span, span });
22282226
}
22292227
}
22302228
}

0 commit comments

Comments
 (0)