Skip to content

Wrong print_literal/write_literal suggestion with byte literal #8615

Closed
@asrcpq

Description

@asrcpq

Summary

When formatting with byte literals, e.g. println!("Ascii code of letter e is {}", b'e');

clippy gives

warning: literal with an empty format string
 --> src/main.rs:2:43
  |
2 |     println!("Ascii code of letter e is {}", b'e');
  |                                              ^^^^
  |
  = note: `#[warn(clippy::print_literal)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
help: try this
  |
2 -     println!("Ascii code of letter e is {}", b'e');
2 +     println!("Ascii code of letter e is e");
  | 

However, the output changed by this modification, from
Ascii code of letter e is 101
to
Ascii code of letter e is e

Reproducer

println!("Ascii code of letter e is {}", b'e');

Version

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions