@@ -13,13 +13,14 @@ use rustc_target::spec::abi::Abi;
13
13
14
14
use crate :: errors:: {
15
15
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 ,
23
24
} ;
24
25
25
26
pub ( crate ) fn collect ( tcx : TyCtxt < ' _ > ) -> Vec < NativeLib > {
@@ -178,18 +179,15 @@ impl<'tcx> Collector<'tcx> {
178
179
}
179
180
sym:: import_name_type => {
180
181
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 ( ) } ) ;
183
183
continue ;
184
184
}
185
185
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 ( ) } ) ;
188
187
continue ;
189
188
} ;
190
189
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 ( ) } ) ;
193
191
continue ;
194
192
}
195
193
@@ -198,11 +196,10 @@ impl<'tcx> Collector<'tcx> {
198
196
"noprefix" => PeImportNameType :: NoPrefix ,
199
197
"undecorated" => PeImportNameType :: Undecorated ,
200
198
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
+ } ) ;
206
203
continue ;
207
204
}
208
205
} ;
@@ -301,8 +298,7 @@ impl<'tcx> Collector<'tcx> {
301
298
// Do this outside of the loop so that `import_name_type` can be specified before `kind`.
302
299
if let Some ( ( _, span) ) = import_name_type {
303
300
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 } ) ;
306
302
}
307
303
}
308
304
0 commit comments