Skip to content

Commit 0d65819

Browse files
committed
respond to review feedback: mainly eliminate as many conversions as possible...
- ... 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
1 parent d0ba1fb commit 0d65819

File tree

11 files changed

+234
-226
lines changed

11 files changed

+234
-226
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,7 @@ dependencies = [
35143514
"rustc_macros",
35153515
"rustc_serialize",
35163516
"rustc_span",
3517+
"rustc_target",
35173518
"serde",
35183519
"serde_json",
35193520
"termcolor",

compiler/rustc_error_messages/locales/en-US/metadata.ftl

+30
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,33 @@ metadata_cannot_find_crate =
225225
226226
metadata_no_dylib_plugin =
227227
plugin `{$crate_name}` only found in rlib format, but must be available in dylib format
228+
229+
metadata_target_not_installed =
230+
the `{$locator_triple}` target may not be installed
231+
232+
metadata_target_no_std_support =
233+
the `{$locator_triple}` target may not support the standard library
234+
235+
metadata_consider_downloading_target =
236+
consider downloading the target with `rustup target add {$locator_triple}`
237+
238+
metadata_std_required =
239+
`std` is required by `{$current_crate}` because it does not declare `#![no_std]`
240+
241+
metadata_consider_building_std =
242+
consider building the standard library from source with `cargo build -Zbuild-std`
243+
244+
metadata_compiler_missing_profiler =
245+
the compiler may have been built without the profiler runtime
246+
247+
metadata_install_missing_components =
248+
maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`
249+
250+
metadata_cant_find_crate =
251+
can't find crate
252+
253+
metadata_crate_location_unknown_type =
254+
extern location for {$crate_name} is of an unknown type: {$path}
255+
256+
metadata_lib_filename_form =
257+
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}

compiler/rustc_errors/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ rustc_macros = { path = "../rustc_macros" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_hir = { path = "../rustc_hir" }
1717
rustc_lint_defs = { path = "../rustc_lint_defs" }
18+
rustc_target = { path = "../rustc_target" }
1819
unicode-width = "0.1.4"
1920
atty = "0.2"
2021
termcolor = "1.0"
2122
annotate-snippets = "0.9"
2223
termize = "0.1.1"
23-
serde = { version = "1.0.125", features = ["derive"] }
24+
serde = { version = "1.0.125", features = [ "derive" ] }
2425
serde_json = "1.0.59"
2526

2627
[target.'cfg(windows)'.dependencies]
27-
winapi = { version = "0.3", features = ["handleapi", "synchapi", "winbase"] }
28+
winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] }

compiler/rustc_errors/src/diagnostic.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_span::edition::LATEST_STABLE_EDITION;
1111
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1212
use rustc_span::{edition::Edition, Span, DUMMY_SP};
13+
use rustc_target::spec::PanicStrategy;
1314
use std::borrow::Cow;
1415
use std::fmt;
1516
use std::hash::{Hash, Hasher};
@@ -144,6 +145,12 @@ impl IntoDiagnosticArg for usize {
144145
}
145146
}
146147

148+
impl IntoDiagnosticArg for PanicStrategy {
149+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
150+
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
151+
}
152+
}
153+
147154
impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
148155
fn into(self) -> FluentValue<'source> {
149156
match self {

compiler/rustc_metadata/src/creader.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,10 @@ impl<'a> CrateLoader<'a> {
750750
// Sanity check the loaded crate to ensure it is indeed a panic runtime
751751
// and the panic strategy is indeed what we thought it was.
752752
if !data.is_panic_runtime() {
753-
self.sess.emit_err(CrateNotPanicRuntime { crate_name: name.to_string() });
753+
self.sess.emit_err(CrateNotPanicRuntime { crate_name: name });
754754
}
755755
if data.required_panic_strategy() != Some(desired_strategy) {
756-
self.sess.emit_err(NoPanicStrategy {
757-
crate_name: name.to_string(),
758-
strategy: desired_strategy.desc().to_string(),
759-
});
756+
self.sess.emit_err(NoPanicStrategy { crate_name: name, strategy: desired_strategy });
760757
}
761758

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

785782
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
786783
if !data.is_profiler_runtime() {
787-
self.sess.emit_err(NotProfilerRuntime { crate_name: name.to_string() });
784+
self.sess.emit_err(NotProfilerRuntime { crate_name: name });
788785
}
789786
}
790787

@@ -828,8 +825,8 @@ impl<'a> CrateLoader<'a> {
828825
match global_allocator {
829826
Some(other_crate) => {
830827
self.sess.emit_err(ConflictingGlobalAlloc {
831-
crate_name: data.name().to_string(),
832-
other_crate_name: other_crate.to_string(),
828+
crate_name: data.name(),
829+
other_crate_name: other_crate,
833830
});
834831
}
835832
None => global_allocator = Some(data.name()),
@@ -874,9 +871,9 @@ impl<'a> CrateLoader<'a> {
874871
let data = self.cstore.get_crate_data(dep);
875872
if needs_dep(&data) {
876873
self.sess.emit_err(NoTransitiveNeedsDep {
877-
crate_name: self.cstore.get_crate_data(krate).name().to_string(),
878-
needs_crate_name: what.to_string(),
879-
deps_crate_name: data.name().to_string(),
874+
crate_name: self.cstore.get_crate_data(krate).name(),
875+
needs_crate_name: what,
876+
deps_crate_name: data.name(),
880877
});
881878
}
882879
}

compiler/rustc_metadata/src/dependency_format.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
140140
if src.rlib.is_some() {
141141
continue;
142142
}
143-
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum).to_string() });
143+
sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum) });
144144
}
145145
return Vec::new();
146146
}
@@ -224,10 +224,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
224224
Linkage::Static => "rlib",
225225
_ => "dylib",
226226
};
227-
sess.emit_err(LibRequired {
228-
crate_name: tcx.crate_name(cnum).to_string(),
229-
kind: kind.to_string(),
230-
});
227+
sess.emit_err(LibRequired { crate_name: tcx.crate_name(cnum), kind: kind });
231228
}
232229
}
233230
}
@@ -251,8 +248,7 @@ fn add_library(
251248
// This error is probably a little obscure, but I imagine that it
252249
// can be refined over time.
253250
if link2 != link || link == RequireStatic {
254-
tcx.sess
255-
.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum).to_string() });
251+
tcx.sess.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum) });
256252
}
257253
}
258254
None => {
@@ -347,8 +343,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
347343

348344
if tcx.is_panic_runtime(cnum) {
349345
if let Some((prev, _)) = panic_runtime {
350-
let prev_name = tcx.crate_name(prev).to_string();
351-
let cur_name = tcx.crate_name(cnum).to_string();
346+
let prev_name = tcx.crate_name(prev);
347+
let cur_name = tcx.crate_name(cnum);
352348
sess.emit_err(TwoPanicRuntimes { prev_name, cur_name });
353349
}
354350
panic_runtime = Some((
@@ -370,8 +366,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
370366
// our same strategy.
371367
if found_strategy != desired_strategy {
372368
sess.emit_err(BadPanicStrategy {
373-
runtime: tcx.crate_name(runtime_cnum).to_string(),
374-
strategy: desired_strategy.desc().to_string(),
369+
runtime: tcx.crate_name(runtime_cnum),
370+
strategy: desired_strategy,
375371
});
376372
}
377373

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

391387
if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy {
392388
sess.emit_err(RequiredPanicStrategy {
393-
crate_name: tcx.crate_name(cnum).to_string(),
394-
found_strategy: found_strategy.desc().to_string(),
395-
desired_strategy: desired_strategy.desc().to_string() });
389+
crate_name: tcx.crate_name(cnum),
390+
found_strategy,
391+
desired_strategy});
396392
}
397393

398394
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
399395
if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy {
400396
sess.emit_err(IncompatiblePanicInDropStrategy {
401-
crate_name: tcx.crate_name(cnum).to_string(),
402-
found_strategy: found_drop_strategy.desc().to_string(),
403-
desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop.desc().to_string(),
397+
crate_name: tcx.crate_name(cnum),
398+
found_strategy: found_drop_strategy,
399+
desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
404400
});
405401
}
406402
}

0 commit comments

Comments
 (0)