Skip to content

Commit 18b158c

Browse files
committed
Add "function name macro"
1 parent d5932dd commit 18b158c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

text/0000-function-name-macro.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
- Start Date: 2014-11-17
2+
- RFC PR: (leave this empty)
3+
- Rust Issue: (leave this empty)
4+
5+
# Summary
6+
7+
Introduce a `function!()` macro that expands to an `Option<&'static str>` of the function
8+
name it's used in.
9+
10+
# Motivation
11+
12+
For error reporting cases we already have `file!`, `line!`, `col!` and `module_path!`
13+
but there is no way yet to figure out in which function an error was reported. Python's
14+
tracebacks are well received and for many people the function name information is much
15+
more important than the line number.
16+
17+
# Detailed design
18+
19+
The behavior of the new `function!` macro should be as such:
20+
21+
* when used within a proper function `fn` (or trait method) it expands to
22+
`Some(name)` where `name` is the name of the function. It is always the
23+
local name of the function which means even if a function is contained in
24+
another function, it's just the the actual name.
25+
* when used inside a local block in a function (proc, closure or anything else) it
26+
expands to the name of the innermost proper function.
27+
* if used anywhere else it expands to `None`.
28+
29+
# Drawbacks
30+
31+
Maybe `function!` is a bit generic of a name. Alternative names could be considered.
32+
33+
# Alternatives
34+
35+
As an alternative name, `function_name!` could be used.

0 commit comments

Comments
 (0)