diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index f390d85a28d..5cc848d2ca3 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -486,13 +486,24 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { } }; + let is_simple_error = if let &TypeError::Sorts(ref values) = terr { + values.expected.is_primitive() && values.found.is_primitive() + } else { + false + }; + + let expected_found_str = if is_simple_error { + expected_found_str + } else { + format!("{} ({})", expected_found_str, terr) + }; + let mut err = struct_span_err!(self.tcx.sess, trace.origin.span(), E0308, - "{}: {} ({})", + "{}: {}", trace.origin, - expected_found_str, - terr); + expected_found_str); self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span()); diff --git a/src/librustc/middle/ty/sty.rs b/src/librustc/middle/ty/sty.rs index 7e8d38ae8e7..6d40d377b78 100644 --- a/src/librustc/middle/ty/sty.rs +++ b/src/librustc/middle/ty/sty.rs @@ -910,6 +910,13 @@ impl<'tcx> TyS<'tcx> { } } + pub fn is_primitive(&self) -> bool { + match self.sty { + TyBool | TyChar | TyInt(_) | TyUint(_) | TyFloat(_) => true, + _ => false, + } + } + pub fn is_ty_var(&self) -> bool { match self.sty { TyInfer(TyVar(_)) => true, diff --git a/src/test/compile-fail/if-branch-types.rs b/src/test/compile-fail/if-branch-types.rs index b7a5b991c6d..2c730531b82 100644 --- a/src/test/compile-fail/if-branch-types.rs +++ b/src/test/compile-fail/if-branch-types.rs @@ -13,6 +13,4 @@ fn main() { //~^ ERROR if and else have incompatible types //~| expected `i32` //~| found `u32` - //~| expected i32 - //~| found u32 } diff --git a/src/test/compile-fail/integer-literal-suffix-inference.rs b/src/test/compile-fail/integer-literal-suffix-inference.rs index 5d9314faef9..8f04b58b778 100644 --- a/src/test/compile-fail/integer-literal-suffix-inference.rs +++ b/src/test/compile-fail/integer-literal-suffix-inference.rs @@ -43,79 +43,55 @@ fn main() { //~^ ERROR mismatched types //~| expected `i8` //~| found `i16` - //~| expected i8 - //~| found i16 id_i8(a32); //~^ ERROR mismatched types //~| expected `i8` //~| found `i32` - //~| expected i8 - //~| found i32 id_i8(a64); //~^ ERROR mismatched types //~| expected `i8` //~| found `i64` - //~| expected i8 - //~| found i64 id_i16(a8); //~^ ERROR mismatched types //~| expected `i16` //~| found `i8` - //~| expected i16 - //~| found i8 id_i16(a16); // ok id_i16(a32); //~^ ERROR mismatched types //~| expected `i16` //~| found `i32` - //~| expected i16 - //~| found i32 id_i16(a64); //~^ ERROR mismatched types //~| expected `i16` //~| found `i64` - //~| expected i16 - //~| found i64 id_i32(a8); //~^ ERROR mismatched types //~| expected `i32` //~| found `i8` - //~| expected i32 - //~| found i8 id_i32(a16); //~^ ERROR mismatched types //~| expected `i32` //~| found `i16` - //~| expected i32 - //~| found i16 id_i32(a32); // ok id_i32(a64); //~^ ERROR mismatched types //~| expected `i32` //~| found `i64` - //~| expected i32 - //~| found i64 id_i64(a8); //~^ ERROR mismatched types //~| expected `i64` //~| found `i8` - //~| expected i64 - //~| found i8 id_i64(a16); //~^ ERROR mismatched types //~| expected `i64` //~| found `i16` - //~| expected i64 - //~| found i16 id_i64(a32); //~^ ERROR mismatched types //~| expected `i64` //~| found `i32` - //~| expected i64 - //~| found i32 id_i64(a64); // ok id_i8(c8); // ok @@ -123,79 +99,55 @@ fn main() { //~^ ERROR mismatched types //~| expected `i8` //~| found `i16` - //~| expected i8 - //~| found i16 id_i8(c32); //~^ ERROR mismatched types //~| expected `i8` //~| found `i32` - //~| expected i8 - //~| found i32 id_i8(c64); //~^ ERROR mismatched types //~| expected `i8` //~| found `i64` - //~| expected i8 - //~| found i64 id_i16(c8); //~^ ERROR mismatched types //~| expected `i16` //~| found `i8` - //~| expected i16 - //~| found i8 id_i16(c16); // ok id_i16(c32); //~^ ERROR mismatched types //~| expected `i16` //~| found `i32` - //~| expected i16 - //~| found i32 id_i16(c64); //~^ ERROR mismatched types //~| expected `i16` //~| found `i64` - //~| expected i16 - //~| found i64 id_i32(c8); //~^ ERROR mismatched types //~| expected `i32` //~| found `i8` - //~| expected i32 - //~| found i8 id_i32(c16); //~^ ERROR mismatched types //~| expected `i32` //~| found `i16` - //~| expected i32 - //~| found i16 id_i32(c32); // ok id_i32(c64); //~^ ERROR mismatched types //~| expected `i32` //~| found `i64` - //~| expected i32 - //~| found i64 id_i64(a8); //~^ ERROR mismatched types //~| expected `i64` //~| found `i8` - //~| expected i64 - //~| found i8 id_i64(a16); //~^ ERROR mismatched types //~| expected `i64` - //~| found `i16` - //~| expected i64 //~| found i16 id_i64(a32); //~^ ERROR mismatched types //~| expected `i64` //~| found `i32` - //~| expected i64 - //~| found i32 id_i64(a64); // ok id_u8(b8); // ok @@ -203,78 +155,54 @@ fn main() { //~^ ERROR mismatched types //~| expected `u8` //~| found `u16` - //~| expected u8 - //~| found u16 id_u8(b32); //~^ ERROR mismatched types //~| expected `u8` //~| found `u32` - //~| expected u8 - //~| found u32 id_u8(b64); //~^ ERROR mismatched types //~| expected `u8` //~| found `u64` - //~| expected u8 - //~| found u64 id_u16(b8); //~^ ERROR mismatched types //~| expected `u16` //~| found `u8` - //~| expected u16 - //~| found u8 id_u16(b16); // ok id_u16(b32); //~^ ERROR mismatched types //~| expected `u16` //~| found `u32` - //~| expected u16 - //~| found u32 id_u16(b64); //~^ ERROR mismatched types //~| expected `u16` //~| found `u64` - //~| expected u16 - //~| found u64 id_u32(b8); //~^ ERROR mismatched types //~| expected `u32` //~| found `u8` - //~| expected u32 - //~| found u8 id_u32(b16); //~^ ERROR mismatched types //~| expected `u32` //~| found `u16` - //~| expected u32 - //~| found u16 id_u32(b32); // ok id_u32(b64); //~^ ERROR mismatched types //~| expected `u32` //~| found `u64` - //~| expected u32 - //~| found u64 id_u64(b8); //~^ ERROR mismatched types //~| expected `u64` //~| found `u8` - //~| expected u64 - //~| found u8 id_u64(b16); //~^ ERROR mismatched types //~| expected `u64` //~| found `u16` - //~| expected u64 - //~| found u16 id_u64(b32); //~^ ERROR mismatched types //~| expected `u64` //~| found `u32` - //~| expected u64 - //~| found u32 id_u64(b64); // ok } diff --git a/src/test/compile-fail/issue-13359.rs b/src/test/compile-fail/issue-13359.rs index c53e5760941..775412a12ca 100644 --- a/src/test/compile-fail/issue-13359.rs +++ b/src/test/compile-fail/issue-13359.rs @@ -17,13 +17,9 @@ fn main() { //~^ ERROR mismatched types //~| expected `i16` //~| found `isize` - //~| expected i16 - //~| found isize bar(1*(1 as usize)); //~^ ERROR mismatched types //~| expected `u32` //~| found `usize` - //~| expected u32 - //~| found usize } diff --git a/src/test/compile-fail/issue-3477.rs b/src/test/compile-fail/issue-3477.rs index 5e7c23164cb..43ef1b59ccf 100644 --- a/src/test/compile-fail/issue-3477.rs +++ b/src/test/compile-fail/issue-3477.rs @@ -13,6 +13,4 @@ fn main() { //~^ ERROR mismatched types //~| expected `char` //~| found `u8` - //~| expected char - //~| found u8 } diff --git a/src/test/compile-fail/issue-5100.rs b/src/test/compile-fail/issue-5100.rs index 35096110e8f..304b6f185fe 100644 --- a/src/test/compile-fail/issue-5100.rs +++ b/src/test/compile-fail/issue-5100.rs @@ -71,6 +71,4 @@ fn main() { let x: char = true; //~ ERROR mismatched types //~| expected `char` //~| found `bool` - //~| expected char - //~| found bool } diff --git a/src/test/compile-fail/issue-8761.rs b/src/test/compile-fail/issue-8761.rs index 30e4ec8ad0e..35be01970cb 100644 --- a/src/test/compile-fail/issue-8761.rs +++ b/src/test/compile-fail/issue-8761.rs @@ -13,14 +13,10 @@ enum Foo { //~^ ERROR mismatched types //~| expected `isize` //~| found `i64` - //~| expected isize - //~| found i64 B = 2u8 //~^ ERROR mismatched types //~| expected `isize` //~| found `u8` - //~| expected isize - //~| found u8 } fn main() {} diff --git a/src/test/compile-fail/pattern-error-continue.rs b/src/test/compile-fail/pattern-error-continue.rs index aa7202574ab..9ebdcf1a9ec 100644 --- a/src/test/compile-fail/pattern-error-continue.rs +++ b/src/test/compile-fail/pattern-error-continue.rs @@ -42,6 +42,4 @@ fn main() { //~^ ERROR mismatched types //~| expected `char` //~| found `bool` - //~| expected char - //~| found bool } diff --git a/src/test/compile-fail/pptypedef.rs b/src/test/compile-fail/pptypedef.rs index ccf82e90b7a..1a1c87ff47d 100644 --- a/src/test/compile-fail/pptypedef.rs +++ b/src/test/compile-fail/pptypedef.rs @@ -15,13 +15,9 @@ fn main() { //~^ ERROR mismatched types //~| expected `u32` //~| found `i32` - //~| expected u32 - //~| found i32 let_in(3i32, |i| { assert!(i == 3u32); }); //~^ ERROR mismatched types //~| expected `i32` //~| found `u32` - //~| expected i32 - //~| found u32 } diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index 7a0623ba44f..9aa61418d6d 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -25,8 +25,6 @@ fn main() { //~^ ERROR mismatched types //~| expected `usize` //~| found `bool` - //~| expected usize - //~| found bool) [E0308] //~| ERROR expected positive integer for repeat count, found boolean [E0306] let d = [0; 0.5]; //~^ ERROR mismatched types @@ -46,15 +44,11 @@ fn main() { //~^ ERROR mismatched types //~| expected `usize` //~| found `isize` - //~| expected usize - //~| found isize) [E0308] //~| ERROR expected positive integer for repeat count, found negative integer [E0306] let f = [0_usize; -1_isize]; //~^ ERROR mismatched types //~| expected `usize` //~| found `isize` - //~| expected usize - //~| found isize) [E0308] //~| ERROR expected positive integer for repeat count, found negative integer [E0306] struct G { g: (), diff --git a/src/test/compile-fail/shift-various-bad-types.rs b/src/test/compile-fail/shift-various-bad-types.rs index c980572fa15..560af9193b3 100644 --- a/src/test/compile-fail/shift-various-bad-types.rs +++ b/src/test/compile-fail/shift-various-bad-types.rs @@ -36,8 +36,6 @@ fn foo(p: &Panolpy) { //~^ ERROR mismatched types //~| expected `i32` //~| found `i64` - //~| expected i32 - //~| found i64) } fn main() { diff --git a/src/test/compile-fail/tutorial-suffix-inference-test.rs b/src/test/compile-fail/tutorial-suffix-inference-test.rs index bb1e199920d..99d6437c02e 100644 --- a/src/test/compile-fail/tutorial-suffix-inference-test.rs +++ b/src/test/compile-fail/tutorial-suffix-inference-test.rs @@ -20,14 +20,10 @@ fn main() { //~^ ERROR mismatched types //~| expected `u16` //~| found `u8` - //~| expected u16 - //~| found u8 identity_u16(y); //~^ ERROR mismatched types //~| expected `u16` //~| found `i32` - //~| expected u16 - //~| found i32 let a = 3; @@ -38,7 +34,4 @@ fn main() { //~^ ERROR mismatched types //~| expected `u16` //~| found `isize` - //~| expected u16 - //~| found isize - } diff --git a/src/test/compile-fail/type-mismatch-multiple.rs b/src/test/compile-fail/type-mismatch-multiple.rs index 627300a0377..dd8f54cdabb 100644 --- a/src/test/compile-fail/type-mismatch-multiple.rs +++ b/src/test/compile-fail/type-mismatch-multiple.rs @@ -19,5 +19,4 @@ fn main() { let a: bool = 1; let b: i32 = true; } //~| ERROR mismatched types //~| expected `i32` //~| found `bool` -//~| expected i32 -//~| found bool +