Skip to content

Commit 4f0b0b0

Browse files
committed
Port #[rustc_std_internal_symbol] to the new attribute system
1 parent 5d7771e commit 4f0b0b0

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-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
@@ -335,6 +335,9 @@ pub enum AttributeKind {
335335
span: Span,
336336
},
337337

338+
/// Represents `#[rustc_std_internal_symbol]`.
339+
StdInternalSymbol(Span),
340+
338341
/// Represents `#[target_feature(enable = "...")]`
339342
TargetFeature(ThinVec<(Symbol, Span)>, Span),
340343

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl AttributeKind {
5151
RustcObjectLifetimeDefault => No,
5252
SkipDuringMethodDispatch { .. } => No,
5353
Stability { .. } => Yes,
54+
StdInternalSymbol(..) => No,
5455
TargetFeature(..) => No,
5556
TrackCaller(..) => Yes,
5657
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};
@@ -157,6 +158,7 @@ attribute_parsers!(
157158
Single<WithoutArgs<NonExhaustiveParser>>,
158159
Single<WithoutArgs<PassByValueParser>>,
159160
Single<WithoutArgs<PubTransparentParser>>,
161+
Single<WithoutArgs<StdInternalSymbolParser>>,
160162
Single<WithoutArgs<TrackCallerParser>>,
161163
// tidy-alphabetical-end
162164
];

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
207207
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
208208
}
209209
AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
210+
AttributeKind::StdInternalSymbol(_) => {
211+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
212+
}
210213
_ => {}
211214
}
212215
}
@@ -223,9 +226,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
223226
sym::rustc_allocator_zeroed => {
224227
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
225228
}
226-
sym::rustc_std_internal_symbol => {
227-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
228-
}
229229
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
230230
sym::linkage => {
231231
if let Some(val) = attr.value_str() {

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub fn check_builtin_meta_item(
274274
| sym::export_stable
275275
| sym::ffi_const
276276
| sym::ffi_pure
277+
| sym::rustc_std_internal_symbol
277278
| sym::may_dangle
278279
| sym::rustc_as_ptr
279280
| sym::rustc_pub_transparent

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
242242
&Attribute::Parsed(AttributeKind::PassByValue(attr_span)) => {
243243
self.check_pass_by_value(attr_span, span, target)
244244
}
245+
&Attribute::Parsed(AttributeKind::StdInternalSymbol(attr_span)) => {
246+
self.check_rustc_std_internal_symbol(attr_span, span, target)
247+
}
245248
Attribute::Unparsed(attr_item) => {
246249
style = Some(attr_item.style);
247250
match attr.path().as_slice() {
@@ -267,9 +270,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
267270
),
268271
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
269272
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
270-
[sym::rustc_std_internal_symbol, ..] => {
271-
self.check_rustc_std_internal_symbol(attr, span, target)
272-
}
273273
[sym::rustc_no_implicit_autorefs, ..] => {
274274
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
275275
}
@@ -2220,13 +2220,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22202220
}
22212221
}
22222222

2223-
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) {
2223+
fn check_rustc_std_internal_symbol(&self, attr_span: Span, span: Span, target: Target) {
22242224
match target {
22252225
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {}
22262226
_ => {
2227-
self.tcx
2228-
.dcx()
2229-
.emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span(), span });
2227+
self.tcx.dcx().emit_err(errors::RustcStdInternalSymbol { attr_span, span });
22302228
}
22312229
}
22322230
}

0 commit comments

Comments
 (0)