macro
line! — Identify the source line number
Yield a one-based u32 source line number associated with the invocation. It is useful for diagnostics, not a stable program identifier. In nested macro expansions the reported location can refer to an outer invocation. Expression result: u32. Expected result (not executed): stdout: 'Difference: 1\n'; no stderr. Common mistake: Hardcoding the current line number in a test that will break when unrelated code is inserted.
Formal Syntax & Structure
rust syntaxrust
line!()Working Example
Example Snippetrust
fn main() { let start = line!(); let end = line!(); println!("Difference: {}", end - start);}