summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/zero_prefixed_literal.txt
blob: 5c5588725363e5b26a1c45454a790b92949301d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### What it does
Warns if an integral constant literal starts with `0`.

### Why is this bad?
In some languages (including the infamous C language
and most of its
family), this marks an octal constant. In Rust however, this is a decimal
constant. This could
be confusing for both the writer and a reader of the constant.

### Example

In Rust:
```
fn main() {
    let a = 0123;
    println!("{}", a);
}
```

prints `123`, while in C:

```
#include <stdio.h>

int main() {
    int a = 0123;
    printf("%d\n", a);
}
```

prints `83` (as `83 == 0o123` while `123 == 0o173`).