Skip to content

Commit 82f38ab

Browse files
authored
Rollup merge of rust-lang#119974 - nnethercote:trimmed_def_paths-improvements, r=compiler-errors
Minor `trimmed_def_paths` improvements r? `@compiler-errors`
2 parents b6f68a7 + 32de78c commit 82f38ab

File tree

4 files changed

+32
-53
lines changed

4 files changed

+32
-53
lines changed

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_lint::unerased_lint_store;
3535
use rustc_metadata::creader::MetadataLoader;
3636
use rustc_metadata::locator;
3737
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
38-
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
38+
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
3939
use rustc_session::getopts::{self, Matches};
4040
use rustc_session::lint::{Lint, LintId};
4141
use rustc_session::{config, EarlyDiagCtxt, Session};
@@ -204,7 +204,7 @@ impl Callbacks for TimePassesCallbacks {
204204
//
205205
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
206206
.then(|| config.opts.unstable_opts.time_passes_format);
207-
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
207+
config.opts.trimmed_def_paths = true;
208208
}
209209
}
210210

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

+26-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
1515
use rustc_hir::def_id::{DefIdMap, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE};
1616
use rustc_hir::definitions::{DefKey, DefPathDataName};
1717
use rustc_hir::LangItem;
18-
use rustc_session::config::TrimmedDefPaths;
1918
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
2019
use rustc_session::Limit;
2120
use rustc_span::symbol::{kw, Ident, Symbol};
@@ -365,26 +364,19 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
365364

366365
/// Try to see if this path can be trimmed to a unique symbol name.
367366
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-
}
367+
if with_forced_trimmed_paths() && self.force_print_trimmed_def_path(def_id)? {
368+
return Ok(true);
373369
}
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()
370+
if self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
371+
&& self.tcx().sess.opts.trimmed_def_paths
372+
&& !with_no_trimmed_paths()
373+
&& !with_crate_prefix()
374+
&& let Some(symbol) = self.tcx().trimmed_def_paths(()).get(&def_id)
378375
{
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-
}
376+
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
377+
Ok(true)
378+
} else {
379+
Ok(false)
388380
}
389381
}
390382

@@ -3080,18 +3072,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
30803072
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths!`].
30813073
// this is pub to be able to intra-doc-link it
30823074
pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
3083-
let mut map: DefIdMap<Symbol> = Default::default();
3084-
3085-
if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {
3086-
// Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting.
3087-
//
3088-
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
3089-
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
3090-
tcx.sess.good_path_delayed_bug(
3091-
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
3092-
);
3093-
}
3094-
3075+
assert!(tcx.sess.opts.trimmed_def_paths);
3076+
3077+
// Trimming paths is expensive and not optimized, since we expect it to only be used for error
3078+
// reporting.
3079+
//
3080+
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
3081+
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
3082+
tcx.sess.good_path_delayed_bug(
3083+
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
3084+
);
3085+
3086+
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
3087+
// non-unique pairs will have a `None` entry.
30953088
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
30963089
&mut FxHashMap::default();
30973090

@@ -3121,6 +3114,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
31213114
}
31223115
});
31233116

3117+
// Put the symbol from all the unique namespace+symbol pairs into `map`.
3118+
let mut map: DefIdMap<Symbol> = Default::default();
31243119
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
31253120
use std::collections::hash_map::Entry::{Occupied, Vacant};
31263121

compiler/rustc_session/src/config.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,6 @@ impl Default for ErrorOutputType {
533533
}
534534
}
535535

536-
/// Parameter to control path trimming.
537-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
538-
pub enum TrimmedDefPaths {
539-
/// `try_print_trimmed_def_path` never prints a trimmed path and never calls the expensive
540-
/// query.
541-
#[default]
542-
Never,
543-
/// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call
544-
/// `good_path_delayed_bug`.
545-
Always,
546-
/// `try_print_trimmed_def_path` calls the expensive query, the query calls
547-
/// `good_path_delayed_bug`.
548-
GoodPath,
549-
}
550-
551536
#[derive(Clone, Hash, Debug)]
552537
pub enum ResolveDocLinks {
553538
/// Do not resolve doc links.
@@ -1089,7 +1074,7 @@ impl Default for Options {
10891074
debug_assertions: true,
10901075
actually_rustdoc: false,
10911076
resolve_doc_links: ResolveDocLinks::None,
1092-
trimmed_def_paths: TrimmedDefPaths::default(),
1077+
trimmed_def_paths: false,
10931078
cli_forced_codegen_units: None,
10941079
cli_forced_local_thinlto_off: false,
10951080
remap_path_prefix: Vec::new(),
@@ -2926,7 +2911,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29262911
debug_assertions,
29272912
actually_rustdoc: false,
29282913
resolve_doc_links: ResolveDocLinks::ExportedMetadata,
2929-
trimmed_def_paths: TrimmedDefPaths::default(),
2914+
trimmed_def_paths: false,
29302915
cli_forced_codegen_units: codegen_units,
29312916
cli_forced_local_thinlto_off: disable_local_thinlto,
29322917
remap_path_prefix,
@@ -3210,7 +3195,7 @@ pub(crate) mod dep_tracking {
32103195
LinkerPluginLto, LocationDetail, LtoCli, NextSolverConfig, OomStrategy, OptLevel,
32113196
OutFileName, OutputType, OutputTypes, Polonius, RemapPathScopeComponents, ResolveDocLinks,
32123197
SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion,
3213-
TrimmedDefPaths, WasiExecModel,
3198+
WasiExecModel,
32143199
};
32153200
use crate::lint;
32163201
use crate::utils::NativeLib;
@@ -3305,7 +3290,6 @@ pub(crate) mod dep_tracking {
33053290
SymbolManglingVersion,
33063291
RemapPathScopeComponents,
33073292
SourceFileHashAlgorithm,
3308-
TrimmedDefPaths,
33093293
OutFileName,
33103294
OutputType,
33113295
RealFileName,

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ top_level_options!(
183183
resolve_doc_links: ResolveDocLinks [TRACKED],
184184

185185
/// Control path trimming.
186-
trimmed_def_paths: TrimmedDefPaths [TRACKED],
186+
trimmed_def_paths: bool [TRACKED],
187187

188188
/// Specifications of codegen units / ThinLTO which are forced as a
189189
/// result of parsing command line options. These are not necessarily

0 commit comments

Comments
 (0)