Skip to content

format_args! does not respect integer literals' type #115423

Closed
@endorpersand

Description

@endorpersand

When using the 1234i8 syntax in the Display format in formatting macros, the i8 is ignored and treated as a u128.

I tried this code:

fn main() {
    println!("{}", 0x8Fi8);
}

I expected to see this happen: Getting an error that 0x8F is out of the bounds for type i8.

Instead, this happened: This function compiles and prints 143.

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-apple-darwin
release: 1.71.1
LLVM version: 16.0.5

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 1, 2023
konnorandrews

konnorandrews commented on Sep 1, 2023

@konnorandrews

I went and looked through the format_args!() implementation and found where the issue comes from. The check at https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast_lowering/src/format.rs#L131 ignores the integer type, and it blindly calls n.string() on the u128 value of the literal.

removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 1, 2023
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 1, 2023
gurry

gurry commented on Sep 3, 2023

@gurry
Contributor

@rustbot claim

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Sep 5, 2023
apiraino

apiraino commented on Sep 7, 2023

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Sep 7, 2023
removed their assignment
on Sep 13, 2023

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-fmtArea: `core::fmt`C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @cuviper@m-ou-se@gurry@apiraino@saethlin

    Issue actions

      `format_args!` does not respect integer literals' type · Issue #115423 · rust-lang/rust