@@ -13,13 +13,14 @@ use rustc_target::spec::abi::Abi;
1313
1414use crate :: errors:: {
1515 AsNeededCompatibility , BundleNeedsStatic , EmptyLinkName , EmptyRenamingTarget ,
16- FrameworkOnlyWindows , IncompatibleWasmLink , InvalidLinkModifier , LibFrameworkApple ,
17- LinkCfgForm , LinkCfgSinglePredicate , LinkFrameworkApple , LinkKindForm , LinkModifiersForm ,
18- LinkNameForm , LinkOrdinalRawDylib , LinkRequiresName , MultipleCfgs , MultipleKindsInLink ,
19- MultipleLinkModifiers , MultipleModifiers , MultipleNamesInLink , MultipleRenamings ,
20- MultipleWasmImport , NoLinkModOverride , RawDylibNoNul , RenamingNoLink , UnexpectedLinkArg ,
21- UnknownLinkKind , UnknownLinkModifier , UnsupportedAbi , UnsupportedAbiI686 , WasmImportForm ,
22- WholeArchiveNeedsStatic ,
16+ FrameworkOnlyWindows , ImportNameTypeForm , ImportNameTypeRaw , ImportNameTypeX86 ,
17+ IncompatibleWasmLink , InvalidLinkModifier , LibFrameworkApple , LinkCfgForm ,
18+ LinkCfgSinglePredicate , LinkFrameworkApple , LinkKindForm , LinkModifiersForm , LinkNameForm ,
19+ LinkOrdinalRawDylib , LinkRequiresName , MultipleCfgs , MultipleImportNameType ,
20+ MultipleKindsInLink , MultipleLinkModifiers , MultipleModifiers , MultipleNamesInLink ,
21+ MultipleRenamings , MultipleWasmImport , NoLinkModOverride , RawDylibNoNul , RenamingNoLink ,
22+ UnexpectedLinkArg , UnknownImportNameType , UnknownLinkKind , UnknownLinkModifier , UnsupportedAbi ,
23+ UnsupportedAbiI686 , WasmImportForm , WholeArchiveNeedsStatic ,
2324} ;
2425
2526pub ( crate ) fn collect ( tcx : TyCtxt < ' _ > ) -> Vec < NativeLib > {
@@ -178,18 +179,15 @@ impl<'tcx> Collector<'tcx> {
178179 }
179180 sym:: import_name_type => {
180181 if import_name_type. is_some ( ) {
181- let msg = "multiple `import_name_type` arguments in a single `#[link]` attribute" ;
182- sess. span_err ( item. span ( ) , msg) ;
182+ sess. emit_err ( MultipleImportNameType { span : item. span ( ) } ) ;
183183 continue ;
184184 }
185185 let Some ( link_import_name_type) = item. value_str ( ) else {
186- let msg = "import name type must be of the form `import_name_type = \" string\" `" ;
187- sess. span_err ( item. span ( ) , msg) ;
186+ sess. emit_err ( ImportNameTypeForm { span : item. span ( ) } ) ;
188187 continue ;
189188 } ;
190189 if self . tcx . sess . target . arch != "x86" {
191- let msg = "import name type is only supported on x86" ;
192- sess. span_err ( item. span ( ) , msg) ;
190+ sess. emit_err ( ImportNameTypeX86 { span : item. span ( ) } ) ;
193191 continue ;
194192 }
195193
@@ -198,11 +196,10 @@ impl<'tcx> Collector<'tcx> {
198196 "noprefix" => PeImportNameType :: NoPrefix ,
199197 "undecorated" => PeImportNameType :: Undecorated ,
200198 import_name_type => {
201- let msg = format ! (
202- "unknown import name type `{import_name_type}`, expected one of: \
203- decorated, noprefix, undecorated"
204- ) ;
205- sess. span_err ( item. span ( ) , msg) ;
199+ sess. emit_err ( UnknownImportNameType {
200+ span : item. span ( ) ,
201+ import_name_type,
202+ } ) ;
206203 continue ;
207204 }
208205 } ;
@@ -301,8 +298,7 @@ impl<'tcx> Collector<'tcx> {
301298 // Do this outside of the loop so that `import_name_type` can be specified before `kind`.
302299 if let Some ( ( _, span) ) = import_name_type {
303300 if kind != Some ( NativeLibKind :: RawDylib ) {
304- let msg = "import name type can only be used with link kind `raw-dylib`" ;
305- sess. span_err ( span, msg) ;
301+ sess. emit_err ( ImportNameTypeRaw { span } ) ;
306302 }
307303 }
308304
0 commit comments