Skip to content

Commit 8df3966

Browse files
committed
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.
1 parent 33a2c24 commit 8df3966

File tree

25 files changed

+47
-32
lines changed

25 files changed

+47
-32
lines changed

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ fn test_unstable_options_tracking_hash() {
738738
untracked!(unstable_options, true);
739739
untracked!(validate_mir, true);
740740
untracked!(verbose, true);
741+
untracked!(write_long_types_to_disk, true);
741742
// tidy-alphabetical-end
742743

743744
macro_rules! tracked {

compiler/rustc_middle/src/ty/error.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,17 @@ impl<'tcx> TyCtxt<'tcx> {
339339
}
340340

341341
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
342-
let width = self.sess.diagnostic_width();
343-
let length_limit = width.saturating_sub(30);
344342
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
345343
.pretty_print_type(ty)
346344
.expect("could not write to `String`")
347345
.into_buffer();
346+
347+
if !self.sess.opts.unstable_opts.write_long_types_to_disk {
348+
return (regular, None);
349+
}
350+
351+
let width = self.sess.diagnostic_width();
352+
let length_limit = width.saturating_sub(30);
348353
if regular.len() <= width {
349354
return (regular, None);
350355
}

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,8 @@ written to standard error output)"),
18751875
Requires `-Clto[=[fat,yes]]`"),
18761876
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
18771877
"whether to build a wasi command or reactor"),
1878+
write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
1879+
"whether long type names should be written to files instead of being printed in errors"),
18781880
// tidy-alphabetical-end
18791881

18801882
// If you add a new option, please update:

src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ impl<'test> TestCx<'test> {
23302330
// Hide line numbers to reduce churn
23312331
rustc.arg("-Zui-testing");
23322332
rustc.arg("-Zdeduplicate-diagnostics=no");
2333+
rustc.arg("-Zwrite-long-types-to-disk=no");
23332334
// FIXME: use this for other modes too, for perf?
23342335
rustc.arg("-Cstrip=debuginfo");
23352336
}

tests/ui/diagnostic-width/E0271.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ note: expected this to be `Foo`
1515
|
1616
LL | type Error = E;
1717
| ^
18-
= note: required for the cast from `Box<Result<..., ...>>` to `Box<(dyn Future<Error = Foo> + 'static)>`
19-
= note: the full name for the source type has been written to '$TEST_BUILD_DIR/diagnostic-width/E0271/E0271.long-type-hash.txt'
18+
= note: required for the cast from `Box<Result<Result<(), Result<Result<(), Result<Result<(), Option<{integer}>>, ()>>, ()>>, ()>>` to `Box<(dyn Future<Error = Foo> + 'static)>`
2019

2120
error: aborting due to previous error
2221

tests/ui/diagnostic-width/long-E0308.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: --diagnostic-width=60
1+
// compile-flags: --diagnostic-width=60 -Zwrite-long-types-to-disk=yes
22
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
33

44
mod a {

tests/ui/error-codes/E0271.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: -Zwrite-long-types-to-disk=yes
12
trait Trait { type AssociatedType; }
23

34
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {

tests/ui/error-codes/E0271.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0271]: type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
2-
--> $DIR/E0271.rs:10:9
2+
--> $DIR/E0271.rs:11:9
33
|
44
LL | foo(3_i8);
55
| --- ^^^^ type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
66
| |
77
| required by a bound introduced by this call
88
|
99
note: expected this to be `u32`
10-
--> $DIR/E0271.rs:7:43
10+
--> $DIR/E0271.rs:8:43
1111
|
1212
LL | impl Trait for i8 { type AssociatedType = &'static str; }
1313
| ^^^^^^^^^^^^
1414
note: required by a bound in `foo`
15-
--> $DIR/E0271.rs:3:32
15+
--> $DIR/E0271.rs:4:32
1616
|
1717
LL | fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
1818
| ^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

tests/ui/error-codes/E0275.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: -Zwrite-long-types-to-disk=yes
12
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
23
trait Foo {}
34

tests/ui/error-codes/E0275.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error[E0275]: overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<...>>>>>>>: Foo`
2-
--> $DIR/E0275.rs:6:33
2+
--> $DIR/E0275.rs:7:33
33
|
44
LL | impl<T> Foo for T where Bar<T>: Foo {}
55
| ^^^
66
|
77
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`E0275`)
88
note: required for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<...>>>>>>>>>>>>>>>>>>>>>` to implement `Foo`
9-
--> $DIR/E0275.rs:6:9
9+
--> $DIR/E0275.rs:7:9
1010
|
1111
LL | impl<T> Foo for T where Bar<T>: Foo {}
1212
| ^^^ ^ --- unsatisfied trait bound introduced here

0 commit comments

Comments
 (0)