macro
file! — Identify the source filename at a macro call
Yield a static string for the source file associated with the invocation. Macro expansion context and compiler path-remapping options can affect it. Do not treat it as a guaranteed absolute path or a path that exists on the deployed machine. Expression result: &'static str. Expected result (not executed): stdout: 'Has Rust suffix: true\n'; no stderr. Common mistake: Using file! as a reliable runtime location for external resources.
Formal Syntax & Structure
rust syntaxrust
file!()Working Example
Example Snippetrust
fn main() { let source = file!(); println!("Has Rust suffix: {}", source.ends_with(".rs"));}