Skip to content

make format! accept const vars as format-strings #69133

Closed
@matthiaskrgr

Description

@matthiaskrgr

I wonder if we could make rustc accept code like this:

    const y: &str = "hello {}";
    let x = format!(y, "world");

Currently this errors with:

error: format argument must be a string literal
 --> src/main.rs:3:21
  |
3 |     let x = format!(y, "world");
  |                     ^
  |
help: you might be missing a string literal to format with
  |
3 |     let x = format!("{} {}", y, "world");
  |                     ^^^^^^^^

rustc 1.43.0-nightly (58b834344 2020-02-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions