Further tweak the type shortening logic

This commit is contained in:
Esteban Küber
2022-11-25 19:08:46 -08:00
parent 360c0a7a3e
commit 73b371a16c
5 changed files with 13 additions and 12 deletions

View File

@@ -986,13 +986,14 @@ fn foo(&self) -> Self::T { String::new() }
} }
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) { pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
let length_limit = self.sess.diagnostic_width().saturating_sub(20); let width = self.sess.diagnostic_width();
let length_limit = width.saturating_sub(30);
let mut type_limit = 50; let mut type_limit = 50;
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS) let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.pretty_print_type(ty) .pretty_print_type(ty)
.expect("could not write to `String`") .expect("could not write to `String`")
.into_buffer(); .into_buffer();
if regular.len() <= length_limit { if regular.len() <= width {
return (regular, None); return (regular, None);
} }
let mut short; let mut short;

View File

@@ -18,7 +18,7 @@ LL | | ))))))))))))))))))))))))))))))
LL | | )))))))))))))))))))))))))))))); LL | | ))))))))))))))))))))))))))))));
| |___________________________________^ expected struct `Atype`, found enum `Result` | |___________________________________^ expected struct `Atype`, found enum `Result`
| |
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>` = note: expected struct `Atype<Btype<..., ...>, ...>`
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
found enum `Result<Result<..., ...>, ...>` found enum `Result<Result<..., ...>, ...>`
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' 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 | | ))))))))))))))))))))))))))))))
LL | | )))))))))))))))))))))))); LL | | ))))))))))))))))))))))));
| |____________________________^ expected enum `Option`, found enum `Result` | |____________________________^ expected enum `Option`, found enum `Result`
| |
= note: expected enum `Option<Result<Option<Option<...>>, ...>>` = note: expected enum `Option<Result<..., ...>>`
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
found enum `Result<Result<..., ...>, ...>` found enum `Result<Result<..., ...>, ...>`
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' 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 | | > = ();
| |_____| | |_____|
| expected due to this | expected due to this
| |
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>` = note: expected struct `Atype<Btype<..., ...>, ...>`
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt' the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
found unit type `()` found unit type `()`

View File

@@ -5,7 +5,7 @@ LL | impl<T> Foo for T where Bar<T>: Foo {}
| ^^^ | ^^^
| |
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`E0275`) = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`E0275`)
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` 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`
--> $DIR/E0275.rs:6:9 --> $DIR/E0275.rs:6:9
| |
LL | impl<T> Foo for T where Bar<T>: Foo {} LL | impl<T> Foo for T where Bar<T>: Foo {}

View File

@@ -14,7 +14,7 @@ LL | impl<T> Foo for T where NoData<T>: Foo {
| ^^^ | ^^^
| |
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>>>>>>>>` to implement `Foo` note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<...>>>>>>>>>>>>>` to implement `Foo`
--> $DIR/issue-20413.rs:9:9 --> $DIR/issue-20413.rs:9:9
| |
LL | impl<T> Foo for T where NoData<T>: Foo { LL | impl<T> Foo for T where NoData<T>: Foo {
@@ -30,13 +30,13 @@ LL | impl<T> Bar for T where EvenLessData<T>: Baz {
| ^^^ | ^^^
| |
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>>` to implement `Bar` note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
--> $DIR/issue-20413.rs:28:9 --> $DIR/issue-20413.rs:28:9
| |
LL | impl<T> Bar for T where EvenLessData<T>: Baz { LL | impl<T> Bar for T where EvenLessData<T>: Baz {
| ^^^ ^ | ^^^ ^
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>>` to implement `Baz` note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
--> $DIR/issue-20413.rs:35:9 --> $DIR/issue-20413.rs:35:9
| |
LL | impl<T> Baz for T where AlmostNoData<T>: Bar { LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
@@ -52,13 +52,13 @@ LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
| ^^^ | ^^^
| |
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`) = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_20413`)
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>>` to implement `Baz` note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
--> $DIR/issue-20413.rs:35:9 --> $DIR/issue-20413.rs:35:9
| |
LL | impl<T> Baz for T where AlmostNoData<T>: Bar { LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
| ^^^ ^ | ^^^ ^
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt' = note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>>` to implement `Bar` note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
--> $DIR/issue-20413.rs:28:9 --> $DIR/issue-20413.rs:28:9
| |
LL | impl<T> Bar for T where EvenLessData<T>: Baz { LL | impl<T> Bar for T where EvenLessData<T>: Baz {

View File

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