port 5 new diagnostics that appeared in master

This commit is contained in:
Nathan Stocks 2022-08-27 17:50:11 -06:00
parent 0d65819d52
commit 30adfd6a17
3 changed files with 67 additions and 20 deletions
compiler
rustc_error_messages/locales/en-US
rustc_metadata/src

View File

@ -255,3 +255,18 @@ metadata_crate_location_unknown_type =
metadata_lib_filename_form = metadata_lib_filename_form =
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix} 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`

View File

@ -634,3 +634,39 @@ pub struct LibFilenameForm<'a> {
pub dll_prefix: &'a str, pub dll_prefix: &'a str,
pub dll_suffix: &'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,
}

View File

@ -13,13 +13,14 @@ use rustc_target::spec::abi::Abi;
use crate::errors::{ use crate::errors::{
AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, EmptyRenamingTarget, AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, EmptyRenamingTarget,
FrameworkOnlyWindows, IncompatibleWasmLink, InvalidLinkModifier, LibFrameworkApple, FrameworkOnlyWindows, ImportNameTypeForm, ImportNameTypeRaw, ImportNameTypeX86,
LinkCfgForm, LinkCfgSinglePredicate, LinkFrameworkApple, LinkKindForm, LinkModifiersForm, IncompatibleWasmLink, InvalidLinkModifier, LibFrameworkApple, LinkCfgForm,
LinkNameForm, LinkOrdinalRawDylib, LinkRequiresName, MultipleCfgs, MultipleKindsInLink, LinkCfgSinglePredicate, LinkFrameworkApple, LinkKindForm, LinkModifiersForm, LinkNameForm,
MultipleLinkModifiers, MultipleModifiers, MultipleNamesInLink, MultipleRenamings, LinkOrdinalRawDylib, LinkRequiresName, MultipleCfgs, MultipleImportNameType,
MultipleWasmImport, NoLinkModOverride, RawDylibNoNul, RenamingNoLink, UnexpectedLinkArg, MultipleKindsInLink, MultipleLinkModifiers, MultipleModifiers, MultipleNamesInLink,
UnknownLinkKind, UnknownLinkModifier, UnsupportedAbi, UnsupportedAbiI686, WasmImportForm, MultipleRenamings, MultipleWasmImport, NoLinkModOverride, RawDylibNoNul, RenamingNoLink,
WholeArchiveNeedsStatic, UnexpectedLinkArg, UnknownImportNameType, UnknownLinkKind, UnknownLinkModifier, UnsupportedAbi,
UnsupportedAbiI686, WasmImportForm, WholeArchiveNeedsStatic,
}; };
pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> { pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
@ -178,18 +179,15 @@ impl<'tcx> Collector<'tcx> {
} }
sym::import_name_type => { sym::import_name_type => {
if import_name_type.is_some() { if import_name_type.is_some() {
let msg = "multiple `import_name_type` arguments in a single `#[link]` attribute"; sess.emit_err(MultipleImportNameType { span: item.span() });
sess.span_err(item.span(), msg);
continue; continue;
} }
let Some(link_import_name_type) = item.value_str() else { 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.emit_err(ImportNameTypeForm { span: item.span() });
sess.span_err(item.span(), msg);
continue; continue;
}; };
if self.tcx.sess.target.arch != "x86" { if self.tcx.sess.target.arch != "x86" {
let msg = "import name type is only supported on x86"; sess.emit_err(ImportNameTypeX86 { span: item.span() });
sess.span_err(item.span(), msg);
continue; continue;
} }
@ -198,11 +196,10 @@ impl<'tcx> Collector<'tcx> {
"noprefix" => PeImportNameType::NoPrefix, "noprefix" => PeImportNameType::NoPrefix,
"undecorated" => PeImportNameType::Undecorated, "undecorated" => PeImportNameType::Undecorated,
import_name_type => { import_name_type => {
let msg = format!( sess.emit_err(UnknownImportNameType {
"unknown import name type `{import_name_type}`, expected one of: \ span: item.span(),
decorated, noprefix, undecorated" import_name_type,
); });
sess.span_err(item.span(), msg);
continue; continue;
} }
}; };
@ -301,8 +298,7 @@ impl<'tcx> Collector<'tcx> {
// Do this outside of the loop so that `import_name_type` can be specified before `kind`. // Do this outside of the loop so that `import_name_type` can be specified before `kind`.
if let Some((_, span)) = import_name_type { if let Some((_, span)) = import_name_type {
if kind != Some(NativeLibKind::RawDylib) { if kind != Some(NativeLibKind::RawDylib) {
let msg = "import name type can only be used with link kind `raw-dylib`"; sess.emit_err(ImportNameTypeRaw { span });
sess.span_err(span, msg);
} }
} }