rustc_metadata: remove huge error imports

This commit is contained in:
est31 2023-02-05 01:58:22 +01:00
parent 60e82aef64
commit 4442f13b03
3 changed files with 89 additions and 92 deletions

View File

@ -1,10 +1,6 @@
//! Validates all used crates and extern libraries and loads their metadata //! Validates all used crates and extern libraries and loads their metadata
use crate::errors::{ use crate::errors;
ConflictingAllocErrorHandler, ConflictingGlobalAlloc, CrateNotPanicRuntime,
GlobalAllocRequired, NoMultipleAllocErrorHandler, NoMultipleGlobalAlloc, NoPanicStrategy,
NoTransitiveNeedsDep, NotProfilerRuntime, ProfilerBuiltinsNeedsCore,
};
use crate::locator::{CrateError, CrateLocator, CratePaths}; use crate::locator::{CrateError, CrateLocator, CratePaths};
use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob}; use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob};
@ -768,10 +764,11 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
// Sanity check the loaded crate to ensure it is indeed a panic runtime // Sanity check the loaded crate to ensure it is indeed a panic runtime
// and the panic strategy is indeed what we thought it was. // and the panic strategy is indeed what we thought it was.
if !data.is_panic_runtime() { if !data.is_panic_runtime() {
self.sess.emit_err(CrateNotPanicRuntime { crate_name: name }); self.sess.emit_err(errors::CrateNotPanicRuntime { crate_name: name });
} }
if data.required_panic_strategy() != Some(desired_strategy) { if data.required_panic_strategy() != Some(desired_strategy) {
self.sess.emit_err(NoPanicStrategy { crate_name: name, strategy: desired_strategy }); self.sess
.emit_err(errors::NoPanicStrategy { crate_name: name, strategy: desired_strategy });
} }
self.cstore.injected_panic_runtime = Some(cnum); self.cstore.injected_panic_runtime = Some(cnum);
@ -791,7 +788,7 @@ fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
let name = Symbol::intern(&self.sess.opts.unstable_opts.profiler_runtime); let name = Symbol::intern(&self.sess.opts.unstable_opts.profiler_runtime);
if name == sym::profiler_builtins && self.sess.contains_name(&krate.attrs, sym::no_core) { if name == sym::profiler_builtins && self.sess.contains_name(&krate.attrs, sym::no_core) {
self.sess.emit_err(ProfilerBuiltinsNeedsCore); self.sess.emit_err(errors::ProfilerBuiltinsNeedsCore);
} }
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; }; let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
@ -799,21 +796,22 @@ fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
// Sanity check the loaded crate to ensure it is indeed a profiler runtime // Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime() { if !data.is_profiler_runtime() {
self.sess.emit_err(NotProfilerRuntime { crate_name: name }); self.sess.emit_err(errors::NotProfilerRuntime { crate_name: name });
} }
} }
fn inject_allocator_crate(&mut self, krate: &ast::Crate) { fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
self.cstore.has_global_allocator = match &*global_allocator_spans(&self.sess, krate) { self.cstore.has_global_allocator = match &*global_allocator_spans(&self.sess, krate) {
[span1, span2, ..] => { [span1, span2, ..] => {
self.sess.emit_err(NoMultipleGlobalAlloc { span2: *span2, span1: *span1 }); self.sess.emit_err(errors::NoMultipleGlobalAlloc { span2: *span2, span1: *span1 });
true true
} }
spans => !spans.is_empty(), spans => !spans.is_empty(),
}; };
self.cstore.has_alloc_error_handler = match &*alloc_error_handler_spans(&self.sess, krate) { self.cstore.has_alloc_error_handler = match &*alloc_error_handler_spans(&self.sess, krate) {
[span1, span2, ..] => { [span1, span2, ..] => {
self.sess.emit_err(NoMultipleAllocErrorHandler { span2: *span2, span1: *span1 }); self.sess
.emit_err(errors::NoMultipleAllocErrorHandler { span2: *span2, span1: *span1 });
true true
} }
spans => !spans.is_empty(), spans => !spans.is_empty(),
@ -849,7 +847,7 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
if data.has_global_allocator() { if data.has_global_allocator() {
match global_allocator { match global_allocator {
Some(other_crate) => { Some(other_crate) => {
self.sess.emit_err(ConflictingGlobalAlloc { self.sess.emit_err(errors::ConflictingGlobalAlloc {
crate_name: data.name(), crate_name: data.name(),
other_crate_name: other_crate, other_crate_name: other_crate,
}); });
@ -864,7 +862,7 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
if data.has_alloc_error_handler() { if data.has_alloc_error_handler() {
match alloc_error_handler { match alloc_error_handler {
Some(other_crate) => { Some(other_crate) => {
self.sess.emit_err(ConflictingAllocErrorHandler { self.sess.emit_err(errors::ConflictingAllocErrorHandler {
crate_name: data.name(), crate_name: data.name(),
other_crate_name: other_crate, other_crate_name: other_crate,
}); });
@ -884,7 +882,7 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
if !self.sess.contains_name(&krate.attrs, sym::default_lib_allocator) if !self.sess.contains_name(&krate.attrs, sym::default_lib_allocator)
&& !self.cstore.iter_crate_data().any(|(_, data)| data.has_default_lib_allocator()) && !self.cstore.iter_crate_data().any(|(_, data)| data.has_default_lib_allocator())
{ {
self.sess.emit_err(GlobalAllocRequired); self.sess.emit_err(errors::GlobalAllocRequired);
} }
self.cstore.allocator_kind = Some(AllocatorKind::Default); self.cstore.allocator_kind = Some(AllocatorKind::Default);
} }
@ -917,7 +915,7 @@ fn inject_dependency_if(
for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) { for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
let data = self.cstore.get_crate_data(dep); let data = self.cstore.get_crate_data(dep);
if needs_dep(&data) { if needs_dep(&data) {
self.sess.emit_err(NoTransitiveNeedsDep { self.sess.emit_err(errors::NoTransitiveNeedsDep {
crate_name: self.cstore.get_crate_data(krate).name(), crate_name: self.cstore.get_crate_data(krate).name(),
needs_crate_name: what, needs_crate_name: what,
deps_crate_name: data.name(), deps_crate_name: data.name(),

View File

@ -213,12 +213,7 @@
//! metadata::locator or metadata::creader for all the juicy details! //! metadata::locator or metadata::creader for all the juicy details!
use crate::creader::Library; use crate::creader::Library;
use crate::errors::{ use crate::errors;
CannotFindCrate, CrateLocationUnknownType, DlError, ExternLocationNotExist,
ExternLocationNotFile, FoundStaticlib, IncompatibleRustc, InvalidMetadataFiles,
LibFilenameForm, MultipleCandidates, NewerCrateVersion, NoCrateWithTriple, NoDylibPlugin,
NonAsciiName, StableCrateIdCollision, SymbolConflictsCurrent, SymbolConflictsOthers,
};
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -980,28 +975,28 @@ impl CrateError {
pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) { pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
match self { match self {
CrateError::NonAsciiName(crate_name) => { CrateError::NonAsciiName(crate_name) => {
sess.emit_err(NonAsciiName { span, crate_name }); sess.emit_err(errors::NonAsciiName { span, crate_name });
} }
CrateError::ExternLocationNotExist(crate_name, loc) => { CrateError::ExternLocationNotExist(crate_name, loc) => {
sess.emit_err(ExternLocationNotExist { span, crate_name, location: &loc }); sess.emit_err(errors::ExternLocationNotExist { span, crate_name, location: &loc });
} }
CrateError::ExternLocationNotFile(crate_name, loc) => { CrateError::ExternLocationNotFile(crate_name, loc) => {
sess.emit_err(ExternLocationNotFile { span, crate_name, location: &loc }); sess.emit_err(errors::ExternLocationNotFile { span, crate_name, location: &loc });
} }
CrateError::MultipleCandidates(crate_name, flavor, candidates) => { CrateError::MultipleCandidates(crate_name, flavor, candidates) => {
sess.emit_err(MultipleCandidates { span, crate_name, flavor, candidates }); sess.emit_err(errors::MultipleCandidates { span, crate_name, flavor, candidates });
} }
CrateError::SymbolConflictsCurrent(root_name) => { CrateError::SymbolConflictsCurrent(root_name) => {
sess.emit_err(SymbolConflictsCurrent { span, crate_name: root_name }); sess.emit_err(errors::SymbolConflictsCurrent { span, crate_name: root_name });
} }
CrateError::SymbolConflictsOthers(root_name) => { CrateError::SymbolConflictsOthers(root_name) => {
sess.emit_err(SymbolConflictsOthers { span, crate_name: root_name }); sess.emit_err(errors::SymbolConflictsOthers { span, crate_name: root_name });
} }
CrateError::StableCrateIdCollision(crate_name0, crate_name1) => { CrateError::StableCrateIdCollision(crate_name0, crate_name1) => {
sess.emit_err(StableCrateIdCollision { span, crate_name0, crate_name1 }); sess.emit_err(errors::StableCrateIdCollision { span, crate_name0, crate_name1 });
} }
CrateError::DlOpen(s) | CrateError::DlSym(s) => { CrateError::DlOpen(s) | CrateError::DlSym(s) => {
sess.emit_err(DlError { span, err: s }); sess.emit_err(errors::DlError { span, err: s });
} }
CrateError::LocatorCombined(locator) => { CrateError::LocatorCombined(locator) => {
let crate_name = locator.crate_name; let crate_name = locator.crate_name;
@ -1012,8 +1007,12 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
if !locator.crate_rejections.via_filename.is_empty() { if !locator.crate_rejections.via_filename.is_empty() {
let mismatches = locator.crate_rejections.via_filename.iter(); let mismatches = locator.crate_rejections.via_filename.iter();
for CrateMismatch { path, .. } in mismatches { for CrateMismatch { path, .. } in mismatches {
sess.emit_err(CrateLocationUnknownType { span, path: &path, crate_name }); sess.emit_err(errors::CrateLocationUnknownType {
sess.emit_err(LibFilenameForm { span,
path: &path,
crate_name,
});
sess.emit_err(errors::LibFilenameForm {
span, span,
dll_prefix: &locator.dll_prefix, dll_prefix: &locator.dll_prefix,
dll_suffix: &locator.dll_suffix, dll_suffix: &locator.dll_suffix,
@ -1039,7 +1038,7 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
)); ));
} }
} }
sess.emit_err(NewerCrateVersion { sess.emit_err(errors::NewerCrateVersion {
span, span,
crate_name: crate_name, crate_name: crate_name,
add_info, add_info,
@ -1055,7 +1054,7 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
path.display(), path.display(),
)); ));
} }
sess.emit_err(NoCrateWithTriple { sess.emit_err(errors::NoCrateWithTriple {
span, span,
crate_name, crate_name,
locator_triple: locator.triple.triple(), locator_triple: locator.triple.triple(),
@ -1071,7 +1070,12 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
path.display() path.display()
)); ));
} }
sess.emit_err(FoundStaticlib { span, crate_name, add_info, found_crates }); sess.emit_err(errors::FoundStaticlib {
span,
crate_name,
add_info,
found_crates,
});
} else if !locator.crate_rejections.via_version.is_empty() { } else if !locator.crate_rejections.via_version.is_empty() {
let mismatches = locator.crate_rejections.via_version.iter(); let mismatches = locator.crate_rejections.via_version.iter();
for CrateMismatch { path, got } in mismatches { for CrateMismatch { path, got } in mismatches {
@ -1082,7 +1086,7 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
path.display(), path.display(),
)); ));
} }
sess.emit_err(IncompatibleRustc { sess.emit_err(errors::IncompatibleRustc {
span, span,
crate_name, crate_name,
add_info, add_info,
@ -1094,14 +1098,14 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
for CrateMismatch { path: _, got } in locator.crate_rejections.via_invalid { for CrateMismatch { path: _, got } in locator.crate_rejections.via_invalid {
crate_rejections.push(got); crate_rejections.push(got);
} }
sess.emit_err(InvalidMetadataFiles { sess.emit_err(errors::InvalidMetadataFiles {
span, span,
crate_name, crate_name,
add_info, add_info,
crate_rejections, crate_rejections,
}); });
} else { } else {
sess.emit_err(CannotFindCrate { sess.emit_err(errors::CannotFindCrate {
span, span,
crate_name, crate_name,
add_info, add_info,
@ -1118,7 +1122,7 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
} }
} }
CrateError::NonDylibPlugin(crate_name) => { CrateError::NonDylibPlugin(crate_name) => {
sess.emit_err(NoDylibPlugin { span, crate_name }); sess.emit_err(errors::NoDylibPlugin { span, crate_name });
} }
} }
} }

View File

@ -13,17 +13,7 @@
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use crate::errors::{ use crate::errors;
AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, EmptyRenamingTarget,
FrameworkOnlyWindows, ImportNameTypeForm, ImportNameTypeRaw, ImportNameTypeX86,
IncompatibleWasmLink, InvalidLinkModifier, LibFrameworkApple, LinkCfgForm,
LinkCfgSinglePredicate, LinkFrameworkApple, LinkKindForm, LinkModifiersForm, LinkNameForm,
LinkOrdinalRawDylib, LinkRequiresName, MissingNativeLibrary, MultipleCfgs,
MultipleImportNameType, MultipleKindsInLink, MultipleLinkModifiers, MultipleModifiers,
MultipleNamesInLink, MultipleRenamings, MultipleWasmImport, NoLinkModOverride, RawDylibNoNul,
RenamingNoLink, UnexpectedLinkArg, UnknownImportNameType, UnknownLinkKind, UnknownLinkModifier,
UnsupportedAbi, UnsupportedAbiI686, WasmImportForm, WholeArchiveNeedsStatic,
};
use std::path::PathBuf; use std::path::PathBuf;
@ -52,7 +42,7 @@ pub fn find_native_static_library(
} }
} }
sess.emit_fatal(MissingNativeLibrary::new(name, verbatim)); sess.emit_fatal(errors::MissingNativeLibrary::new(name, verbatim));
} }
fn find_bundled_library( fn find_bundled_library(
@ -129,26 +119,26 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
match item.name_or_empty() { match item.name_or_empty() {
sym::name => { sym::name => {
if name.is_some() { if name.is_some() {
sess.emit_err(MultipleNamesInLink { span: item.span() }); sess.emit_err(errors::MultipleNamesInLink { span: item.span() });
continue; continue;
} }
let Some(link_name) = item.value_str() else { let Some(link_name) = item.value_str() else {
sess.emit_err(LinkNameForm { span: item.span() }); sess.emit_err(errors::LinkNameForm { span: item.span() });
continue; continue;
}; };
let span = item.name_value_literal_span().unwrap(); let span = item.name_value_literal_span().unwrap();
if link_name.is_empty() { if link_name.is_empty() {
sess.emit_err(EmptyLinkName { span }); sess.emit_err(errors::EmptyLinkName { span });
} }
name = Some((link_name, span)); name = Some((link_name, span));
} }
sym::kind => { sym::kind => {
if kind.is_some() { if kind.is_some() {
sess.emit_err(MultipleKindsInLink { span: item.span() }); sess.emit_err(errors::MultipleKindsInLink { span: item.span() });
continue; continue;
} }
let Some(link_kind) = item.value_str() else { let Some(link_kind) = item.value_str() else {
sess.emit_err(LinkKindForm { span: item.span() }); sess.emit_err(errors::LinkKindForm { span: item.span() });
continue; continue;
}; };
@ -158,13 +148,13 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
"dylib" => NativeLibKind::Dylib { as_needed: None }, "dylib" => NativeLibKind::Dylib { as_needed: None },
"framework" => { "framework" => {
if !sess.target.is_like_osx { if !sess.target.is_like_osx {
sess.emit_err(LinkFrameworkApple { span }); sess.emit_err(errors::LinkFrameworkApple { span });
} }
NativeLibKind::Framework { as_needed: None } NativeLibKind::Framework { as_needed: None }
} }
"raw-dylib" => { "raw-dylib" => {
if !sess.target.is_like_windows { if !sess.target.is_like_windows {
sess.emit_err(FrameworkOnlyWindows { span }); sess.emit_err(errors::FrameworkOnlyWindows { span });
} else if !features.raw_dylib && sess.target.arch == "x86" { } else if !features.raw_dylib && sess.target.arch == "x86" {
feature_err( feature_err(
&sess.parse_sess, &sess.parse_sess,
@ -177,7 +167,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
NativeLibKind::RawDylib NativeLibKind::RawDylib
} }
kind => { kind => {
sess.emit_err(UnknownLinkKind { span, kind }); sess.emit_err(errors::UnknownLinkKind { span, kind });
continue; continue;
} }
}; };
@ -185,26 +175,26 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
} }
sym::modifiers => { sym::modifiers => {
if modifiers.is_some() { if modifiers.is_some() {
sess.emit_err(MultipleLinkModifiers { span: item.span() }); sess.emit_err(errors::MultipleLinkModifiers { span: item.span() });
continue; continue;
} }
let Some(link_modifiers) = item.value_str() else { let Some(link_modifiers) = item.value_str() else {
sess.emit_err(LinkModifiersForm { span: item.span() }); sess.emit_err(errors::LinkModifiersForm { span: item.span() });
continue; continue;
}; };
modifiers = Some((link_modifiers, item.name_value_literal_span().unwrap())); modifiers = Some((link_modifiers, item.name_value_literal_span().unwrap()));
} }
sym::cfg => { sym::cfg => {
if cfg.is_some() { if cfg.is_some() {
sess.emit_err(MultipleCfgs { span: item.span() }); sess.emit_err(errors::MultipleCfgs { span: item.span() });
continue; continue;
} }
let Some(link_cfg) = item.meta_item_list() else { let Some(link_cfg) = item.meta_item_list() else {
sess.emit_err(LinkCfgForm { span: item.span() }); sess.emit_err(errors::LinkCfgForm { span: item.span() });
continue; continue;
}; };
let [NestedMetaItem::MetaItem(link_cfg)] = link_cfg else { let [NestedMetaItem::MetaItem(link_cfg)] = link_cfg else {
sess.emit_err(LinkCfgSinglePredicate { span: item.span() }); sess.emit_err(errors::LinkCfgSinglePredicate { span: item.span() });
continue; continue;
}; };
if !features.link_cfg { if !features.link_cfg {
@ -220,26 +210,26 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
} }
sym::wasm_import_module => { sym::wasm_import_module => {
if wasm_import_module.is_some() { if wasm_import_module.is_some() {
sess.emit_err(MultipleWasmImport { span: item.span() }); sess.emit_err(errors::MultipleWasmImport { span: item.span() });
continue; continue;
} }
let Some(link_wasm_import_module) = item.value_str() else { let Some(link_wasm_import_module) = item.value_str() else {
sess.emit_err(WasmImportForm { span: item.span() }); sess.emit_err(errors::WasmImportForm { span: item.span() });
continue; continue;
}; };
wasm_import_module = Some((link_wasm_import_module, item.span())); wasm_import_module = Some((link_wasm_import_module, item.span()));
} }
sym::import_name_type => { sym::import_name_type => {
if import_name_type.is_some() { if import_name_type.is_some() {
sess.emit_err(MultipleImportNameType { span: item.span() }); sess.emit_err(errors::MultipleImportNameType { span: item.span() });
continue; continue;
} }
let Some(link_import_name_type) = item.value_str() else { let Some(link_import_name_type) = item.value_str() else {
sess.emit_err(ImportNameTypeForm { span: item.span() }); sess.emit_err(errors::ImportNameTypeForm { span: item.span() });
continue; continue;
}; };
if self.tcx.sess.target.arch != "x86" { if self.tcx.sess.target.arch != "x86" {
sess.emit_err(ImportNameTypeX86 { span: item.span() }); sess.emit_err(errors::ImportNameTypeX86 { span: item.span() });
continue; continue;
} }
@ -248,7 +238,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
"noprefix" => PeImportNameType::NoPrefix, "noprefix" => PeImportNameType::NoPrefix,
"undecorated" => PeImportNameType::Undecorated, "undecorated" => PeImportNameType::Undecorated,
import_name_type => { import_name_type => {
sess.emit_err(UnknownImportNameType { sess.emit_err(errors::UnknownImportNameType {
span: item.span(), span: item.span(),
import_name_type, import_name_type,
}); });
@ -268,7 +258,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
import_name_type = Some((link_import_name_type, item.span())); import_name_type = Some((link_import_name_type, item.span()));
} }
_ => { _ => {
sess.emit_err(UnexpectedLinkArg { span: item.span() }); sess.emit_err(errors::UnexpectedLinkArg { span: item.span() });
} }
} }
} }
@ -280,7 +270,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
let (modifier, value) = match modifier.strip_prefix(&['+', '-']) { let (modifier, value) = match modifier.strip_prefix(&['+', '-']) {
Some(m) => (m, modifier.starts_with('+')), Some(m) => (m, modifier.starts_with('+')),
None => { None => {
sess.emit_err(InvalidLinkModifier { span }); sess.emit_err(errors::InvalidLinkModifier { span });
continue; continue;
} }
}; };
@ -298,7 +288,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
} }
let assign_modifier = |dst: &mut Option<bool>| { let assign_modifier = |dst: &mut Option<bool>| {
if dst.is_some() { if dst.is_some() {
sess.emit_err(MultipleModifiers { span, modifier }); sess.emit_err(errors::MultipleModifiers { span, modifier });
} else { } else {
*dst = Some(value); *dst = Some(value);
} }
@ -308,7 +298,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
assign_modifier(bundle) assign_modifier(bundle)
} }
("bundle", _) => { ("bundle", _) => {
sess.emit_err(BundleNeedsStatic { span }); sess.emit_err(errors::BundleNeedsStatic { span });
} }
("verbatim", _) => assign_modifier(&mut verbatim), ("verbatim", _) => assign_modifier(&mut verbatim),
@ -317,7 +307,7 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
assign_modifier(whole_archive) assign_modifier(whole_archive)
} }
("whole-archive", _) => { ("whole-archive", _) => {
sess.emit_err(WholeArchiveNeedsStatic { span }); sess.emit_err(errors::WholeArchiveNeedsStatic { span });
} }
("as-needed", Some(NativeLibKind::Dylib { as_needed })) ("as-needed", Some(NativeLibKind::Dylib { as_needed }))
@ -326,11 +316,11 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
assign_modifier(as_needed) assign_modifier(as_needed)
} }
("as-needed", _) => { ("as-needed", _) => {
sess.emit_err(AsNeededCompatibility { span }); sess.emit_err(errors::AsNeededCompatibility { span });
} }
_ => { _ => {
sess.emit_err(UnknownLinkModifier { span, modifier }); sess.emit_err(errors::UnknownLinkModifier { span, modifier });
} }
} }
} }
@ -338,23 +328,23 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
if let Some((_, span)) = wasm_import_module { if let Some((_, span)) = wasm_import_module {
if name.is_some() || kind.is_some() || modifiers.is_some() || cfg.is_some() { if name.is_some() || kind.is_some() || modifiers.is_some() || cfg.is_some() {
sess.emit_err(IncompatibleWasmLink { span }); sess.emit_err(errors::IncompatibleWasmLink { span });
} }
} else if name.is_none() { } else if name.is_none() {
sess.emit_err(LinkRequiresName { span: m.span }); sess.emit_err(errors::LinkRequiresName { span: m.span });
} }
// 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) {
sess.emit_err(ImportNameTypeRaw { span }); sess.emit_err(errors::ImportNameTypeRaw { span });
} }
} }
let dll_imports = match kind { let dll_imports = match kind {
Some(NativeLibKind::RawDylib) => { Some(NativeLibKind::RawDylib) => {
if let Some((name, span)) = name && name.as_str().contains('\0') { if let Some((name, span)) = name && name.as_str().contains('\0') {
sess.emit_err(RawDylibNoNul { span }); sess.emit_err(errors::RawDylibNoNul { span });
} }
foreign_mod_items foreign_mod_items
.iter() .iter()
@ -383,7 +373,9 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
.iter() .iter()
.find(|a| a.has_name(sym::link_ordinal)) .find(|a| a.has_name(sym::link_ordinal))
.unwrap(); .unwrap();
sess.emit_err(LinkOrdinalRawDylib { span: link_ordinal_attr.span }); sess.emit_err(errors::LinkOrdinalRawDylib {
span: link_ordinal_attr.span,
});
} }
} }
@ -414,7 +406,7 @@ fn process_command_line(&mut self) {
for lib in &self.tcx.sess.opts.libs { for lib in &self.tcx.sess.opts.libs {
if let NativeLibKind::Framework { .. } = lib.kind && !self.tcx.sess.target.is_like_osx { if let NativeLibKind::Framework { .. } = lib.kind && !self.tcx.sess.target.is_like_osx {
// Cannot check this when parsing options because the target is not yet available. // Cannot check this when parsing options because the target is not yet available.
self.tcx.sess.emit_err(LibFrameworkApple); self.tcx.sess.emit_err(errors::LibFrameworkApple);
} }
if let Some(ref new_name) = lib.new_name { if let Some(ref new_name) = lib.new_name {
let any_duplicate = self let any_duplicate = self
@ -423,11 +415,11 @@ fn process_command_line(&mut self) {
.filter_map(|lib| lib.name.as_ref()) .filter_map(|lib| lib.name.as_ref())
.any(|n| n.as_str() == lib.name); .any(|n| n.as_str() == lib.name);
if new_name.is_empty() { if new_name.is_empty() {
self.tcx.sess.emit_err(EmptyRenamingTarget { lib_name: &lib.name }); self.tcx.sess.emit_err(errors::EmptyRenamingTarget { lib_name: &lib.name });
} else if !any_duplicate { } else if !any_duplicate {
self.tcx.sess.emit_err(RenamingNoLink { lib_name: &lib.name }); self.tcx.sess.emit_err(errors::RenamingNoLink { lib_name: &lib.name });
} else if !renames.insert(&lib.name) { } else if !renames.insert(&lib.name) {
self.tcx.sess.emit_err(MultipleRenamings { lib_name: &lib.name }); self.tcx.sess.emit_err(errors::MultipleRenamings { lib_name: &lib.name });
} }
} }
} }
@ -453,12 +445,15 @@ fn process_command_line(&mut self) {
// explicit `:rename` in particular. // explicit `:rename` in particular.
if lib.has_modifiers() || passed_lib.has_modifiers() { if lib.has_modifiers() || passed_lib.has_modifiers() {
match lib.foreign_module { match lib.foreign_module {
Some(def_id) => self.tcx.sess.emit_err(NoLinkModOverride { Some(def_id) => {
self.tcx.sess.emit_err(errors::NoLinkModOverride {
span: Some(self.tcx.def_span(def_id)), span: Some(self.tcx.def_span(def_id)),
}), })
None => {
self.tcx.sess.emit_err(NoLinkModOverride { span: None })
} }
None => self
.tcx
.sess
.emit_err(errors::NoLinkModOverride { span: None }),
}; };
} }
if passed_lib.kind != NativeLibKind::Unspecified { if passed_lib.kind != NativeLibKind::Unspecified {
@ -542,14 +537,14 @@ fn build_dll_import(
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item)) DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
} }
_ => { _ => {
self.tcx.sess.emit_fatal(UnsupportedAbiI686 { span: item.span }); self.tcx.sess.emit_fatal(errors::UnsupportedAbiI686 { span: item.span });
} }
} }
} else { } else {
match abi { match abi {
Abi::C { .. } | Abi::Win64 { .. } | Abi::System { .. } => DllCallingConvention::C, Abi::C { .. } | Abi::Win64 { .. } | Abi::System { .. } => DllCallingConvention::C,
_ => { _ => {
self.tcx.sess.emit_fatal(UnsupportedAbi { span: item.span }); self.tcx.sess.emit_fatal(errors::UnsupportedAbi { span: item.span });
} }
} }
}; };