Skip to content

Commit 8824ae6

Browse files
authored
Rollup merge of rust-lang#135949 - estebank:shorten-ty, r=davidtwco
Use short type string in E0308 secondary span label We were previously printing the full type on the "this expression has type" label. ``` error[E0308]: mismatched types --> $DIR/secondary-label-with-long-type.rs:8:9 | LL | let () = x; | ^^ - this expression has type `((..., ..., ..., ...), ..., ..., ...)` | | | expected `((..., ..., ..., ...), ..., ..., ...)`, found `()` | = note: expected tuple `((..., ..., ..., ...), ..., ..., ...)` found unit type `()` = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-3987761834644699448.txt' = note: consider using `--verbose` to print the full type name to the console ``` Reported in a comment of rust-lang#135919.
2 parents 884ec6b + 32cf7cc commit 8824ae6

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
435435
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
436436
terr: TypeError<'tcx>,
437437
param_env: Option<ParamEnv<'tcx>>,
438+
path: &mut Option<PathBuf>,
438439
) {
439440
match *cause.code() {
440441
ObligationCauseCode::Pattern {
@@ -457,6 +458,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
457458
format!("this is an iterator with items of type `{}`", args.type_at(0)),
458459
);
459460
} else {
461+
let expected_ty = self.tcx.short_ty_string(expected_ty, path);
460462
err.span_label(span, format!("this expression has type `{expected_ty}`"));
461463
}
462464
}
@@ -1594,7 +1596,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15941596
return;
15951597
}
15961598

1597-
if let Some((expected, found, path)) = expected_found {
1599+
let mut path = None;
1600+
if let Some((expected, found, p)) = expected_found {
1601+
path = p;
15981602
let (expected_label, found_label, exp_found) = match exp_found {
15991603
Mismatch::Variable(ef) => (
16001604
ef.expected.prefix_string(self.tcx),
@@ -1775,13 +1779,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17751779
&sort_string(values.expected),
17761780
&sort_string(values.found),
17771781
);
1778-
if let Some(path) = path {
1779-
diag.note(format!(
1780-
"the full type name has been written to '{}'",
1781-
path.display(),
1782-
));
1783-
diag.note("consider using `--verbose` to print the full type name to the console");
1784-
}
17851782
}
17861783
}
17871784
}
@@ -1877,7 +1874,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18771874

18781875
// It reads better to have the error origin as the final
18791876
// thing.
1880-
self.note_error_origin(diag, cause, exp_found, terr, param_env);
1877+
self.note_error_origin(diag, cause, exp_found, terr, param_env, &mut path);
1878+
if let Some(path) = path {
1879+
diag.note(format!("the full type name has been written to '{}'", path.display()));
1880+
diag.note("consider using `--verbose` to print the full type name to the console");
1881+
}
18811882

18821883
debug!(?diag);
18831884
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: --diagnostic-width=100 -Zwrite-long-types-to-disk=yes
2+
//@ normalize-stderr: "long-type-\d+" -> "long-type-hash"
3+
type A = (i32, i32, i32, i32);
4+
type B = (A, A, A, A);
5+
type C = (B, B, B, B);
6+
type D = (C, C, C, C);
7+
8+
fn foo(x: D) {
9+
let () = x; //~ ERROR mismatched types
10+
//~^ NOTE this expression has type `((...,
11+
//~| NOTE expected `((...,
12+
//~| NOTE expected tuple
13+
//~| NOTE the full type name has been written to
14+
//~| NOTE consider using `--verbose` to print the full type name to the console
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/secondary-label-with-long-type.rs:9:9
3+
|
4+
LL | let () = x;
5+
| ^^ - this expression has type `((..., ..., ..., ...), ..., ..., ...)`
6+
| |
7+
| expected `((..., ..., ..., ...), ..., ..., ...)`, found `()`
8+
|
9+
= note: expected tuple `((..., ..., ..., ...), ..., ..., ...)`
10+
found unit type `()`
11+
= note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-hash.txt'
12+
= note: consider using `--verbose` to print the full type name to the console
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)