Skip to content

Commit

Permalink
respond to review feedback: mainly eliminate as many conversions as p…
Browse files Browse the repository at this point in the history
…ossible...

- ... when creating diagnostics in rustc_metadata
-  use the error_code! macro
- pass macro output to diag.code()
- use fluent from within manual implementation of SessionDiagnostic
- emit the untested errors in case they occur in the wild
- stop panicking in the probably-not-dead code, add fixme to write test
  • Loading branch information
CleanCut committed Aug 31, 2022
1 parent d0ba1fb commit 0d65819
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 226 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,7 @@ dependencies = [
"rustc_macros",
"rustc_serialize",
"rustc_span",
"rustc_target",
"serde",
"serde_json",
"termcolor",
Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/metadata.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,33 @@ metadata_cannot_find_crate =
metadata_no_dylib_plugin =
plugin `{$crate_name}` only found in rlib format, but must be available in dylib format
metadata_target_not_installed =
the `{$locator_triple}` target may not be installed
metadata_target_no_std_support =
the `{$locator_triple}` target may not support the standard library
metadata_consider_downloading_target =
consider downloading the target with `rustup target add {$locator_triple}`
metadata_std_required =
`std` is required by `{$current_crate}` because it does not declare `#![no_std]`
metadata_consider_building_std =
consider building the standard library from source with `cargo build -Zbuild-std`
metadata_compiler_missing_profiler =
the compiler may have been built without the profiler runtime
metadata_install_missing_components =
maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`
metadata_cant_find_crate =
can't find crate
metadata_crate_location_unknown_type =
extern location for {$crate_name} is of an unknown type: {$path}
metadata_lib_filename_form =
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
5 changes: 3 additions & 2 deletions compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_hir = { path = "../rustc_hir" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_target = { path = "../rustc_target" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.9"
termize = "0.1.1"
serde = { version = "1.0.125", features = ["derive"] }
serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["handleapi", "synchapi", "winbase"] }
winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] }
7 changes: 7 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_span::edition::LATEST_STABLE_EDITION;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_span::{edition::Edition, Span, DUMMY_SP};
use rustc_target::spec::PanicStrategy;
use std::borrow::Cow;
use std::fmt;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -144,6 +145,12 @@ impl IntoDiagnosticArg for usize {
}
}

impl IntoDiagnosticArg for PanicStrategy {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
}
}

impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
fn into(self) -> FluentValue<'source> {
match self {
Expand Down
19 changes: 8 additions & 11 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,10 @@ 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.emit_err(CrateNotPanicRuntime { crate_name: name.to_string() });
self.sess.emit_err(CrateNotPanicRuntime { crate_name: name });
}
if data.required_panic_strategy() != Some(desired_strategy) {
self.sess.emit_err(NoPanicStrategy {
crate_name: name.to_string(),
strategy: desired_strategy.desc().to_string(),
});
self.sess.emit_err(NoPanicStrategy { crate_name: name, strategy: desired_strategy });
}

self.cstore.injected_panic_runtime = Some(cnum);
Expand Down Expand Up @@ -784,7 +781,7 @@ impl<'a> CrateLoader<'a> {

// Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime() {
self.sess.emit_err(NotProfilerRuntime { crate_name: name.to_string() });
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
}
}

Expand Down Expand Up @@ -828,8 +825,8 @@ impl<'a> CrateLoader<'a> {
match global_allocator {
Some(other_crate) => {
self.sess.emit_err(ConflictingGlobalAlloc {
crate_name: data.name().to_string(),
other_crate_name: other_crate.to_string(),
crate_name: data.name(),
other_crate_name: other_crate,
});
}
None => global_allocator = Some(data.name()),
Expand Down Expand Up @@ -874,9 +871,9 @@ impl<'a> CrateLoader<'a> {
let data = self.cstore.get_crate_data(dep);
if needs_dep(&data) {
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(),
crate_name: self.cstore.get_crate_data(krate).name(),
needs_crate_name: what,
deps_crate_name: data.name(),
});
}
}
Expand Down
30 changes: 13 additions & 17 deletions compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
if src.rlib.is_some() {
continue;
}
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum).to_string() });
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum) });
}
return Vec::new();
}
Expand Down Expand Up @@ -224,10 +224,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
Linkage::Static => "rlib",
_ => "dylib",
};
sess.emit_err(LibRequired {
crate_name: tcx.crate_name(cnum).to_string(),
kind: kind.to_string(),
});
sess.emit_err(LibRequired { crate_name: tcx.crate_name(cnum), kind: kind });
}
}
}
Expand All @@ -251,8 +248,7 @@ fn add_library(
// This error is probably a little obscure, but I imagine that it
// can be refined over time.
if link2 != link || link == RequireStatic {
tcx.sess
.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum).to_string() });
tcx.sess.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum) });
}
}
None => {
Expand Down Expand Up @@ -347,8 +343,8 @@ 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).to_string();
let cur_name = tcx.crate_name(cnum).to_string();
let prev_name = tcx.crate_name(prev);
let cur_name = tcx.crate_name(cnum);
sess.emit_err(TwoPanicRuntimes { prev_name, cur_name });
}
panic_runtime = Some((
Expand All @@ -370,8 +366,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
// our same strategy.
if found_strategy != desired_strategy {
sess.emit_err(BadPanicStrategy {
runtime: tcx.crate_name(runtime_cnum).to_string(),
strategy: desired_strategy.desc().to_string(),
runtime: tcx.crate_name(runtime_cnum),
strategy: desired_strategy,
});
}

Expand All @@ -390,17 +386,17 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {

if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy {
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() });
crate_name: tcx.crate_name(cnum),
found_strategy,
desired_strategy});
}

let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy {
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(),
crate_name: tcx.crate_name(cnum),
found_strategy: found_drop_strategy,
desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
});
}
}
Expand Down
Loading

0 comments on commit 0d65819

Please sign in to comment.