Skip to content

Fix the diagnostic for fat pointer to usize casts. #27596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum CastError {
DifferingKinds,
IllegalCast,
NeedViaPtr,
NeedViaThinPtr,
NeedViaInt,
NeedViaUsize,
NonScalar,
Expand All @@ -120,6 +121,7 @@ impl<'tcx> CastCheck<'tcx> {
e: CastError) {
match e {
CastError::NeedViaPtr |
CastError::NeedViaThinPtr |
CastError::NeedViaInt |
CastError::NeedViaUsize => {
fcx.type_error_message(self.span, |actual| {
Expand All @@ -130,6 +132,7 @@ impl<'tcx> CastCheck<'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!()
Expand Down Expand Up @@ -324,7 +327,7 @@ impl<'tcx> CastCheck<'tcx> {
if fcx.type_is_known_to_be_sized(m_expr.ty, self.span) {
Ok(CastKind::PtrAddrCast)
} else {
Err(CastError::NeedViaPtr)
Err(CastError::NeedViaThinPtr)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/cast-rfc0401.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/fat-ptr-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down