]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/src/docs/zero_prefixed_literal.txt
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / zero_prefixed_literal.txt
1 ### What it does
2 Warns if an integral constant literal starts with `0`.
3
4 ### Why is this bad?
5 In some languages (including the infamous C language
6 and most of its
7 family), this marks an octal constant. In Rust however, this is a decimal
8 constant. This could
9 be confusing for both the writer and a reader of the constant.
10
11 ### Example
12
13 In Rust:
14 ```
15 fn main() {
16 let a = 0123;
17 println!("{}", a);
18 }
19 ```
20
21 prints `123`, while in C:
22
23 ```
24 #include <stdio.h>
25
26 int main() {
27 int a = 0123;
28 printf("%d\n", a);
29 }
30 ```
31
32 prints `83` (as `83 == 0o123` while `123 == 0o173`).