Rollup merge of #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 #135919.
This commit is contained in:
commit
8824ae6a6c
3 changed files with 43 additions and 9 deletions
|
@ -435,6 +435,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
||||||
terr: TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
param_env: Option<ParamEnv<'tcx>>,
|
param_env: Option<ParamEnv<'tcx>>,
|
||||||
|
path: &mut Option<PathBuf>,
|
||||||
) {
|
) {
|
||||||
match *cause.code() {
|
match *cause.code() {
|
||||||
ObligationCauseCode::Pattern {
|
ObligationCauseCode::Pattern {
|
||||||
|
@ -457,6 +458,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
format!("this is an iterator with items of type `{}`", args.type_at(0)),
|
format!("this is an iterator with items of type `{}`", args.type_at(0)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
let expected_ty = self.tcx.short_ty_string(expected_ty, path);
|
||||||
err.span_label(span, format!("this expression has type `{expected_ty}`"));
|
err.span_label(span, format!("this expression has type `{expected_ty}`"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1594,7 +1596,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((expected, found, path)) = expected_found {
|
let mut path = None;
|
||||||
|
if let Some((expected, found, p)) = expected_found {
|
||||||
|
path = p;
|
||||||
let (expected_label, found_label, exp_found) = match exp_found {
|
let (expected_label, found_label, exp_found) = match exp_found {
|
||||||
Mismatch::Variable(ef) => (
|
Mismatch::Variable(ef) => (
|
||||||
ef.expected.prefix_string(self.tcx),
|
ef.expected.prefix_string(self.tcx),
|
||||||
|
@ -1775,13 +1779,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
&sort_string(values.expected),
|
&sort_string(values.expected),
|
||||||
&sort_string(values.found),
|
&sort_string(values.found),
|
||||||
);
|
);
|
||||||
if let Some(path) = path {
|
|
||||||
diag.note(format!(
|
|
||||||
"the full type name has been written to '{}'",
|
|
||||||
path.display(),
|
|
||||||
));
|
|
||||||
diag.note("consider using `--verbose` to print the full type name to the console");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1877,7 +1874,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// It reads better to have the error origin as the final
|
// It reads better to have the error origin as the final
|
||||||
// thing.
|
// thing.
|
||||||
self.note_error_origin(diag, cause, exp_found, terr, param_env);
|
self.note_error_origin(diag, cause, exp_found, terr, param_env, &mut path);
|
||||||
|
if let Some(path) = path {
|
||||||
|
diag.note(format!("the full type name has been written to '{}'", path.display()));
|
||||||
|
diag.note("consider using `--verbose` to print the full type name to the console");
|
||||||
|
}
|
||||||
|
|
||||||
debug!(?diag);
|
debug!(?diag);
|
||||||
}
|
}
|
||||||
|
|
17
tests/ui/diagnostic-width/secondary-label-with-long-type.rs
Normal file
17
tests/ui/diagnostic-width/secondary-label-with-long-type.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//@ compile-flags: --diagnostic-width=100 -Zwrite-long-types-to-disk=yes
|
||||||
|
//@ normalize-stderr: "long-type-\d+" -> "long-type-hash"
|
||||||
|
type A = (i32, i32, i32, i32);
|
||||||
|
type B = (A, A, A, A);
|
||||||
|
type C = (B, B, B, B);
|
||||||
|
type D = (C, C, C, C);
|
||||||
|
|
||||||
|
fn foo(x: D) {
|
||||||
|
let () = x; //~ ERROR mismatched types
|
||||||
|
//~^ NOTE this expression has type `((...,
|
||||||
|
//~| NOTE expected `((...,
|
||||||
|
//~| NOTE expected tuple
|
||||||
|
//~| NOTE the full type name has been written to
|
||||||
|
//~| NOTE consider using `--verbose` to print the full type name to the console
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,16 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/secondary-label-with-long-type.rs:9: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-hash.txt'
|
||||||
|
= note: consider using `--verbose` to print the full type name to the console
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue