Skip to content

Commit 038a166

Browse files
committed
Properly display note/expected details
1 parent c49d102 commit 038a166

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

Diff for: src/librustc/infer/error_reporting.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -562,40 +562,41 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
562562
values: Option<ValuePairs<'tcx>>,
563563
terr: &TypeError<'tcx>)
564564
{
565-
let expected_found = match values {
566-
None => None,
567-
Some(values) => match self.values_str(&values) {
568-
Some((expected, found)) => Some((expected, found)),
569-
None => {
570-
// Derived error. Cancel the emitter.
571-
self.tcx.sess.diagnostic().cancel(diag);
572-
return
573-
}
565+
let (expected_found, is_simple_error) = match values {
566+
None => (None, false),
567+
Some(values) => {
568+
let is_simple_error = match values {
569+
ValuePairs::Types(exp_found) => {
570+
exp_found.expected.is_primitive() && exp_found.found.is_primitive()
571+
}
572+
_ => false,
573+
};
574+
let vals = match self.values_str(&values) {
575+
Some((expected, found)) => Some((expected, found)),
576+
None => {
577+
// Derived error. Cancel the emitter.
578+
self.tcx.sess.diagnostic().cancel(diag);
579+
return
580+
}
581+
};
582+
(vals, is_simple_error)
574583
}
575584
};
576585

577586
let span = cause.span;
578587

579588
if let Some((expected, found)) = expected_found {
580-
let is_simple_error = if let &TypeError::Sorts(ref values) = terr {
581-
values.expected.is_primitive() && values.found.is_primitive()
582-
} else {
583-
false
584-
};
585-
586-
if !is_simple_error {
587-
if expected == found {
588-
if let &TypeError::Sorts(ref values) = terr {
589-
diag.note_expected_found_extra(
590-
&"type", &expected, &found,
591-
&format!(" ({})", values.expected.sort_string(self.tcx)),
592-
&format!(" ({})", values.found.sort_string(self.tcx)));
593-
} else {
594-
diag.note_expected_found(&"type", &expected, &found);
595-
}
596-
} else {
589+
match (terr, is_simple_error, expected == found) {
590+
(&TypeError::Sorts(ref values), false, true) => {
591+
diag.note_expected_found_extra(
592+
&"type", &expected, &found,
593+
&format!(" ({})", values.expected.sort_string(self.tcx)),
594+
&format!(" ({})", values.found.sort_string(self.tcx)));
595+
}
596+
(_, false, _) => {
597597
diag.note_expected_found(&"type", &expected, &found);
598598
}
599+
_ => (),
599600
}
600601
}
601602

Diff for: src/test/compile-fail/default_ty_param_conflict.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ fn main() {
2323
// Here, F is instantiated with $0=uint
2424
let x = foo();
2525
//~^ ERROR: mismatched types
26-
//~| expected type `usize`
27-
//~| found type `isize`
2826
//~| NOTE: conflicting type parameter defaults `usize` and `isize`
2927
//~| NOTE: conflicting type parameter defaults `usize` and `isize`
3028
//~| NOTE: ...that was applied to an unconstrained type variable here

Diff for: src/test/compile-fail/default_ty_param_conflict_cross_crate.rs

-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ fn main() {
2929
//~| NOTE: conflicting type parameter defaults `bool` and `char`
3030
//~| a second default is defined on `default_param_test::bleh`
3131
//~| NOTE: ...that was applied to an unconstrained type variable here
32-
//~| expected type `bool`
33-
//~| found type `char`
3432
}

Diff for: src/test/compile-fail/issue-35869.rs

+4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ impl Foo for Bar {
2323
fn foo(_: fn(u16) -> ()) {}
2424
//~^ ERROR method `foo` has an incompatible type for trait
2525
//~| NOTE expected u8
26+
//~| NOTE expected type `fn(fn(u8))`
2627
fn bar(_: Option<u16>) {}
2728
//~^ ERROR method `bar` has an incompatible type for trait
2829
//~| NOTE expected u8
30+
//~| NOTE expected type `fn(std::option::Option<u8>)`
2931
fn baz(_: (u16, u16)) {}
3032
//~^ ERROR method `baz` has an incompatible type for trait
3133
//~| NOTE expected u8
34+
//~| NOTE expected type `fn((u8, u16))`
3235
fn qux() -> u16 { 5u16 }
3336
//~^ ERROR method `qux` has an incompatible type for trait
3437
//~| NOTE expected u8
38+
//~| NOTE expected type `fn() -> u8`
3539
}
3640

3741
fn main() {}

Diff for: src/test/ui/mismatched_types/E0053.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ error[E0053]: method `foo` has an incompatible type for trait
66
...
77
19 | fn foo(x: i16) { }
88
| ^^^ expected u16, found i16
9+
|
10+
= note: expected type `fn(u16)`
11+
found type `fn(i16)`
912

1013
error[E0053]: method `bar` has an incompatible type for trait
1114
--> $DIR/E0053.rs:22:12

Diff for: src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ error[E0053]: method `foo` has an incompatible type for trait
66
...
77
21 | fn foo(x: i16) { }
88
| ^^^ expected u16, found i16
9+
|
10+
= note: expected type `fn(u16)`
11+
found type `fn(i16)`
912

1013
error[E0053]: method `bar` has an incompatible type for trait
1114
--> $DIR/trait-impl-fn-incompatibility.rs:22:28

0 commit comments

Comments
 (0)