The following doesn't compile:
pub fn main() {
const IMG_PATH: &str = concat!("a", "b", "c");
let img = include_str!(IMG_PATH);
}
It fails with an error that include_str
requires a string literal:
error: argument must be a string literal
--> src/main.rs:3:28
|
3 | let img = include_str!(IMG_PATH);
| ^^^^^^^^
Constructing the string inside the include_str!
seems to fix the compiler issue — it then complains about the path not being present in the filesystem so I suspect the former is resolved)
// works
let img = include_str!(concat!("a", "b", "c"));
Why is this happening? As far as I understand concat
operates statically and doesn't require doing anything at runtime. IMG_PATH
is also a constant that should also be allocated at compile-time.
rustc 1.43.1 (8d69840ab 2020-05-04)