From b8d5b3e6110023e17e1c191afa1d143f8b71fe4f Mon Sep 17 00:00:00 2001 From: Chris Watson Date: Tue, 30 Jun 2020 19:52:02 -0600 Subject: [PATCH] Add documentation for @src() builtin --- doc/langref.html.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/langref.html.in b/doc/langref.html.in index aef7b09798..dfbb93decf 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -8030,7 +8030,29 @@ test "vector @splat" {

{#see_also|Vectors|@shuffle#} {#header_close#} + {#header_open|@src#} +
{#syntax#}@src() std.builtin.SourceLocation{#endsyntax#}
+

+ Returns a {#syntax#}SourceLocation{#endsyntax#} struct representing the function's name and location in the source code. This must be called in a function. +

+ {#code_begin|test#} +const std = @import("std"); +const expect = std.testing.expect; +test "@src" { + doTheTest(); +} + +fn doTheTest() void { + const src = @src(); + + expect(src.line == 9); + expect(src.column == 17); + expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); + expect(std.mem.endsWith(u8, src.file, "test.zig")); +} + {#code_end#} + {#header_close#} {#header_open|@sqrt#}
{#syntax#}@sqrt(value: var) @TypeOf(value){#endsyntax#}