Fix the diagnostic for fat pointer to usize casts.

Fixes #27450.
This commit is contained in:
Scott Olson
2015-08-07 22:08:28 -04:00
parent e5d90d9840
commit f351e762f0
3 changed files with 6 additions and 3 deletions

View File

@@ -100,6 +100,7 @@ enum CastError {
DifferingKinds, DifferingKinds,
IllegalCast, IllegalCast,
NeedViaPtr, NeedViaPtr,
NeedViaThinPtr,
NeedViaInt, NeedViaInt,
NeedViaUsize, NeedViaUsize,
NonScalar, NonScalar,
@@ -120,6 +121,7 @@ impl<'tcx> CastCheck<'tcx> {
e: CastError) { e: CastError) {
match e { match e {
CastError::NeedViaPtr | CastError::NeedViaPtr |
CastError::NeedViaThinPtr |
CastError::NeedViaInt | CastError::NeedViaInt |
CastError::NeedViaUsize => { CastError::NeedViaUsize => {
fcx.type_error_message(self.span, |actual| { fcx.type_error_message(self.span, |actual| {
@@ -130,6 +132,7 @@ impl<'tcx> CastCheck<'tcx> {
fcx.ccx.tcx.sess.fileline_help(self.span, fcx.ccx.tcx.sess.fileline_help(self.span,
&format!("cast through {} first", match e { &format!("cast through {} first", match e {
CastError::NeedViaPtr => "a raw pointer", CastError::NeedViaPtr => "a raw pointer",
CastError::NeedViaThinPtr => "a thin pointer",
CastError::NeedViaInt => "an integer", CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize", CastError::NeedViaUsize => "a usize",
_ => unreachable!() _ => unreachable!()
@@ -324,7 +327,7 @@ impl<'tcx> CastCheck<'tcx> {
if fcx.type_is_known_to_be_sized(m_expr.ty, self.span) { if fcx.type_is_known_to_be_sized(m_expr.ty, self.span) {
Ok(CastKind::PtrAddrCast) Ok(CastKind::PtrAddrCast)
} else { } else {
Err(CastError::NeedViaPtr) Err(CastError::NeedViaThinPtr)
} }
} }

View File

@@ -96,7 +96,7 @@ fn main()
let _ = &f as *const f64; //~ ERROR casting let _ = &f as *const f64; //~ ERROR casting
let _ = fat_v as usize; let _ = fat_v as usize;
//~^ ERROR casting //~^ ERROR casting
//~^^ HELP through a raw pointer first //~^^ HELP through a thin pointer first
let a : *const str = "hello"; let a : *const str = "hello";
let _ = a as *const Foo; let _ = a as *const Foo;

View File

@@ -21,7 +21,7 @@ fn main() {
b as usize; //~ ERROR non-scalar cast b as usize; //~ ERROR non-scalar cast
p as usize; p as usize;
//~^ ERROR casting //~^ ERROR casting
//~^^ HELP cast through a raw pointer //~^^ HELP cast through a thin pointer
// #22955 // #22955
q as *const [i32]; //~ ERROR casting q as *const [i32]; //~ ERROR casting