Skip to content

Commit e433029

Browse files
committed
Give a more helpful error for "trimmed_def_paths construted"
1 parent 2d76a9d commit e433029

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4039,6 +4039,7 @@ dependencies = [
40394039
"rustc_ast",
40404040
"rustc_attr",
40414041
"rustc_data_structures",
4042+
"rustc_error_messages",
40424043
"rustc_errors",
40434044
"rustc_feature",
40444045
"rustc_graphviz",

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<S: Into<String>> From<S> for DiagnosticMessage {
380380
}
381381
}
382382

383-
/// A workaround for "good path" ICEs when formatting types in disables lints.
383+
/// A workaround for "good path" ICEs when formatting types in disabled lints.
384384
///
385385
/// Delays formatting until `.into(): DiagnosticMessage` is used.
386386
pub struct DelayDm<F>(pub F);

compiler/rustc_middle/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ rustc_ast = { path = "../rustc_ast" }
1818
rustc_attr = { path = "../rustc_attr" }
1919
rustc_data_structures = { path = "../rustc_data_structures" }
2020
rustc_errors = { path = "../rustc_errors" }
21+
# Used for intra-doc links
22+
rustc_error_messages = { path = "../rustc_error_messages" }
2123
rustc_feature = { path = "../rustc_feature" }
2224
rustc_graphviz = { path = "../rustc_graphviz" }
2325
rustc_hir = { path = "../rustc_hir" }

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -2883,13 +2883,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
28832883
/// `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere.
28842884
///
28852885
/// The implementation uses similar import discovery logic to that of 'use' suggestions.
2886+
///
2887+
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths`].
28862888
fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
28872889
let mut map: FxHashMap<DefId, Symbol> = FxHashMap::default();
28882890

28892891
if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {
2892+
// Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting.
2893+
//
28902894
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
28912895
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
2892-
tcx.sess.delay_good_path_bug("trimmed_def_paths constructed");
2896+
tcx.sess.delay_good_path_bug(
2897+
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
2898+
);
28932899
}
28942900

28952901
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =

0 commit comments

Comments
 (0)