Skip to content

type casting #138121

Closed as not planned
Closed as not planned
@TanvirSiddik

Description

@TanvirSiddik

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions