Use .name_str() to format primitive types in error messages
This commit is contained in:
parent
506e75cbf8
commit
f740923b8c
3 changed files with 63 additions and 2 deletions
|
@ -159,10 +159,23 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
|||
)
|
||||
}),
|
||||
IntMismatch(ref values) => {
|
||||
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
|
||||
let expected = match values.expected {
|
||||
ty::IntVarValue::IntType(ty) => ty.name_str(),
|
||||
ty::IntVarValue::UintType(ty) => ty.name_str(),
|
||||
};
|
||||
let found = match values.found {
|
||||
ty::IntVarValue::IntType(ty) => ty.name_str(),
|
||||
ty::IntVarValue::UintType(ty) => ty.name_str(),
|
||||
};
|
||||
write!(f, "expected `{}`, found `{}`", expected, found)
|
||||
}
|
||||
FloatMismatch(ref values) => {
|
||||
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
|
||||
write!(
|
||||
f,
|
||||
"expected `{}`, found `{}`",
|
||||
values.expected.name_str(),
|
||||
values.found.name_str()
|
||||
)
|
||||
}
|
||||
VariadicMismatch(ref values) => write!(
|
||||
f,
|
||||
|
|
21
src/test/ui/mismatched_types/issue-84976.rs
Normal file
21
src/test/ui/mismatched_types/issue-84976.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
fn foo(length: &u32) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
fn bar(length: &f32) -> f64 {
|
||||
0.0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut length = 0;
|
||||
length = { foo(&length) };
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
length = foo(&length);
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
|
||||
let mut float_length = 0.0;
|
||||
float_length = { bar(&float_length) };
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
float_length = bar(&float_length);
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
}
|
27
src/test/ui/mismatched_types/issue-84976.stderr
Normal file
27
src/test/ui/mismatched_types/issue-84976.stderr
Normal file
|
@ -0,0 +1,27 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84976.rs:11:16
|
||||
|
|
||||
LL | length = { foo(&length) };
|
||||
| ^^^^^^^^^^^^ expected `u32`, found `i32`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84976.rs:13:14
|
||||
|
|
||||
LL | length = foo(&length);
|
||||
| ^^^^^^^^^^^^ expected `u32`, found `i32`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84976.rs:17:22
|
||||
|
|
||||
LL | float_length = { bar(&float_length) };
|
||||
| ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84976.rs:19:20
|
||||
|
|
||||
LL | float_length = bar(&float_length);
|
||||
| ^^^^^^^^^^^^^^^^^^ expected `f32`, found `f64`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Reference in a new issue