提交 920cf4b4 编写于 作者: B bors

Auto merge of #27596 - tsion:fix-27450, r=arielb1

Fixes #27450.

r? @steveklabnik
......@@ -100,6 +100,7 @@ enum CastError {
DifferingKinds,
IllegalCast,
NeedViaPtr,
NeedViaThinPtr,
NeedViaInt,
NeedViaUsize,
NonScalar,
......@@ -120,6 +121,7 @@ fn report_cast_error<'a>(&self, fcx: &FnCtxt<'a, 'tcx>,
e: CastError) {
match e {
CastError::NeedViaPtr |
CastError::NeedViaThinPtr |
CastError::NeedViaInt |
CastError::NeedViaUsize => {
fcx.type_error_message(self.span, |actual| {
......@@ -130,6 +132,7 @@ fn report_cast_error<'a>(&self, fcx: &FnCtxt<'a, 'tcx>,
fcx.ccx.tcx.sess.fileline_help(self.span,
&format!("cast through {} first", match e {
CastError::NeedViaPtr => "a raw pointer",
CastError::NeedViaThinPtr => "a thin pointer",
CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize",
_ => unreachable!()
......@@ -324,7 +327,7 @@ fn check_ptr_addr_cast<'a>(&self,
if fcx.type_is_known_to_be_sized(m_expr.ty, self.span) {
Ok(CastKind::PtrAddrCast)
} else {
Err(CastError::NeedViaPtr)
Err(CastError::NeedViaThinPtr)
}
}
......
......@@ -96,7 +96,7 @@ fn main()
let _ = &f as *const f64; //~ ERROR casting
let _ = fat_v as usize;
//~^ ERROR casting
//~^^ HELP through a raw pointer first
//~^^ HELP through a thin pointer first
let a : *const str = "hello";
let _ = a as *const Foo;
......
......@@ -21,7 +21,7 @@ fn main() {
b as usize; //~ ERROR non-scalar cast
p as usize;
//~^ ERROR casting
//~^^ HELP cast through a raw pointer
//~^^ HELP cast through a thin pointer
// #22955
q as *const [i32]; //~ ERROR casting
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册