1
Fork 0

Rollup merge of #85187 - FabianWolff:issue-84976, r=jackh726

Use .name_str() to format primitive types in error messages

This pull request fixes #84976. The problem described there is caused by this code
506e75cbf8/compiler/rustc_middle/src/ty/error.rs (L161-L166)
using `Debug` formatting (`{:?}`), while the proper solution is to call `name_str()` of `ty::IntTy`, `ty::UintTy` and `ty::FloatTy`, respectively.
This commit is contained in:
Yuki Okushi 2021-05-12 07:18:04 +09:00 committed by GitHub
commit c4c654f422
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 2 deletions

View file

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