Skip to content

Commit 01a4d8f

Browse files
authored
Unrolled build for rust-lang#135949
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 1e9b017 + 32cf7cc commit 01a4d8f

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
}
@@ -1611,7 +1613,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16111613
return;
16121614
}
16131615

1614-
if let Some((expected, found, path)) = expected_found {
1616+
let mut path = None;
1617+
if let Some((expected, found, p)) = expected_found {
1618+
path = p;
16151619
let (expected_label, found_label, exp_found) = match exp_found {
16161620
Mismatch::Variable(ef) => (
16171621
ef.expected.prefix_string(self.tcx),
@@ -1792,13 +1796,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17921796
&sort_string(values.expected),
17931797
&sort_string(values.found),
17941798
);
1795-
if let Some(path) = path {
1796-
diag.note(format!(
1797-
"the full type name has been written to '{}'",
1798-
path.display(),
1799-
));
1800-
diag.note("consider using `--verbose` to print the full type name to the console");
1801-
}
18021799
}
18031800
}
18041801
}
@@ -1894,7 +1891,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18941891

18951892
// It reads better to have the error origin as the final
18961893
// thing.
1897-
self.note_error_origin(diag, cause, exp_found, terr, param_env);
1894+
self.note_error_origin(diag, cause, exp_found, terr, param_env, &mut path);
1895+
if let Some(path) = path {
1896+
diag.note(format!("the full type name has been written to '{}'", path.display()));
1897+
diag.note("consider using `--verbose` to print the full type name to the console");
1898+
}
18981899

18991900
debug!(?diag);
19001901
}
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)