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",
|
infer => "../locales/en-US/infer.ftl",
|
||||||
lint => "../locales/en-US/lint.ftl",
|
lint => "../locales/en-US/lint.ftl",
|
||||||
monomorphize => "../locales/en-US/monomorphize.ftl",
|
monomorphize => "../locales/en-US/monomorphize.ftl",
|
||||||
|
metadata => "../locales/en-US/metadata.ftl",
|
||||||
parser => "../locales/en-US/parser.ftl",
|
parser => "../locales/en-US/parser.ftl",
|
||||||
passes => "../locales/en-US/passes.ftl",
|
passes => "../locales/en-US/passes.ftl",
|
||||||
plugin_impl => "../locales/en-US/plugin_impl.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).
|
//! than finding a number of solutions (there are normally quite a few).
|
||||||
|
|
||||||
use crate::creader::CStore;
|
use crate::creader::CStore;
|
||||||
|
use crate::errors::{
|
||||||
|
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired,
|
||||||
|
RequiredPanicStrategy, RlibRequired, TwoPanicRuntimes,
|
||||||
|
};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::def_id::CrateNum;
|
use rustc_hir::def_id::CrateNum;
|
||||||
|
@ -136,11 +140,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
|
||||||
if src.rlib.is_some() {
|
if src.rlib.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sess.err(&format!(
|
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum).to_string() });
|
||||||
"crate `{}` required to be available in rlib format, \
|
|
||||||
but was not found in this form",
|
|
||||||
tcx.crate_name(cnum)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -224,12 +224,10 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
|
||||||
Linkage::Static => "rlib",
|
Linkage::Static => "rlib",
|
||||||
_ => "dylib",
|
_ => "dylib",
|
||||||
};
|
};
|
||||||
sess.err(&format!(
|
sess.emit_err(LibRequired {
|
||||||
"crate `{}` required to be available in {} format, \
|
crate_name: tcx.crate_name(cnum).to_string(),
|
||||||
but was not found in this form",
|
kind: kind.to_string(),
|
||||||
tcx.crate_name(cnum),
|
});
|
||||||
kind
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,16 +252,7 @@ fn add_library(
|
||||||
// can be refined over time.
|
// can be refined over time.
|
||||||
if link2 != link || link == RequireStatic {
|
if link2 != link || link == RequireStatic {
|
||||||
tcx.sess
|
tcx.sess
|
||||||
.struct_err(&format!(
|
.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum).to_string() });
|
||||||
"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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -358,13 +347,9 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
|
||||||
|
|
||||||
if tcx.is_panic_runtime(cnum) {
|
if tcx.is_panic_runtime(cnum) {
|
||||||
if let Some((prev, _)) = panic_runtime {
|
if let Some((prev, _)) = panic_runtime {
|
||||||
let prev_name = tcx.crate_name(prev);
|
let prev_name = tcx.crate_name(prev).to_string();
|
||||||
let cur_name = tcx.crate_name(cnum);
|
let cur_name = tcx.crate_name(cnum).to_string();
|
||||||
sess.err(&format!(
|
sess.emit_err(TwoPanicRuntimes { prev_name, cur_name });
|
||||||
"cannot link together two \
|
|
||||||
panic runtimes: {} and {}",
|
|
||||||
prev_name, cur_name
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
panic_runtime = Some((
|
panic_runtime = Some((
|
||||||
cnum,
|
cnum,
|
||||||
|
@ -384,13 +369,10 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
|
||||||
// First up, validate that our selected panic runtime is indeed exactly
|
// First up, validate that our selected panic runtime is indeed exactly
|
||||||
// our same strategy.
|
// our same strategy.
|
||||||
if found_strategy != desired_strategy {
|
if found_strategy != desired_strategy {
|
||||||
sess.err(&format!(
|
sess.emit_err(BadPanicStrategy {
|
||||||
"the linked panic runtime `{}` is \
|
runtime: tcx.crate_name(runtime_cnum).to_string(),
|
||||||
not compiled with this crate's \
|
strategy: desired_strategy.desc().to_string(),
|
||||||
panic strategy `{}`",
|
});
|
||||||
tcx.crate_name(runtime_cnum),
|
|
||||||
desired_strategy.desc()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next up, verify that all other crates are compatible with this panic
|
// 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 {
|
if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy {
|
||||||
sess.err(&format!(
|
sess.emit_err(RequiredPanicStrategy {
|
||||||
"the crate `{}` requires \
|
crate_name: tcx.crate_name(cnum).to_string(),
|
||||||
panic strategy `{}` which is \
|
found_strategy: found_strategy.desc().to_string(),
|
||||||
incompatible with this crate's \
|
desired_strategy: desired_strategy.desc().to_string() });
|
||||||
strategy of `{}`",
|
|
||||||
tcx.crate_name(cnum),
|
|
||||||
found_strategy.desc(),
|
|
||||||
desired_strategy.desc()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
|
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
|
||||||
if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy {
|
if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy {
|
||||||
sess.err(&format!(
|
sess.emit_err(IncompatiblePanicInDropStrategy {
|
||||||
"the crate `{}` is compiled with the \
|
crate_name: tcx.crate_name(cnum).to_string(),
|
||||||
panic-in-drop strategy `{}` which is \
|
found_strategy: found_drop_strategy.desc().to_string(),
|
||||||
incompatible with this crate's \
|
desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop.desc().to_string(),
|
||||||
strategy of `{}`",
|
});
|
||||||
tcx.crate_name(cnum),
|
|
||||||
found_drop_strategy.desc(),
|
|
||||||
tcx.sess.opts.unstable_opts.panic_in_drop.desc()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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)]
|
#![feature(never_type)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ mod native_libs;
|
||||||
mod rmeta;
|
mod rmeta;
|
||||||
|
|
||||||
pub mod creader;
|
pub mod creader;
|
||||||
|
pub mod errors;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod locator;
|
pub mod locator;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue