Skip to content

does not detect {} not being in quotes when looking for a string literal, instead offers an incorrect solution #130170

Closed
@EnderNon

Description

@EnderNon

Code

use serde_json;

let idsmap: HashMap<String, u8> = serde_json::from_reader(fs::File::open("id_keys.json").expect("error 3"))
    .expect("error 4");
println!({},idsmap.get("1stSpellCost"));

Current output

error: format argument must be a string literal
  --> src/main.rs:55:14
   |
55 |     println!({},idsmap.get("1stSpellCost"));
   |              ^^
   |
help: you might be missing a string literal to format with
   |
55 |     println!("{} {}", {},idsmap.get("1stSpellCost"));
   |              ++++++++

Desired output

error: format argument must be a string literal
  --> src/main.rs:55:14
   |
55 |     println!({},idsmap.get("1stSpellCost"));
   |              ^^
   |
help: you might be missing brackets
   |
55 |     println!("{}",idsmap.get("1stSpellCost"));
   |              +  +

Rationale and extra context

Cargo does not seem to be detecting the {} outside brackets and provides an incredibly strange fix instead.

Other cases

No response

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Anything else?

the file is from here:
https://github.com/Wynntils/Static-Storage/blob/main/Reference/id_keys.json
You will need serde_json crate.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions