Skip to content

Commit

Permalink
Auto merge of #30953 - KalitaAlexey:17823-get-rid-of-duplicate-error,…
Browse files Browse the repository at this point in the history
… r=nrc
  • Loading branch information
bors committed Jan 18, 2016
2 parents 257d324 + 8a41eb5 commit 9d21aca
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 112 deletions.
17 changes: 14 additions & 3 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
7 changes: 7 additions & 0 deletions src/librustc/middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/if-branch-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ fn main() {
//~^ ERROR if and else have incompatible types
//~| expected `i32`
//~| found `u32`
//~| expected i32
//~| found u32
}
72 changes: 0 additions & 72 deletions src/test/compile-fail/integer-literal-suffix-inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,238 +43,166 @@ 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
id_i8(c16);
//~^ 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
id_u8(b16);
//~^ 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
}
4 changes: 0 additions & 4 deletions src/test/compile-fail/issue-13359.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-3477.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ fn main() {
//~^ ERROR mismatched types
//~| expected `char`
//~| found `u8`
//~| expected char
//~| found u8
}
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-5100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@ fn main() {
let x: char = true; //~ ERROR mismatched types
//~| expected `char`
//~| found `bool`
//~| expected char
//~| found bool
}
4 changes: 0 additions & 4 deletions src/test/compile-fail/issue-8761.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
2 changes: 0 additions & 2 deletions src/test/compile-fail/pattern-error-continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ fn main() {
//~^ ERROR mismatched types
//~| expected `char`
//~| found `bool`
//~| expected char
//~| found bool
}
4 changes: 0 additions & 4 deletions src/test/compile-fail/pptypedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions src/test/compile-fail/repeat_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: (),
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/shift-various-bad-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fn foo(p: &Panolpy) {
//~^ ERROR mismatched types
//~| expected `i32`
//~| found `i64`
//~| expected i32
//~| found i64)
}

fn main() {
Expand Down
Loading

0 comments on commit 9d21aca

Please sign in to comment.