Skip to content

Commit 73b371a

Browse files
committed
Further tweak the type shortening logic
1 parent 360c0a7 commit 73b371a

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

compiler/rustc_middle/src/ty/error.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,14 @@ fn foo(&self) -> Self::T { String::new() }
986986
}
987987

988988
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
989-
let length_limit = self.sess.diagnostic_width().saturating_sub(20);
989+
let width = self.sess.diagnostic_width();
990+
let length_limit = width.saturating_sub(30);
990991
let mut type_limit = 50;
991992
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
992993
.pretty_print_type(ty)
993994
.expect("could not write to `String`")
994995
.into_buffer();
995-
if regular.len() <= length_limit {
996+
if regular.len() <= width {
996997
return (regular, None);
997998
}
998999
let mut short;

src/test/ui/diagnostic-width/long-E0308.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | | ))))))))))))))))))))))))))))))
1818
LL | | ))))))))))))))))))))))))))))));
1919
| |___________________________________^ expected struct `Atype`, found enum `Result`
2020
|
21-
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>`
21+
= note: expected struct `Atype<Btype<..., ...>, ...>`
2222
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
2323
found enum `Result<Result<..., ...>, ...>`
2424
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
@@ -34,7 +34,7 @@ LL | | ))))))))))))))))))))))))))))))
3434
LL | | ))))))))))))))))))))))));
3535
| |____________________________^ expected enum `Option`, found enum `Result`
3636
|
37-
= note: expected enum `Option<Result<Option<Option<...>>, ...>>`
37+
= note: expected enum `Option<Result<..., ...>>`
3838
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
3939
found enum `Result<Result<..., ...>, ...>`
4040
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
@@ -54,7 +54,7 @@ LL | | > = ();
5454
| |_____|
5555
| expected due to this
5656
|
57-
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>`
57+
= note: expected struct `Atype<Btype<..., ...>, ...>`
5858
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
5959
found unit type `()`
6060

src/test/ui/error-codes/E0275.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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`)
8-
note: required for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<...>>>>>>>>>>>>>>>>>>>>>>>` to implement `Foo`
8+
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`
99
--> $DIR/E0275.rs:6:9
1010
|
1111
LL | impl<T> Foo for T where Bar<T>: Foo {}

src/test/ui/issues/issue-20413.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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`)
17-
note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>>>>>>>>` to implement `Foo`
17+
note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>>>>>>>` to implement `Foo`
1818
--> $DIR/issue-20413.rs:9:9
1919
|
2020
LL | impl<T> Foo for T where NoData<T>: Foo {
@@ -30,13 +30,13 @@ 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`)
33-
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>>` to implement `Bar`
33+
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
3434
--> $DIR/issue-20413.rs:28:9
3535
|
3636
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
3737
| ^^^ ^
3838
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
39-
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>>` to implement `Baz`
39+
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
4040
--> $DIR/issue-20413.rs:35:9
4141
|
4242
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
@@ -52,13 +52,13 @@ 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`)
55-
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>>` to implement `Baz`
55+
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
5656
--> $DIR/issue-20413.rs:35:9
5757
|
5858
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
5959
| ^^^ ^
6060
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
61-
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>>` to implement `Bar`
61+
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
6262
--> $DIR/issue-20413.rs:28:9
6363
|
6464
LL | impl<T> Bar for T where EvenLessData<T>: Baz {

src/test/ui/recursion/issue-83150.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | func(&mut iter.map(|x| x + 1))
1212
error[E0275]: overflow evaluating the requirement `Map<&mut Map<&mut Map<&mut Map<..., ...>, ...>, ...>, ...>: Iterator`
1313
|
1414
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_83150`)
15-
= note: required for `&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut ..., ...>, ...>, ...>, ...>, ...>, ...>, ...>` to implement `Iterator`
15+
= note: required for `&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<..., ...>, ...>, ...>, ...>, ...>, ...>, ...>` to implement `Iterator`
1616
= note: the full type name has been written to '$TEST_BUILD_DIR/recursion/issue-83150/issue-83150.long-type-hash.txt'
1717

1818
error: aborting due to previous error; 1 warning emitted

0 commit comments

Comments
 (0)