Skip to content

Commit 0c10b27

Browse files
committed
Detect and reject out-of-range integers in format string literals
Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes #102528
1 parent 9c11905 commit 0c10b27

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

alloc/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
//! - `text` must not contain any `'{'` or `'}'` characters,
328328
//! - `ws` is any character for which [`char::is_whitespace`] returns `true`, has no semantic
329329
//! meaning and is completely optional,
330-
//! - `integer` is a decimal integer that may contain leading zeroes and
330+
//! - `integer` is a decimal integer that may contain leading zeroes and must fit into an `usize` and
331331
//! - `identifier` is an `IDENTIFIER_OR_KEYWORD` (not an `IDENTIFIER`) as defined by the [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html).
332332
//!
333333
//! # Formatting traits

0 commit comments

Comments
 (0)