Skip to content

Commit

Permalink
Improve type mismatch error messages
Browse files Browse the repository at this point in the history
Replace "integral variable" with "integer" and replace
"floating-point variable" with "floating-point number" to make the
message less confusing.
  • Loading branch information
codeworm96 committed Jan 1, 2019
1 parent 6efaef6 commit 710dcbd
Show file tree
Hide file tree
Showing 54 changed files with 105 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
ty::GeneratorWitness(..) => "generator witness".into(),
ty::Tuple(..) => "tuple".into(),
ty::Infer(ty::TyVar(_)) => "inferred type".into(),
ty::Infer(ty::IntVar(_)) => "integral variable".into(),
ty::Infer(ty::FloatVar(_)) => "floating-point variable".into(),
ty::Infer(ty::IntVar(_)) => "integer".into(),
ty::Infer(ty::FloatVar(_)) => "floating-point number".into(),
ty::Placeholder(..) => "placeholder type".into(),
ty::Bound(..) => "bound type".into(),
ty::Infer(ty::FreshTy(_)) => "fresh type".into(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/bad/bad-const-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ static i: String = 10;
//~^ ERROR mismatched types
//~| expected type `std::string::String`
//~| found type `{integer}`
//~| expected struct `std::string::String`, found integral variable
//~| expected struct `std::string::String`, found integer
fn main() { println!("{}", i); }
2 changes: 1 addition & 1 deletion src/test/ui/bad/bad-const-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | static i: String = 10;
| ^^
| |
| expected struct `std::string::String`, found integral variable
| expected struct `std::string::String`, found integer
| help: try using a conversion method: `10.to_string()`
|
= note: expected type `std::string::String`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/binop/binop-logic-int.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/binop-logic-int.rs:1:21
|
LL | fn main() { let x = 1 && 2; }
| ^ expected bool, found integral variable
| ^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -11,7 +11,7 @@ error[E0308]: mismatched types
--> $DIR/binop-logic-int.rs:1:26
|
LL | fn main() { let x = 1 && 2; }
| ^ expected bool, found integral variable
| ^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/blind/blind-item-block-middle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/blind-item-block-middle.rs:6:9
|
LL | let bar = 5;
| ^^^ expected integral variable, found struct `foo::bar`
| ^^^ expected integer, found struct `foo::bar`
|
= note: expected type `{integer}`
found type `foo::bar`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/chalkify/type_inference.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/type_inference.rs:21:14
|
LL | only_foo(x); //~ ERROR mismatched types
| ^ expected i32, found floating-point variable
| ^ expected i32, found floating-point number
|
= note: expected type `i32`
found type `{float}`
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/coercion/coerce-to-bang.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:6:17
|
LL | foo(return, 22, 44);
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -11,7 +11,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:18:13
|
LL | foo(22, 44, return); //~ ERROR mismatched types
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -20,7 +20,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:26:12
|
LL | foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
| ^ expected !, found integral variable
| ^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -29,7 +29,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:36:12
|
LL | foo(a, b, c); //~ ERROR mismatched types
| ^ expected !, found integral variable
| ^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -38,7 +38,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:45:12
|
LL | foo(a, b, c); //~ ERROR mismatched types
| ^ expected !, found integral variable
| ^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -47,7 +47,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:50:21
|
LL | let x: [!; 2] = [return, 22]; //~ ERROR mismatched types
| ^^^^^^^^^^^^ expected !, found integral variable
| ^^^^^^^^^^^^ expected !, found integer
|
= note: expected type `[!; 2]`
found type `[{integer}; 2]`
Expand All @@ -56,7 +56,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:55:22
|
LL | let x: [!; 2] = [22, return]; //~ ERROR mismatched types
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -65,7 +65,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:60:37
|
LL | let x: (usize, !, usize) = (22, 44, 66); //~ ERROR mismatched types
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -74,7 +74,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:65:41
|
LL | let x: (usize, !, usize) = (return, 44, 66);
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand All @@ -83,7 +83,7 @@ error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:76:37
|
LL | let x: (usize, !, usize) = (22, 44, return); //~ ERROR mismatched types
| ^^ expected !, found integral variable
| ^^ expected !, found integer
|
= note: expected type `!`
found type `{integer}`
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/consts/const-integer-bool-ops.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
const X: usize = 42 && 39;
//~^ ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected usize, found bool
const ARR: [i32; X] = [99; 34];
//~^ ERROR evaluation of constant value failed

const X1: usize = 42 || 39;
//~^ ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected usize, found bool
const ARR1: [i32; X1] = [99; 47];
//~^ ERROR evaluation of constant value failed

const X2: usize = -42 || -39;
//~^ ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected usize, found bool
const ARR2: [i32; X2] = [99; 18446744073709551607];
//~^ ERROR evaluation of constant value failed

const X3: usize = -42 && -39;
//~^ ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected bool, found integral variable
//~| expected bool, found integer
//~| ERROR mismatched types
//~| expected usize, found bool
const ARR3: [i32; X3] = [99; 6];
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/consts/const-integer-bool-ops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:1:18
|
LL | const X: usize = 42 && 39;
| ^^ expected bool, found integral variable
| ^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -11,7 +11,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:1:24
|
LL | const X: usize = 42 && 39;
| ^^ expected bool, found integral variable
| ^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -32,7 +32,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:11:19
|
LL | const X1: usize = 42 || 39;
| ^^ expected bool, found integral variable
| ^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -41,7 +41,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:11:25
|
LL | const X1: usize = 42 || 39;
| ^^ expected bool, found integral variable
| ^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -62,7 +62,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:21:19
|
LL | const X2: usize = -42 || -39;
| ^^^ expected bool, found integral variable
| ^^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -71,7 +71,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:21:26
|
LL | const X2: usize = -42 || -39;
| ^^^ expected bool, found integral variable
| ^^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -92,7 +92,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:31:19
|
LL | const X3: usize = -42 && -39;
| ^^^ expected bool, found integral variable
| ^^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand All @@ -101,7 +101,7 @@ error[E0308]: mismatched types
--> $DIR/const-integer-bool-ops.rs:31:26
|
LL | const X3: usize = -42 && -39;
| ^^^ expected bool, found integral variable
| ^^^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/conversion-methods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ error[E0308]: mismatched types
LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here
| ^
| |
| expected struct `std::string::String`, found integral variable
| expected struct `std::string::String`, found integer
| help: try using a conversion method: `2.to_string()`
|
= note: expected type `std::string::String`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | let sixteen: f32 = 16;
| ^^
| |
| expected f32, found integral variable
| expected f32, found integer
| help: use a float literal: `16.0`
|
= note: expected type `f32`
Expand All @@ -16,7 +16,7 @@ error[E0308]: mismatched types
LL | let a_million_and_seventy: f64 = 1_000_070;
| ^^^^^^^^^
| |
| expected f64, found integral variable
| expected f64, found integer
| help: use a float literal: `1_000_070.0`
|
= note: expected type `f64`
Expand All @@ -28,7 +28,7 @@ error[E0308]: mismatched types
LL | let negative_nine: f32 = -9;
| ^^
| |
| expected f32, found integral variable
| expected f32, found integer
| help: use a float literal: `-9.0`
|
= note: expected type `f32`
Expand All @@ -38,7 +38,7 @@ error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:15:30
|
LL | let sixteen_again: f64 = 0x10;
| ^^^^ expected f64, found integral variable
| ^^^^ expected f64, found integer
|
= note: expected type `f64`
found type `{integer}`
Expand All @@ -47,7 +47,7 @@ error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:17:30
|
LL | let and_once_more: f32 = 0o20;
| ^^^^ expected f32, found integral variable
| ^^^^ expected f32, found integer
|
= note: expected type `f32`
found type `{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0070.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0308]: mismatched types
--> $DIR/E0070.rs:8:25
|
LL | some_other_func() = 4; //~ ERROR E0070
| ^ expected (), found integral variable
| ^ expected (), found integer
|
= note: expected type `()`
found type `{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/float-literal-inference-restrictions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | let x: f32 = 1; //~ ERROR mismatched types
| ^
| |
| expected f32, found integral variable
| expected f32, found integer
| help: use a float literal: `1.0`
|
= note: expected type `f32`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `std::option::Option<usize>`
//~| found type `{integer}`
//~| expected enum `std::option::Option`, found integral variable
//~| expected enum `std::option::Option`, found integer
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | x = 5;
| ^
| |
| expected enum `std::option::Option`, found integral variable
| expected enum `std::option::Option`, found integer
| help: try using a variant of the expected type: `Some(5)`
|
= note: expected type `std::option::Option<usize>`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generic/generic-arg-mismatch-recover.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/generic-arg-mismatch-recover.rs:6:33
|
LL | Foo::<'static, 'static, ()>(&0); //~ ERROR wrong number of lifetime arguments
| ^^ expected (), found integral variable
| ^^ expected (), found integer
|
= note: expected type `&'static ()`
found type `&{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/if/if-let-arm-types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
if let Some(b) = None { //~ ERROR: `if let` arms have incompatible types
//~^ expected (), found integral variable
//~^ expected (), found integer
//~| expected type `()`
//~| found type `{integer}`
()
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/if/if-let-arm-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0308]: `if let` arms have incompatible types
--> $DIR/if-let-arm-types.rs:2:5
|
LL | / if let Some(b) = None { //~ ERROR: `if let` arms have incompatible types
LL | | //~^ expected (), found integral variable
LL | | //~^ expected (), found integer
LL | | //~| expected type `()`
LL | | //~| found type `{integer}`
... |
LL | | 1
LL | | };
| |_____^ expected (), found integral variable
| |_____^ expected (), found integer
|
= note: expected type `()`
found type `{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/integral-variable-unification-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `{integer}`
//~| found type `{float}`
//~| expected integral variable, found floating-point variable
//~| expected integer, found floating-point number
}
Loading

0 comments on commit 710dcbd

Please sign in to comment.