Shorten trimmed display of closures
When `with_forced_trimmed_paths` is used, only print filename and start of the closure's span, to reduce their verbosity.
This commit is contained in:
parent
30ae261c42
commit
4d4d4786f9
@ -16,6 +16,7 @@ use rustc_session::config::TrimmedDefPaths;
|
||||
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
|
||||
use rustc_session::Limit;
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::FileNameDisplayPreference;
|
||||
use rustc_target::abi::Size;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use smallvec::SmallVec;
|
||||
@ -818,11 +819,16 @@ pub trait PrettyPrinter<'tcx>:
|
||||
p!("@", print_def_path(did.to_def_id(), substs));
|
||||
} else {
|
||||
let span = self.tcx().def_span(did);
|
||||
let preference = if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
|
||||
FileNameDisplayPreference::Short
|
||||
} else {
|
||||
FileNameDisplayPreference::Remapped
|
||||
};
|
||||
p!(write(
|
||||
"@{}",
|
||||
// This may end up in stderr diagnostics but it may also be emitted
|
||||
// into MIR. Hence we use the remapped path if available
|
||||
self.tcx().sess.source_map().span_to_embeddable_string(span)
|
||||
self.tcx().sess.source_map().span_to_string(span, preference)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
|
@ -259,6 +259,10 @@ impl RealFileName {
|
||||
FileNameDisplayPreference::Remapped => {
|
||||
self.remapped_path_if_available().to_string_lossy()
|
||||
}
|
||||
FileNameDisplayPreference::Short => self
|
||||
.local_path_if_available()
|
||||
.file_name()
|
||||
.map_or_else(|| "".into(), |f| f.to_string_lossy()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -302,6 +306,9 @@ pub enum FileNameDisplayPreference {
|
||||
/// Display the path before the application of rewrite rules provided via `--remap-path-prefix`.
|
||||
/// This is appropriate for use in user-facing output (such as diagnostics).
|
||||
Local,
|
||||
/// Display only the filename, as a way to reduce the verbosity of the output.
|
||||
/// This is appropriate for use in user-facing output (such as diagnostics).
|
||||
Short,
|
||||
}
|
||||
|
||||
pub struct FileNameDisplay<'a> {
|
||||
|
@ -438,7 +438,11 @@ impl SourceMap {
|
||||
}
|
||||
}
|
||||
|
||||
fn span_to_string(&self, sp: Span, filename_display_pref: FileNameDisplayPreference) -> String {
|
||||
pub fn span_to_string(
|
||||
&self,
|
||||
sp: Span,
|
||||
filename_display_pref: FileNameDisplayPreference,
|
||||
) -> String {
|
||||
if self.files.borrow().source_files.is_empty() || sp.is_dummy() {
|
||||
return "no-location".to_string();
|
||||
}
|
||||
@ -446,12 +450,15 @@ impl SourceMap {
|
||||
let lo = self.lookup_char_pos(sp.lo());
|
||||
let hi = self.lookup_char_pos(sp.hi());
|
||||
format!(
|
||||
"{}:{}:{}: {}:{}",
|
||||
"{}:{}:{}{}",
|
||||
lo.file.name.display(filename_display_pref),
|
||||
lo.line,
|
||||
lo.col.to_usize() + 1,
|
||||
hi.line,
|
||||
hi.col.to_usize() + 1,
|
||||
if let FileNameDisplayPreference::Short = filename_display_pref {
|
||||
String::new()
|
||||
} else {
|
||||
format!(": {}:{}", hi.line, hi.col.to_usize() + 1)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ LL | where
|
||||
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`
|
||||
|
||||
error[E0271]: expected `[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]` to be a closure that returns `Unit3`, but it returns `Unit4`
|
||||
error[E0271]: expected `[closure@issue-62203-hrtb-ice.rs:42:16]` to be a closure that returns `Unit3`, but it returns `Unit4`
|
||||
--> $DIR/issue-62203-hrtb-ice.rs:39:9
|
||||
|
|
||||
LL | let v = Unit2.m(
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0271]: expected `TakeWhile<&mut IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>` to be an iterator that yields `&_`, but it yields `u8`
|
||||
error[E0271]: expected `TakeWhile<&mut IntoIter<u8>, [closure@issue-31173.rs:7:21]>` to be an iterator that yields `&_`, but it yields `u8`
|
||||
--> $DIR/issue-31173.rs:11:10
|
||||
|
|
||||
LL | .cloned()
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0271]: expected `[closure@$DIR/fallback-closure-wrap.rs:18:40: 18:47]` to be a closure that returns `()`, but it returns `!`
|
||||
error[E0271]: expected `[closure@fallback-closure-wrap.rs:18:40]` to be a closure that returns `()`, but it returns `!`
|
||||
--> $DIR/fallback-closure-wrap.rs:18:31
|
||||
|
|
||||
LL | let error = Closure::wrap(Box::new(move || {
|
||||
|
Loading…
x
Reference in New Issue
Block a user