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

25 files changed

+47
-32
lines changed

compiler/rustc_interface/src/tests.rs

+1
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

+7-2
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

+2
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

+1
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

+1-2
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

+1-1
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

+1
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

+3-3
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

+1
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

+2-2
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

tests/ui/higher-ranked/trait-bounds/hang-on-deeply-nested-dyn.rs

+1
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

34
fn id(

tests/ui/higher-ranked/trait-bounds/hang-on-deeply-nested-dyn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hang-on-deeply-nested-dyn.rs:12:5
2+
--> $DIR/hang-on-deeply-nested-dyn.rs:13:5
33
|
44
LL | ) -> &dyn Fn(
55
| ______-

tests/ui/higher-ranked/trait-bounds/issue-30786.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ LL | pub struct Filter<S, F> {
3131
LL | let count = filter.countx();
3232
| ^^^^^^ method cannot be called due to unsatisfied trait bounds
3333
|
34-
= note: the full type name has been written to '$TEST_BUILD_DIR/higher-ranked/trait-bounds/issue-30786/issue-30786.long-type-hash.txt'
3534
note: the following trait bounds were not satisfied:
3635
`&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
3736
`&'a mut &mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`

tests/ui/issues/issue-20413.rs

+1
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
fn answer(self);

tests/ui/issues/issue-20413.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0392]: parameter `T` is never used
2-
--> $DIR/issue-20413.rs:6:15
2+
--> $DIR/issue-20413.rs:7:15
33
|
44
LL | struct NoData<T>;
55
| ^ unused parameter
@@ -8,14 +8,14 @@ LL | struct NoData<T>;
88
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
99

1010
error[E0275]: overflow evaluating the requirement `NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>: Foo`
11-
--> $DIR/issue-20413.rs:9:36
11+
--> $DIR/issue-20413.rs:10:36
1212
|
1313
LL | impl<T> Foo for T where NoData<T>: Foo {
1414
| ^^^
1515
|
1616
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
1717
note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>>>>>>>` to implement `Foo`
18-
--> $DIR/issue-20413.rs:9:9
18+
--> $DIR/issue-20413.rs:10:9
1919
|
2020
LL | impl<T> Foo for T where NoData<T>: Foo {
2121
| ^^^ ^ --- unsatisfied trait bound introduced here
@@ -24,20 +24,20 @@ LL | impl<T> Foo for T where NoData<T>: Foo {
2424
= note: required for `NoData<T>` to implement `Foo`
2525

2626
error[E0275]: overflow evaluating the requirement `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>: Bar`
27-
--> $DIR/issue-20413.rs:28:42
27+
--> $DIR/issue-20413.rs:29:42
2828
|
2929
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
3030
| ^^^
3131
|
3232
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
3333
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
34-
--> $DIR/issue-20413.rs:35:9
34+
--> $DIR/issue-20413.rs:36:9
3535
|
3636
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
3737
| ^^^ ^ --- unsatisfied trait bound introduced here
3838
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
3939
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
40-
--> $DIR/issue-20413.rs:28:9
40+
--> $DIR/issue-20413.rs:29:9
4141
|
4242
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
4343
| ^^^ ^ --- unsatisfied trait bound introduced here
@@ -46,20 +46,20 @@ LL | impl<T> Bar for T where EvenLessData<T>: Baz {
4646
= note: required for `EvenLessData<T>` to implement `Baz`
4747

4848
error[E0275]: overflow evaluating the requirement `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>: Baz`
49-
--> $DIR/issue-20413.rs:35:42
49+
--> $DIR/issue-20413.rs:36:42
5050
|
5151
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
5252
| ^^^
5353
|
5454
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
5555
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
56-
--> $DIR/issue-20413.rs:28:9
56+
--> $DIR/issue-20413.rs:29:9
5757
|
5858
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
5959
| ^^^ ^ --- unsatisfied trait bound introduced here
6060
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
6161
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
62-
--> $DIR/issue-20413.rs:35:9
62+
--> $DIR/issue-20413.rs:36:9
6363
|
6464
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
6565
| ^^^ ^ --- unsatisfied trait bound introduced here

tests/ui/issues/issue-23122-2.rs

+1
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 Next {
34
type Next: Next;

tests/ui/issues/issue-23122-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error[E0275]: overflow evaluating the requirement `<<<<<<<... as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized`
2-
--> $DIR/issue-23122-2.rs:11:17
2+
--> $DIR/issue-23122-2.rs:12:17
33
|
44
LL | type Next = <GetNext<T::Next> as Next>::Next;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_23122_2`)
88
note: required for `GetNext<<<<<<<... as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next>` to implement `Next`
9-
--> $DIR/issue-23122-2.rs:10:15
9+
--> $DIR/issue-23122-2.rs:11:15
1010
|
1111
LL | impl<T: Next> Next for GetNext<T> {
1212
| - ^^^^ ^^^^^^^^^^

tests/ui/issues/issue-37311-type-length-limit/issue-37311.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-fail
2+
// compile-flags: -Zwrite-long-types-to-disk=yes
23
// normalize-stderr-test: ".nll/" -> "/"
34
// ignore-compare-mode-next-solver (hangs)
45

tests/ui/issues/issue-37311-type-length-limit/issue-37311.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: reached the recursion limit while instantiating `<(&(&(..., ...), ...), ...) as Foo>::recurse`
2-
--> $DIR/issue-37311.rs:18:9
2+
--> $DIR/issue-37311.rs:19:9
33
|
44
LL | (self, self).recurse();
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: `<T as Foo>::recurse` defined here
8-
--> $DIR/issue-37311.rs:17:5
8+
--> $DIR/issue-37311.rs:18:5
99
|
1010
LL | fn recurse(&self) {
1111
| ^^^^^^^^^^^^^^^^^

tests/ui/methods/inherent-bound-in-probe.rs

+1
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

34
// Fixes #110131

tests/ui/methods/inherent-bound-in-probe.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `Helper<'a, T>` is not an iterator
2-
--> $DIR/inherent-bound-in-probe.rs:40:21
2+
--> $DIR/inherent-bound-in-probe.rs:41:21
33
|
44
LL | type IntoIter = Helper<'a, T>;
55
| ^^^^^^^^^^^^^ `Helper<'a, T>` is not an iterator
@@ -9,14 +9,14 @@ note: required by a bound in `std::iter::IntoIterator::IntoIter`
99
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
1010

1111
error[E0275]: overflow evaluating the requirement `&_: IntoIterator`
12-
--> $DIR/inherent-bound-in-probe.rs:44:17
12+
--> $DIR/inherent-bound-in-probe.rs:45:17
1313
|
1414
LL | Helper::new(&self.0)
1515
| ^^^
1616
|
1717
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inherent_bound_in_probe`)
1818
note: required for `&BitReaderWrapper<_>` to implement `IntoIterator`
19-
--> $DIR/inherent-bound-in-probe.rs:34:13
19+
--> $DIR/inherent-bound-in-probe.rs:35:13
2020
|
2121
LL | impl<'a, T> IntoIterator for &'a BitReaderWrapper<T>
2222
| ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | &'a T: IntoIterator<Item = &'a u8>,
2727
= note: required for `&BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<...>>>>>` to implement `IntoIterator`
2828
= note: the full type name has been written to '$TEST_BUILD_DIR/methods/inherent-bound-in-probe/inherent-bound-in-probe.long-type-hash.txt'
2929
note: required by a bound in `Helper<'a, T>`
30-
--> $DIR/inherent-bound-in-probe.rs:25:25
30+
--> $DIR/inherent-bound-in-probe.rs:26:25
3131
|
3232
LL | &'a T: IntoIterator<Item = &'a u8>,
3333
| ^^^^^^^^^^^^^ required by this bound in `Helper<'a, T>`

tests/ui/recursion/issue-83150.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// build-fail
2-
// compile-flags: -Copt-level=0
2+
// compile-flags: -Copt-level=0 -Zwrite-long-types-to-disk=yes
33
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
44
//~^^^ ERROR overflow evaluating the requirement
55
// ignore-compare-mode-next-solver (hangs)

tests/ui/regions/issue-102374.rs

+1
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
use std::cell::Cell;
34

tests/ui/regions/issue-102374.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/issue-102374.rs:17:5
2+
--> $DIR/issue-102374.rs:18:5
33
|
44
LL | ) -> i32 {
55
| --- expected `i32` because of return type

tests/ui/traits/issue-91949-hangs-on-recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// build-fail
2-
// compile-flags: -Zinline-mir=no
2+
// compile-flags: -Zinline-mir=no -Zwrite-long-types-to-disk=yes
33
// error-pattern: overflow evaluating the requirement `<std::iter::Empty<()> as Iterator>::Item == ()`
44
// error-pattern: function cannot return without recursing
55
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"

0 commit comments

Comments
 (0)