Skip to content

Commit 086d17b

Browse files
committed
Refactor try_print_trimmed_def_path.
Inverting the condition lets us merge the two `Ok(false)` paths. I also find the inverted condition easier to read: "all the things that must be true for trimming to occur", instead of "any of the things that must be true for trimming to not occur".
1 parent 4efddb1 commit 086d17b

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -365,26 +365,19 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
365365

366366
/// Try to see if this path can be trimmed to a unique symbol name.
367367
fn try_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintError> {
368-
if with_forced_trimmed_paths() {
369-
let trimmed = self.force_print_trimmed_def_path(def_id)?;
370-
if trimmed {
371-
return Ok(true);
372-
}
368+
if with_forced_trimmed_paths() && self.force_print_trimmed_def_path(def_id)? {
369+
return Ok(true);
373370
}
374-
if !self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
375-
|| matches!(self.tcx().sess.opts.trimmed_def_paths, TrimmedDefPaths::Never)
376-
|| with_no_trimmed_paths()
377-
|| with_crate_prefix()
371+
if self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
372+
&& !matches!(self.tcx().sess.opts.trimmed_def_paths, TrimmedDefPaths::Never)
373+
&& !with_no_trimmed_paths()
374+
&& !with_crate_prefix()
375+
&& let Some(symbol) = self.tcx().trimmed_def_paths(()).get(&def_id)
378376
{
379-
return Ok(false);
380-
}
381-
382-
match self.tcx().trimmed_def_paths(()).get(&def_id) {
383-
None => Ok(false),
384-
Some(symbol) => {
385-
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
386-
Ok(true)
387-
}
377+
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
378+
Ok(true)
379+
} else {
380+
Ok(false)
388381
}
389382
}
390383

0 commit comments

Comments
 (0)