Skip to content

Fixed #17823 #30937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,38 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
trace: TypeTrace<'tcx>,
terr: &TypeError<'tcx>)
-> DiagnosticBuilder<'tcx> {
fn is_simple_type<'tcx>(ty: Ty<'tcx>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a method on TyS rather than a function here - is_primitive maybe

use middle::ty::TypeVariants::*;
match ty.sty {
TyBool | TyChar | TyInt(_) | TyUint(_) | TyFloat(_) => true,
_ => false,
}
}

let expected_found_str = match self.values_str(&trace.values) {
Some(v) => v,
None => {
return self.tcx.sess.diagnostic().struct_dummy(); /* derived error */
}
};

let is_simple_error = if let &TypeError::Sorts(ref values) = terr {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only make simple errors for TypeError::Sorts? Do other kinds of error never give the repetitive pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what TypeError::Sorts for. Maybe other kinds also give the repetitive pattern, I will see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I check for TypeError::IntMismatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only TypeError::Sorts has repetitive error.

is_simple_type(values.expected) && is_simple_type(values.found)
} else {
false
};
let err = if is_simple_error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename err to expected_found_str

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);
err);

self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span());

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