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

type casting #138121

Closed
TanvirSiddik opened this issue Mar 6, 2025 · 1 comment
Closed

type casting #138121

TanvirSiddik opened this issue Mar 6, 2025 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@TanvirSiddik
Copy link

I tried this code:

pub fn type_casting() {
    let something: u8 = 255;
    let something_i8 = something as i8;
    println!("{}", something_i8);
    println!("{}", something);
}

I expected to see this happen: i was expecting somekind of error, not even runtime error

Instead, this happened: *i get
-1
255
as output this may cause bugs in application
*

Meta

rustc --version --verbose:

<version>

rustc 1.85.0 (4d91de4 2025-02-17)
binary: rustc
commit-hash: 4d91de4
commit-date: 2025-02-17
host: x86_64-pc-windows-msvc
release: 1.85.0
LLVM version: 19.1.7

Backtrace

<backtrace>

@TanvirSiddik TanvirSiddik added the C-bug Category: This is a bug. label Mar 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 6, 2025

See:

I'm going to close this as inactionable because while it's known that as casts are a confusing mix of a bunch of behaviors, it's likely too noisy to warn on existing code, and more explicit methods are being added to address such use cases to make it unambiguous.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants