Skip to content

Clippy suggests 0o<8|9>, which is an invalid suggestion. #9651

Closed

Description

Summary

When this code is ran through clippy, it suggests invalid code.

Lint Name

zero_prefixed_literal

Reproducer

I tried this code:

fn main() {
    let x = 08;
}

I saw this happen:

warning: this is a decimal constant
 --> src/main.rs:2:13
  |
2 |     let x = 08;
  |             ^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal
  = note: `#[warn(clippy::zero_prefixed_literal)]` on by default
help: if you mean to use a decimal constant, remove the `0` to avoid confusion
  |
2 |     let x = 8;
  |             ~
help: if you mean to use an octal constant, use `0o`
  |
2 |     let x = 0o8;

I expected to see this happen: Clippy to not suggest a borked suggestion. As running

fn main() {
    let x = 0o8;
}

results in

error: invalid digit for a base 8 literal
 --> src/main.rs:2:15
  |
2 |     let x = 0o8;
  |  

Version

rustc 1.66.0-nightly (bf15a9e52 2022-10-14)
binary: rustc
commit-hash: bf15a9e5263fcea065a7ae9c179b2d24c2deb670
commit-date: 2022-10-14
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

Additional Labels

@rustbot label +I-suggestion-causes-error

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

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions