Skip to content

Commit 360c0a7

Browse files
committed
Tweak shortening logic to be less trigger happy
1 parent 7674ede commit 360c0a7

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25032503
Some(match (exp_found.expected.unpack(), exp_found.found.unpack()) {
25042504
(ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => {
25052505
let (mut exp, mut fnd) = self.cmp(expected, found);
2506-
let len = self.tcx.sess().diagnostic_width().saturating_sub(20);
2506+
// Use the terminal width as the basis to determine when to compress the printed
2507+
// out type, but give ourselves some leeway to avoid ending up creating a file for
2508+
// a type that is somewhat shorter than the path we'd write to.
2509+
let len = self.tcx.sess().diagnostic_width() + 40;
25072510
let exp_s = exp.content();
25082511
let fnd_s = fnd.content();
25092512
let mut exp_p = None;

src/test/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=100
1+
// compile-flags: --diagnostic-width=60
22
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
33

44
struct Atype<T, K>(T, K);

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ LL | | Ctype<
88
LL | | Atype<
99
... |
1010
LL | | i32
11-
LL | | > = Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(...
11+
LL | | > = Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok...
1212
| |_____-___^
1313
| ||_____|
1414
| | expected due to this
15-
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(...
15+
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok...
1616
LL | | Ok("")
1717
LL | | ))))))))))))))))))))))))))))))
1818
LL | | ))))))))))))))))))))))))))))));
1919
| |___________________________________^ expected struct `Atype`, found enum `Result`
2020
|
21-
= note: expected struct `Atype<Btype<Ctype<Atype<Btype<Ctype<..., ...>, ...>, ...>, ...>, ...>, ...>`
21+
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>`
2222
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
23-
found enum `Result<Result<Result<Result<Result<..., ...>, ...>, ...>, ...>, ...>`
23+
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'
2525

2626
error[E0308]: mismatched types
2727
--> $DIR/long-E0308.rs:46:26
2828
|
29-
LL | ))))))))))))))))) == Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok...
29+
LL | ))))))))))))))))) == Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(O...
3030
| __________________________^
31-
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(O...
31+
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(...
3232
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok("")))))))
3333
LL | | ))))))))))))))))))))))))))))))
3434
LL | | ))))))))))))))))))))))));
3535
| |____________________________^ expected enum `Option`, found enum `Result`
3636
|
37-
= note: expected enum `Option<Result<Option<Option<Option<Option<Option<Option<Option<...>>>>>>>, ...>>`
37+
= note: expected enum `Option<Result<Option<Option<...>>, ...>>`
3838
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
39-
found enum `Result<Result<Result<Result<Result<..., ...>, ...>, ...>, ...>, ...>`
39+
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'
4141

4242
error[E0308]: mismatched types
@@ -54,25 +54,25 @@ LL | | > = ();
5454
| |_____|
5555
| expected due to this
5656
|
57-
= note: expected struct `Atype<Btype<Ctype<Atype<Btype<Ctype<..., ...>, ...>, ...>, ...>, ...>, ...>`
57+
= note: expected struct `Atype<Btype<Ctype<..., ...>, ...>, ...>`
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

6161
error[E0308]: mismatched types
6262
--> $DIR/long-E0308.rs:80:17
6363
|
64-
LL | let _: () = Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(
64+
LL | let _: () = Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(O...
6565
| ____________--___^
6666
| | |
6767
| | expected due to this
68-
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(O...
68+
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(Ok(...
6969
LL | | Ok(Ok(Ok(Ok(Ok(Ok(Ok("")))))))
7070
LL | | ))))))))))))))))))))))))))))))
7171
LL | | ))))))))))))))))))))))));
7272
| |____________________________^ expected `()`, found enum `Result`
7373
|
7474
= note: expected unit type `()`
75-
found enum `Result<Result<Result<Result<Result<..., ...>, ...>, ...>, ...>, ...>`
75+
found enum `Result<Result<..., ...>, ...>`
7676
the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/long-E0308/long-E0308.long-type-hash.txt'
7777

7878
error: aborting due to 4 previous errors

src/test/ui/typeck/return_type_containing_closure.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ LL | vec!['a'].iter().map(|c| c)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map`
66
|
77
= note: expected unit type `()`
8-
found struct `Map<std::slice::Iter<'_, char>, ...>`
9-
the full type name has been written to '$TEST_BUILD_DIR/typeck/return_type_containing_closure/return_type_containing_closure.long-type-hash.txt'
8+
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:4:26: 4:29]>`
109
help: consider using a semicolon here
1110
|
1211
LL | vec!['a'].iter().map(|c| c);

0 commit comments

Comments
 (0)