Created
December 3, 2014 17:42
-
-
Save mnemnion/aa678124058a8ee4ab5d to your computer and use it in GitHub Desktop.
Constants aren't literal?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
const FORMATTER: &'static str = "{}" ; | |
fn main() { | |
let x = 5i; | |
println! (FORMATTER, x); | |
} |
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
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.