Skip to content

Commit 7d4af88

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#105188 - compiler-errors:verbose-ty-err, r=TaKO8Ki
Don't elide type information when printing E0308 with `-Zverbose` When we pass `-Zverbose`, we kinda expect for all `_` to be replaced with more descriptive information, for example -- ``` = note: expected fn pointer `fn(_, u32)` found fn item `fn(_, i32) {foo}` ``` Where `_` is the "identical" part of the fn signatures, now gets rendered as: ``` = note: expected fn pointer `fn(i32, u32)` found fn item `fn(i32, i32) {foo}` ```
2 parents 9afa850 + 5c642d7 commit 7d4af88

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12551255
let num_display_types = consts_offset - regions_len;
12561256
for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() {
12571257
let i = i + regions_len;
1258-
if ta1 == ta2 {
1258+
if ta1 == ta2 && !self.tcx.sess.verbose() {
12591259
values.0.push_normal("_");
12601260
values.1.push_normal("_");
12611261
} else {
@@ -1271,7 +1271,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12711271
let const_arguments = sub1.consts().zip(sub2.consts());
12721272
for (i, (ca1, ca2)) in const_arguments.enumerate() {
12731273
let i = i + consts_offset;
1274-
if ca1 == ca2 {
1274+
if ca1 == ca2 && !self.tcx.sess.verbose() {
12751275
values.0.push_normal("_");
12761276
values.1.push_normal("_");
12771277
} else {
@@ -1450,7 +1450,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14501450
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
14511451

14521452
_ => {
1453-
if t1 == t2 {
1453+
if t1 == t2 && !self.tcx.sess.verbose() {
14541454
// The two types are the same, elide and don't highlight.
14551455
(DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_"))
14561456
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Zverbose
2+
3+
fn foo(_: i32, _: i32) {}
4+
5+
fn needs_ptr(_: fn(i32, u32)) {}
6+
//~^ NOTE function defined here
7+
//~| NOTE
8+
9+
fn main() {
10+
needs_ptr(foo);
11+
//~^ ERROR mismatched types
12+
//~| NOTE expected `u32`, found `i32`
13+
//~| NOTE expected fn pointer `fn(i32, u32)`
14+
//~| NOTE arguments to this function are incorrect
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/signature-error-reporting-under-verbose.rs:10:15
3+
|
4+
LL | needs_ptr(foo);
5+
| --------- ^^^ expected `u32`, found `i32`
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
= note: expected fn pointer `fn(i32, u32)`
10+
found fn item `fn(i32, i32) {foo}`
11+
note: function defined here
12+
--> $DIR/signature-error-reporting-under-verbose.rs:5:4
13+
|
14+
LL | fn needs_ptr(_: fn(i32, u32)) {}
15+
| ^^^^^^^^^ ---------------
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)