Disable visible path calculation for PrettyPrinter in Ok path of compiler
This commit is contained in:
parent
db1fb85cff
commit
9da27f0429
10 changed files with 54 additions and 29 deletions
|
@ -59,6 +59,7 @@ thread_local! {
|
|||
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
|
||||
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
|
||||
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
|
||||
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
|
||||
}
|
||||
|
||||
/// Avoids running any queries during any prints that occur
|
||||
|
@ -112,6 +113,16 @@ pub fn with_no_trimmed_paths<F: FnOnce() -> R, R>(f: F) -> R {
|
|||
})
|
||||
}
|
||||
|
||||
/// Prevent selection of visible paths. `Display` impl of DefId will prefer visible (public) reexports of types as paths.
|
||||
pub fn with_no_visible_paths<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
NO_VISIBLE_PATH.with(|flag| {
|
||||
let old = flag.replace(true);
|
||||
let result = f();
|
||||
flag.set(old);
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
/// The "region highlights" are used to control region printing during
|
||||
/// specific error messages. When a "region highlight" is enabled, it
|
||||
/// gives an alternate way to print specific regions. For now, we
|
||||
|
@ -268,6 +279,10 @@ pub trait PrettyPrinter<'tcx>:
|
|||
/// from at least one local module, and returns `true`. If the crate defining `def_id` is
|
||||
/// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
|
||||
fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
|
||||
if NO_VISIBLE_PATH.with(|flag| flag.get()) {
|
||||
return Ok((self, false));
|
||||
}
|
||||
|
||||
let mut callers = Vec::new();
|
||||
self.try_print_visible_def_path_recur(def_id, &mut callers)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue