new unstable option: -Zwrite-long-types-to-disk

This option guards the logic of writing long type names in files and
instead using short forms in error messages in rustc_middle/ty/error
behind a flag. The main motivation for this change is to disable this
behaviour when running ui tests.

This logic can be triggered by running tests in a directory that has a
long enough path, e.g. /my/very-long-path/where/rust-codebase/exists/

This means ui tests can fail depending on how long the path to their
file is.

Some ui tests actually rely on this behaviour for their assertions,
so for those we enable the flag manually.
This commit is contained in:
Mahdi Dibaiee 2023-07-20 16:47:42 +01:00
parent 33a2c2487a
commit 8df39667dc
25 changed files with 47 additions and 32 deletions

View file

@ -339,12 +339,17 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
let width = self.sess.diagnostic_width();
let length_limit = width.saturating_sub(30);
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.pretty_print_type(ty)
.expect("could not write to `String`")
.into_buffer();
if !self.sess.opts.unstable_opts.write_long_types_to_disk {
return (regular, None);
}
let width = self.sess.diagnostic_width();
let length_limit = width.saturating_sub(30);
if regular.len() <= width {
return (regular, None);
}