Auto merge of #30953 - KalitaAlexey:17823-get-rid-of-duplicate-error, r=nrc

This commit is contained in:
bors 2016-01-18 06:29:59 +00:00
commit 9d21acaf9b
14 changed files with 22 additions and 112 deletions

View File

@ -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());

View File

@ -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,

View File

@ -13,6 +13,4 @@ fn main() {
//~^ ERROR if and else have incompatible types
//~| expected `i32`
//~| found `u32`
//~| expected i32
//~| found u32
}

View File

@ -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
}

View File

@ -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
}

View File

@ -13,6 +13,4 @@ fn main() {
//~^ ERROR mismatched types
//~| expected `char`
//~| found `u8`
//~| expected char
//~| found u8
}

View File

@ -71,6 +71,4 @@ fn main() {
let x: char = true; //~ ERROR mismatched types
//~| expected `char`
//~| found `bool`
//~| expected char
//~| found bool
}

View File

@ -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() {}

View File

@ -42,6 +42,4 @@ fn main() {
//~^ ERROR mismatched types
//~| expected `char`
//~| found `bool`
//~| expected char
//~| found bool
}

View File

@ -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
}

View File

@ -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: (),

View File

@ -36,8 +36,6 @@ fn foo(p: &Panolpy) {
//~^ ERROR mismatched types
//~| expected `i32`
//~| found `i64`
//~| expected i32
//~| found i64)
}
fn main() {

View File

@ -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
}

View File

@ -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