@@ -3,7 +3,9 @@ use std::str::FromStr;
33use rustc_abi:: { Align , ExternAbi } ;
44use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , DiffActivity , DiffMode } ;
55use rustc_ast:: { LitKind , MetaItem , MetaItemInner , attr} ;
6- use rustc_hir:: attrs:: { AttributeKind , InlineAttr , InstructionSetAttr , UsedBy } ;
6+ use rustc_hir:: attrs:: {
7+ AttributeKind , ExportVisibilityAttrValue , InlineAttr , InstructionSetAttr , UsedBy ,
8+ } ;
79use rustc_hir:: def:: DefKind ;
810use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId } ;
911use rustc_hir:: { self as hir, Attribute , LangItem , find_attr, lang_items} ;
@@ -160,6 +162,22 @@ fn process_builtin_attrs(
160162 codegen_fn_attrs. inline = * inline;
161163 interesting_spans. inline = Some ( * span) ;
162164 }
165+ AttributeKind :: ExportVisibility { visibility, span } => {
166+ if !tcx. features ( ) . export_visibility ( ) {
167+ feature_err (
168+ & tcx. sess ,
169+ sym:: export_visibility,
170+ * span,
171+ "`#[export_visibility = ...]` is currently unstable" ,
172+ )
173+ . emit ( ) ;
174+ }
175+ codegen_fn_attrs. export_visibility = Some ( match visibility {
176+ ExportVisibilityAttrValue :: TargetDefault => {
177+ tcx. sess . default_visibility ( ) . into ( )
178+ }
179+ } ) ;
180+ }
163181 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
164182 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
165183 AttributeKind :: LinkName { name, .. } => {
@@ -546,6 +564,17 @@ fn handle_lang_items(
546564 }
547565 err. emit ( ) ;
548566 }
567+
568+ if codegen_fn_attrs. export_visibility . is_some ( ) && !codegen_fn_attrs. contains_extern_indicator ( )
569+ {
570+ let export_visibility_span =
571+ find_attr ! ( attrs, AttributeKind :: ExportVisibility { span, ..} => * span)
572+ . unwrap_or_default ( ) ;
573+ tcx. dcx ( ) . span_err (
574+ export_visibility_span,
575+ "export visibility will be ignored without `export_name`, `no_mangle`, or similar attribute" ,
576+ ) ;
577+ }
549578}
550579
551580/// Generate the [`CodegenFnAttrs`] for an item (identified by the [`LocalDefId`]).
0 commit comments