Fix const arguments not displaying in types mismatch diagnostic.

This commit is contained in:
ben 2019-10-06 19:56:05 +13:00
parent 7870050796
commit 5880ce3968
2 changed files with 24 additions and 7 deletions

View file

@ -935,6 +935,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.filter(|(a, b)| a == b)
.count();
let len = sub1.len() - common_default_params;
let consts_offset = len - sub1.consts().count();
// Only draw `<...>` if there're lifetime/type arguments.
if len > 0 {
@ -981,7 +982,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// ^ elided type as this type argument was the same in both sides
let type_arguments = sub1.types().zip(sub2.types());
let regions_len = sub1.regions().count();
for (i, (ta1, ta2)) in type_arguments.take(len).enumerate() {
let num_display_types = consts_offset - regions_len;
for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() {
let i = i + regions_len;
if ta1 == ta2 {
values.0.push_normal("_");
@ -994,6 +996,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.push_comma(&mut values.0, &mut values.1, len, i);
}
// Do the same for const arguments, if they are equal, do not highlight and
// elide them from the output.
let const_arguments = sub1.consts().zip(sub2.consts());
for (i, (ca1, ca2)) in const_arguments.enumerate() {
let i = i + consts_offset;
if ca1 == ca2 {
values.0.push_normal("_");
values.1.push_normal("_");
} else {
values.0.push_highlighted(ca1.to_string());
values.1.push_highlighted(ca2.to_string());
}
self.push_comma(&mut values.0, &mut values.1, len, i);
}
// Close the type argument bracket.
// Only draw `<...>` if there're lifetime/type arguments.
if len > 0 {

View file

@ -12,8 +12,8 @@ error[E0308]: mismatched types
LL | let _: ConstString<"Hello"> = ConstString::<"World">;
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"`
|
= note: expected type `ConstString<>`
found type `ConstString<>`
= note: expected type `ConstString<"Hello">`
found type `ConstString<"World">`
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:11:33
@ -21,8 +21,8 @@ error[E0308]: mismatched types
LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">;
| ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"`
|
= note: expected type `ConstString<>`
found type `ConstString<>`
= note: expected type `ConstString<"ℇ㇈↦">`
found type `ConstString<"ℇ㇈↥">`
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:13:33
@ -30,8 +30,8 @@ error[E0308]: mismatched types
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"`
|
= note: expected type `ConstBytes<>`
found type `ConstBytes<>`
= note: expected type `ConstBytes<b"AAA">`
found type `ConstBytes<b"BBB">`
error: aborting due to 3 previous errors