set up rustc_metadata for SessionDiagnostics, port dependency_format.rs
This commit is contained in:
parent
4fd4de7ea3
commit
54645e880f
5 changed files with 103 additions and 53 deletions
21
compiler/rustc_error_messages/locales/en-US/metadata.ftl
Normal file
21
compiler/rustc_error_messages/locales/en-US/metadata.ftl
Normal file
|
@ -0,0 +1,21 @@
|
|||
metadata_rlib_required =
|
||||
crate `{$crate_name}` required to be available in rlib format, but was not found in this form
|
||||
|
||||
metadata_lib_required =
|
||||
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
|
||||
|
||||
metadata_crate_dep_multiple =
|
||||
cannot satisfy dependencies so `{$crate_name}` only shows up once
|
||||
.help = having upstream crates all available in one format will likely make this go away
|
||||
|
||||
metadata_two_panic_runtimes =
|
||||
cannot link together two panic runtimes: {$prev_name} and {$cur_name}
|
||||
|
||||
metadata_bad_panic_strategy =
|
||||
the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}`
|
||||
|
||||
metadata_required_panic_strategy =
|
||||
the crate `{$crate_name}` requires panic strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`
|
||||
|
||||
metadata_incompatible_panic_in_drop_strategy =
|
||||
the crate `{$crate_name}` is compiled with the panic-in-drop strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`
|
|
@ -46,6 +46,7 @@ fluent_messages! {
|
|||
infer => "../locales/en-US/infer.ftl",
|
||||
lint => "../locales/en-US/lint.ftl",
|
||||
monomorphize => "../locales/en-US/monomorphize.ftl",
|
||||
metadata => "../locales/en-US/metadata.ftl",
|
||||
parser => "../locales/en-US/parser.ftl",
|
||||
passes => "../locales/en-US/passes.ftl",
|
||||
plugin_impl => "../locales/en-US/plugin_impl.ftl",
|
||||
|
|
|
@ -52,6 +52,10 @@
|
|||
//! than finding a number of solutions (there are normally quite a few).
|
||||
|
||||
use crate::creader::CStore;
|
||||
use crate::errors::{
|
||||
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired,
|
||||
RequiredPanicStrategy, RlibRequired, TwoPanicRuntimes,
|
||||
};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::CrateNum;
|
||||
|
@ -136,11 +140,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
|
|||
if src.rlib.is_some() {
|
||||
continue;
|
||||
}
|
||||
sess.err(&format!(
|
||||
"crate `{}` required to be available in rlib format, \
|
||||
but was not found in this form",
|
||||
tcx.crate_name(cnum)
|
||||
));
|
||||
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum).to_string() });
|
||||
}
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -224,12 +224,10 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
|
|||
Linkage::Static => "rlib",
|
||||
_ => "dylib",
|
||||
};
|
||||
sess.err(&format!(
|
||||
"crate `{}` required to be available in {} format, \
|
||||
but was not found in this form",
|
||||
tcx.crate_name(cnum),
|
||||
kind
|
||||
));
|
||||
sess.emit_err(LibRequired {
|
||||
crate_name: tcx.crate_name(cnum).to_string(),
|
||||
kind: kind.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,16 +252,7 @@ fn add_library(
|
|||
// can be refined over time.
|
||||
if link2 != link || link == RequireStatic {
|
||||
tcx.sess
|
||||
.struct_err(&format!(
|
||||
"cannot satisfy dependencies so `{}` only \
|
||||
shows up once",
|
||||
tcx.crate_name(cnum)
|
||||
))
|
||||
.help(
|
||||
"having upstream crates all available in one format \
|
||||
will likely make this go away",
|
||||
)
|
||||
.emit();
|
||||
.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum).to_string() });
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
@ -358,13 +347,9 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
|
|||
|
||||
if tcx.is_panic_runtime(cnum) {
|
||||
if let Some((prev, _)) = panic_runtime {
|
||||
let prev_name = tcx.crate_name(prev);
|
||||
let cur_name = tcx.crate_name(cnum);
|
||||
sess.err(&format!(
|
||||
"cannot link together two \
|
||||
panic runtimes: {} and {}",
|
||||
prev_name, cur_name
|
||||
));
|
||||
let prev_name = tcx.crate_name(prev).to_string();
|
||||
let cur_name = tcx.crate_name(cnum).to_string();
|
||||
sess.emit_err(TwoPanicRuntimes { prev_name, cur_name });
|
||||
}
|
||||
panic_runtime = Some((
|
||||
cnum,
|
||||
|
@ -384,13 +369,10 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
|
|||
// First up, validate that our selected panic runtime is indeed exactly
|
||||
// our same strategy.
|
||||
if found_strategy != desired_strategy {
|
||||
sess.err(&format!(
|
||||
"the linked panic runtime `{}` is \
|
||||
not compiled with this crate's \
|
||||
panic strategy `{}`",
|
||||
tcx.crate_name(runtime_cnum),
|
||||
desired_strategy.desc()
|
||||
));
|
||||
sess.emit_err(BadPanicStrategy {
|
||||
runtime: tcx.crate_name(runtime_cnum).to_string(),
|
||||
strategy: desired_strategy.desc().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// Next up, verify that all other crates are compatible with this panic
|
||||
|
@ -407,28 +389,19 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
|
|||
}
|
||||
|
||||
if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy {
|
||||
sess.err(&format!(
|
||||
"the crate `{}` requires \
|
||||
panic strategy `{}` which is \
|
||||
incompatible with this crate's \
|
||||
strategy of `{}`",
|
||||
tcx.crate_name(cnum),
|
||||
found_strategy.desc(),
|
||||
desired_strategy.desc()
|
||||
));
|
||||
sess.emit_err(RequiredPanicStrategy {
|
||||
crate_name: tcx.crate_name(cnum).to_string(),
|
||||
found_strategy: found_strategy.desc().to_string(),
|
||||
desired_strategy: desired_strategy.desc().to_string() });
|
||||
}
|
||||
|
||||
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
|
||||
if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy {
|
||||
sess.err(&format!(
|
||||
"the crate `{}` is compiled with the \
|
||||
panic-in-drop strategy `{}` which is \
|
||||
incompatible with this crate's \
|
||||
strategy of `{}`",
|
||||
tcx.crate_name(cnum),
|
||||
found_drop_strategy.desc(),
|
||||
tcx.sess.opts.unstable_opts.panic_in_drop.desc()
|
||||
));
|
||||
sess.emit_err(IncompatiblePanicInDropStrategy {
|
||||
crate_name: tcx.crate_name(cnum).to_string(),
|
||||
found_strategy: found_drop_strategy.desc().to_string(),
|
||||
desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop.desc().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
52
compiler/rustc_metadata/src/errors.rs
Normal file
52
compiler/rustc_metadata/src/errors.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
// use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::rlib_required)]
|
||||
pub struct RlibRequired {
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::lib_required)]
|
||||
pub struct LibRequired {
|
||||
pub crate_name: String,
|
||||
pub kind: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::crate_dep_multiple)]
|
||||
#[help]
|
||||
pub struct CrateDepMultiple {
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::two_panic_runtimes)]
|
||||
pub struct TwoPanicRuntimes {
|
||||
pub prev_name: String,
|
||||
pub cur_name: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::bad_panic_strategy)]
|
||||
pub struct BadPanicStrategy {
|
||||
pub runtime: String,
|
||||
pub strategy: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::required_panic_strategy)]
|
||||
pub struct RequiredPanicStrategy {
|
||||
pub crate_name: String,
|
||||
pub found_strategy: String,
|
||||
pub desired_strategy: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(metadata::incompatible_panic_in_drop_strategy)]
|
||||
pub struct IncompatiblePanicInDropStrategy {
|
||||
pub crate_name: String,
|
||||
pub found_strategy: String,
|
||||
pub desired_strategy: String,
|
||||
}
|
|
@ -16,6 +16,8 @@
|
|||
#![feature(never_type)]
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
@ -34,6 +36,7 @@ mod native_libs;
|
|||
mod rmeta;
|
||||
|
||||
pub mod creader;
|
||||
pub mod errors;
|
||||
pub mod fs;
|
||||
pub mod locator;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue