@@ -15,7 +15,6 @@ use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
15
15
use rustc_hir:: def_id:: { DefIdMap , DefIdSet , ModDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
16
16
use rustc_hir:: definitions:: { DefKey , DefPathDataName } ;
17
17
use rustc_hir:: LangItem ;
18
- use rustc_session:: config:: TrimmedDefPaths ;
19
18
use rustc_session:: cstore:: { ExternCrate , ExternCrateSource } ;
20
19
use rustc_session:: Limit ;
21
20
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
@@ -365,26 +364,19 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
365
364
366
365
/// Try to see if this path can be trimmed to a unique symbol name.
367
366
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 ) ;
373
369
}
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)
378
375
{
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 )
388
380
}
389
381
}
390
382
@@ -3080,18 +3072,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
3080
3072
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths!`].
3081
3073
// this is pub to be able to intra-doc-link it
3082
3074
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.
3095
3088
let unique_symbols_rev: & mut FxHashMap < ( Namespace , Symbol ) , Option < DefId > > =
3096
3089
& mut FxHashMap :: default ( ) ;
3097
3090
@@ -3121,6 +3114,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
3121
3114
}
3122
3115
} ) ;
3123
3116
3117
+ // Put the symbol from all the unique namespace+symbol pairs into `map`.
3118
+ let mut map: DefIdMap < Symbol > = Default :: default ( ) ;
3124
3119
for ( ( _, symbol) , opt_def_id) in unique_symbols_rev. drain ( ) {
3125
3120
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
3126
3121
0 commit comments