port creader.rs to SessionDiagnostics
This commit is contained in:
parent
f7e462a6c7
commit
32e1823b22
3 changed files with 102 additions and 34 deletions
|
@ -130,3 +130,31 @@ metadata_fail_seek_file =
|
|||
|
||||
metadata_fail_write_file =
|
||||
failed to write to the file: {$err}
|
||||
|
||||
metadata_crate_not_panic_runtime =
|
||||
the crate `{$crate_name}` is not a panic runtime
|
||||
|
||||
metadata_no_panic_strategy =
|
||||
the crate `{$crate_name}` does not have the panic strategy `{$strategy}`
|
||||
|
||||
metadata_profiler_builtins_needs_core =
|
||||
`profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]`
|
||||
|
||||
metadata_not_profiler_runtime =
|
||||
the crate `{$crate_name}` is not a profiler runtime
|
||||
|
||||
metadata_no_multiple_global_alloc =
|
||||
cannot define multiple global allocators
|
||||
.label = cannot define a new global allocator
|
||||
|
||||
metadata_prev_global_alloc =
|
||||
previous global allocator defined here
|
||||
|
||||
metadata_conflicting_global_alloc =
|
||||
the `#[global_allocator]` in {$other_crate_name} conflicts with global allocator in: {$crate_name}
|
||||
|
||||
metadata_global_alloc_required =
|
||||
no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
|
||||
|
||||
metadata_no_transitive_needs_dep =
|
||||
the crate `{$crate_name}` cannot depend on a crate that needs {$needs_crate_name}, but it depends on `{$deps_crate_name}`
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
//! Validates all used crates and extern libraries and loads their metadata
|
||||
|
||||
use crate::errors::{
|
||||
ConflictingGlobalAlloc, CrateNotPanicRuntime, GlobalAllocRequired, NoMultipleGlobalAlloc,
|
||||
NoPanicStrategy, NoTransitiveNeedsDep, NotProfilerRuntime, ProfilerBuiltinsNeedsCore,
|
||||
};
|
||||
use crate::locator::{CrateError, CrateLocator, CratePaths};
|
||||
use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob};
|
||||
|
||||
|
@ -746,15 +750,13 @@ impl<'a> CrateLoader<'a> {
|
|||
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
||||
// and the panic strategy is indeed what we thought it was.
|
||||
if !data.is_panic_runtime() {
|
||||
self.sess.err(&format!("the crate `{}` is not a panic runtime", name));
|
||||
self.sess.emit_err(CrateNotPanicRuntime { crate_name: name.to_string() });
|
||||
}
|
||||
if data.required_panic_strategy() != Some(desired_strategy) {
|
||||
self.sess.err(&format!(
|
||||
"the crate `{}` does not have the panic \
|
||||
strategy `{}`",
|
||||
name,
|
||||
desired_strategy.desc()
|
||||
));
|
||||
self.sess.emit_err(NoPanicStrategy {
|
||||
crate_name: name.to_string(),
|
||||
strategy: desired_strategy.desc().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
self.cstore.injected_panic_runtime = Some(cnum);
|
||||
|
@ -774,10 +776,7 @@ impl<'a> CrateLoader<'a> {
|
|||
|
||||
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) {
|
||||
self.sess.err(
|
||||
"`profiler_builtins` crate (required by compiler options) \
|
||||
is not compatible with crate attribute `#![no_core]`",
|
||||
);
|
||||
self.sess.emit_err(ProfilerBuiltinsNeedsCore);
|
||||
}
|
||||
|
||||
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
|
||||
|
@ -785,18 +784,14 @@ impl<'a> CrateLoader<'a> {
|
|||
|
||||
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
||||
if !data.is_profiler_runtime() {
|
||||
self.sess.err(&format!("the crate `{}` is not a profiler runtime", name));
|
||||
self.sess.emit_err(NotProfilerRuntime { crate_name: name.to_string() });
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
|
||||
self.cstore.has_global_allocator = match &*global_allocator_spans(&self.sess, krate) {
|
||||
[span1, span2, ..] => {
|
||||
self.sess
|
||||
.struct_span_err(*span2, "cannot define multiple global allocators")
|
||||
.span_label(*span2, "cannot define a new global allocator")
|
||||
.span_label(*span1, "previous global allocator defined here")
|
||||
.emit();
|
||||
self.sess.emit_err(NoMultipleGlobalAlloc { span2: *span2, span1: *span1 });
|
||||
true
|
||||
}
|
||||
spans => !spans.is_empty(),
|
||||
|
@ -832,11 +827,10 @@ impl<'a> CrateLoader<'a> {
|
|||
if data.has_global_allocator() {
|
||||
match global_allocator {
|
||||
Some(other_crate) => {
|
||||
self.sess.err(&format!(
|
||||
"the `#[global_allocator]` in {} conflicts with global allocator in: {}",
|
||||
other_crate,
|
||||
data.name()
|
||||
));
|
||||
self.sess.emit_err(ConflictingGlobalAlloc {
|
||||
crate_name: data.name().to_string(),
|
||||
other_crate_name: other_crate.to_string(),
|
||||
});
|
||||
}
|
||||
None => global_allocator = Some(data.name()),
|
||||
}
|
||||
|
@ -855,10 +849,7 @@ impl<'a> CrateLoader<'a> {
|
|||
if !self.sess.contains_name(&krate.attrs, sym::default_lib_allocator)
|
||||
&& !self.cstore.iter_crate_data().any(|(_, data)| data.has_default_lib_allocator())
|
||||
{
|
||||
self.sess.err(
|
||||
"no global memory allocator found but one is required; link to std or add \
|
||||
`#[global_allocator]` to a static item that implements the GlobalAlloc trait",
|
||||
);
|
||||
self.sess.emit_err(GlobalAllocRequired);
|
||||
}
|
||||
self.cstore.allocator_kind = Some(AllocatorKind::Default);
|
||||
}
|
||||
|
@ -882,14 +873,11 @@ impl<'a> CrateLoader<'a> {
|
|||
for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
|
||||
let data = self.cstore.get_crate_data(dep);
|
||||
if needs_dep(&data) {
|
||||
self.sess.err(&format!(
|
||||
"the crate `{}` cannot depend \
|
||||
on a crate that needs {}, but \
|
||||
it depends on `{}`",
|
||||
self.cstore.get_crate_data(krate).name(),
|
||||
what,
|
||||
data.name()
|
||||
));
|
||||
self.sess.emit_err(NoTransitiveNeedsDep {
|
||||
crate_name: self.cstore.get_crate_data(krate).name().to_string(),
|
||||
needs_crate_name: what.to_string(),
|
||||
deps_crate_name: data.name().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -300,3 +300,55 @@ pub struct FailSeekFile {
|
|||
pub struct FailWriteFile {
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::crate_not_panic_runtime)]
|
||||
pub struct CrateNotPanicRuntime {
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::no_panic_strategy)]
|
||||
pub struct NoPanicStrategy {
|
||||
pub crate_name: String,
|
||||
pub strategy: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::profiler_builtins_needs_core)]
|
||||
pub struct ProfilerBuiltinsNeedsCore;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::not_profiler_runtime)]
|
||||
pub struct NotProfilerRuntime {
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::no_multiple_global_alloc)]
|
||||
pub struct NoMultipleGlobalAlloc {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span2: Span,
|
||||
#[label(metadata::prev_global_alloc)]
|
||||
pub span1: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::conflicting_global_alloc)]
|
||||
pub struct ConflictingGlobalAlloc {
|
||||
pub crate_name: String,
|
||||
pub other_crate_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::global_alloc_required)]
|
||||
pub struct GlobalAllocRequired;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::no_transitive_needs_dep)]
|
||||
pub struct NoTransitiveNeedsDep {
|
||||
pub crate_name: String,
|
||||
pub needs_crate_name: String,
|
||||
pub deps_crate_name: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue