Skip to content
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

gccrs: allow casts from numeric types to floats #3270

Merged
merged 1 commit into from
Nov 27, 2024
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
10 changes: 10 additions & 0 deletions gcc/rust/typecheck/rust-casts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ TypeCastRules::cast_rules ()
}
break;

case TyTy::TypeKind::FLOAT: {
// can only do this for number types not char
bool from_char
= from.get_ty ()->get_kind () == TyTy::TypeKind::CHAR;
if (!from_char)
return TypeCoercionRules::CoercionResult{{},
to.get_ty ()->clone ()};
}
break;

case TyTy::TypeKind::INFER:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
Expand Down
18 changes: 18 additions & 0 deletions gcc/testsuite/rust/compile/issue-3261.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// { dg-options "-w" }
fn main() {
let a: i8 = 50;
let b = a as f32;
let c = a as f64;

let a: i16 = 1337;
let b = a as f32;
let c = a as f64;

let a: i32 = 1337;
let b = a as f32;
let c = a as f64;

let a: i64 = 1337;
let b = a as f32;
let c = a as f64;
}
Loading