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

Restricted type casting from integer types to float types and vice versa #3261

Closed
nobel-sh opened this issue Nov 22, 2024 · 0 comments · Fixed by #3270 · May be fixed by #3319
Closed

Restricted type casting from integer types to float types and vice versa #3261

nobel-sh opened this issue Nov 22, 2024 · 0 comments · Fixed by #3270 · May be fixed by #3319

Comments

@nobel-sh
Copy link
Contributor

gccrs does not allow conversion from integer type to float type and float type to integer type.

fn main(){
    let a: u8 = 13;
    let b:f64 = a as f64;
}

gccrs produces the following error:

<source>:3:17: error: casting 'u8' as 'f64' is invalid [E0606]
    3 |     let b:f64 = a as f64;
      |                 ^    ~~~

Godbolt link: https://godbolt.org/z/qorqTvfbx

@philberty philberty self-assigned this Nov 26, 2024
philberty added a commit that referenced this issue Nov 26, 2024
Fixes #3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
philberty added a commit that referenced this issue Nov 27, 2024
Fixes #3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Nov 27, 2024
Fixes #3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in libcore 1.49 Nov 27, 2024
tschwinge pushed a commit that referenced this issue Dec 4, 2024
Fixes #3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
Kamiinarii78 pushed a commit to Kamiinarii78/gccrs that referenced this issue Dec 12, 2024
Fixes Rust-GCC#3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
matthewjasper pushed a commit to matthewjasper/gccrs that referenced this issue Dec 21, 2024
Fixes Rust-GCC#3261

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment