Skip to content

Commit 30adfd6

Browse files
committed
port 5 new diagnostics that appeared in master
1 parent 0d65819 commit 30adfd6

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

compiler/rustc_error_messages/locales/en-US/metadata.ftl

+15
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,18 @@ metadata_crate_location_unknown_type =
255255
256256
metadata_lib_filename_form =
257257
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
258+
259+
metadata_multiple_import_name_type =
260+
multiple `import_name_type` arguments in a single `#[link]` attribute
261+
262+
metadata_import_name_type_form =
263+
import name type must be of the form `import_name_type = "string"`
264+
265+
metadata_import_name_type_x86 =
266+
import name type is only supported on x86
267+
268+
metadata_unknown_import_name_type =
269+
unknown import name type `{$import_name_type}`, expected one of: decorated, noprefix, undecorated
270+
271+
metadata_import_name_type_raw =
272+
import name type can only be used with link kind `raw-dylib`

compiler/rustc_metadata/src/errors.rs

+36
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,39 @@ pub struct LibFilenameForm<'a> {
634634
pub dll_prefix: &'a str,
635635
pub dll_suffix: &'a str,
636636
}
637+
638+
#[derive(SessionDiagnostic)]
639+
#[diag(metadata::multiple_import_name_type)]
640+
pub struct MultipleImportNameType {
641+
#[primary_span]
642+
pub span: Span,
643+
}
644+
645+
#[derive(SessionDiagnostic)]
646+
#[diag(metadata::import_name_type_form)]
647+
pub struct ImportNameTypeForm {
648+
#[primary_span]
649+
pub span: Span,
650+
}
651+
652+
#[derive(SessionDiagnostic)]
653+
#[diag(metadata::import_name_type_x86)]
654+
pub struct ImportNameTypeX86 {
655+
#[primary_span]
656+
pub span: Span,
657+
}
658+
659+
#[derive(SessionDiagnostic)]
660+
#[diag(metadata::unknown_import_name_type)]
661+
pub struct UnknownImportNameType<'a> {
662+
#[primary_span]
663+
pub span: Span,
664+
pub import_name_type: &'a str,
665+
}
666+
667+
#[derive(SessionDiagnostic)]
668+
#[diag(metadata::import_name_type_raw)]
669+
pub struct ImportNameTypeRaw {
670+
#[primary_span]
671+
pub span: Span,
672+
}

compiler/rustc_metadata/src/native_libs.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ use rustc_target::spec::abi::Abi;
1313

1414
use 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

2526
pub(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

Comments
 (0)