rustc_middle::ty::print::pretty

Function trimmed_def_paths

source
pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol>
Expand description

The purpose of this function is to collect public symbols names that are unique across all crates in the build. Later, when printing about types we can use those names instead of the full exported path to them.

So essentially, if a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name.

This has wide implications on error messages with types, for example, shortening std::vec::Vec to just Vec, as long as there is no other Vec importable anywhere.

The implementation uses similar import discovery logic to that of ‘use’ suggestions.

See also with_no_trimmed_paths!.