Skip to content

Commit

Permalink
port 5 new diagnostics that appeared in master
Browse files Browse the repository at this point in the history
  • Loading branch information
CleanCut committed Aug 31, 2022
1 parent 0d65819 commit 30adfd6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
15 changes: 15 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/metadata.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,18 @@ metadata_crate_location_unknown_type =
metadata_lib_filename_form =
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
metadata_multiple_import_name_type =
multiple `import_name_type` arguments in a single `#[link]` attribute
metadata_import_name_type_form =
import name type must be of the form `import_name_type = "string"`
metadata_import_name_type_x86 =
import name type is only supported on x86
metadata_unknown_import_name_type =
unknown import name type `{$import_name_type}`, expected one of: decorated, noprefix, undecorated
metadata_import_name_type_raw =
import name type can only be used with link kind `raw-dylib`
36 changes: 36 additions & 0 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,39 @@ pub struct LibFilenameForm<'a> {
pub dll_prefix: &'a str,
pub dll_suffix: &'a str,
}

#[derive(SessionDiagnostic)]
#[diag(metadata::multiple_import_name_type)]
pub struct MultipleImportNameType {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[diag(metadata::import_name_type_form)]
pub struct ImportNameTypeForm {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[diag(metadata::import_name_type_x86)]
pub struct ImportNameTypeX86 {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[diag(metadata::unknown_import_name_type)]
pub struct UnknownImportNameType<'a> {
#[primary_span]
pub span: Span,
pub import_name_type: &'a str,
}

#[derive(SessionDiagnostic)]
#[diag(metadata::import_name_type_raw)]
pub struct ImportNameTypeRaw {
#[primary_span]
pub span: Span,
}
36 changes: 16 additions & 20 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ use rustc_target::spec::abi::Abi;

use crate::errors::{
AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, EmptyRenamingTarget,
FrameworkOnlyWindows, IncompatibleWasmLink, InvalidLinkModifier, LibFrameworkApple,
LinkCfgForm, LinkCfgSinglePredicate, LinkFrameworkApple, LinkKindForm, LinkModifiersForm,
LinkNameForm, LinkOrdinalRawDylib, LinkRequiresName, MultipleCfgs, MultipleKindsInLink,
MultipleLinkModifiers, MultipleModifiers, MultipleNamesInLink, MultipleRenamings,
MultipleWasmImport, NoLinkModOverride, RawDylibNoNul, RenamingNoLink, UnexpectedLinkArg,
UnknownLinkKind, UnknownLinkModifier, UnsupportedAbi, UnsupportedAbiI686, WasmImportForm,
WholeArchiveNeedsStatic,
FrameworkOnlyWindows, ImportNameTypeForm, ImportNameTypeRaw, ImportNameTypeX86,
IncompatibleWasmLink, InvalidLinkModifier, LibFrameworkApple, LinkCfgForm,
LinkCfgSinglePredicate, LinkFrameworkApple, LinkKindForm, LinkModifiersForm, LinkNameForm,
LinkOrdinalRawDylib, LinkRequiresName, MultipleCfgs, MultipleImportNameType,
MultipleKindsInLink, MultipleLinkModifiers, MultipleModifiers, MultipleNamesInLink,
MultipleRenamings, MultipleWasmImport, NoLinkModOverride, RawDylibNoNul, RenamingNoLink,
UnexpectedLinkArg, UnknownImportNameType, UnknownLinkKind, UnknownLinkModifier, UnsupportedAbi,
UnsupportedAbiI686, WasmImportForm, WholeArchiveNeedsStatic,
};

pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
Expand Down Expand Up @@ -178,18 +179,15 @@ impl<'tcx> Collector<'tcx> {
}
sym::import_name_type => {
if import_name_type.is_some() {
let msg = "multiple `import_name_type` arguments in a single `#[link]` attribute";
sess.span_err(item.span(), msg);
sess.emit_err(MultipleImportNameType { span: item.span() });
continue;
}
let Some(link_import_name_type) = item.value_str() else {
let msg = "import name type must be of the form `import_name_type = \"string\"`";
sess.span_err(item.span(), msg);
sess.emit_err(ImportNameTypeForm { span: item.span() });
continue;
};
if self.tcx.sess.target.arch != "x86" {
let msg = "import name type is only supported on x86";
sess.span_err(item.span(), msg);
sess.emit_err(ImportNameTypeX86 { span: item.span() });
continue;
}

Expand All @@ -198,11 +196,10 @@ impl<'tcx> Collector<'tcx> {
"noprefix" => PeImportNameType::NoPrefix,
"undecorated" => PeImportNameType::Undecorated,
import_name_type => {
let msg = format!(
"unknown import name type `{import_name_type}`, expected one of: \
decorated, noprefix, undecorated"
);
sess.span_err(item.span(), msg);
sess.emit_err(UnknownImportNameType {
span: item.span(),
import_name_type,
});
continue;
}
};
Expand Down Expand Up @@ -301,8 +298,7 @@ impl<'tcx> Collector<'tcx> {
// Do this outside of the loop so that `import_name_type` can be specified before `kind`.
if let Some((_, span)) = import_name_type {
if kind != Some(NativeLibKind::RawDylib) {
let msg = "import name type can only be used with link kind `raw-dylib`";
sess.span_err(span, msg);
sess.emit_err(ImportNameTypeRaw { span });
}
}

Expand Down

0 comments on commit 30adfd6

Please sign in to comment.