Skip to content

Instantly share code, notes, and snippets.

@mnemnion
Created December 3, 2014 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnemnion/aa678124058a8ee4ab5d to your computer and use it in GitHub Desktop.
Save mnemnion/aa678124058a8ee4ab5d to your computer and use it in GitHub Desktop.
Constants aren't literal?
use std::fmt;
const FORMATTER: &'static str = "{}" ;
fn main() {
let x = 5i;
println! (FORMATTER, x);
}
@mnemnion
Copy link
Author

mnemnion commented Dec 3, 2014

This produces the error /src/main.rs:11:15: 11:24 error: format argument must be a string literal. /src/main.rs:11 println! (FORMATTER, x);

How is this anything but a string literal? I plan to put FORMATTER in a base file and reuse it several times, seeking the usual advantages: semantics, and a single place from which to change or configure the constant.

@kmcallister
Copy link

Macro expansion happens before name resolution, so I think this would be pretty hard to fix :/

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