-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Add "function name macro" #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
`Some(name)` where `name` is the name of the function. It is always the | ||
local name of the function which means even if a function is contained in | ||
another function, it's just the the actual name. | ||
* when used inside a local block in a function (proc, closure or anything else) it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What name will you give for anonymous functions such as closures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned the name of the function they are contained in is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function in which they are defined, or the function in which they are invoked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would need to be the one they are defined in, unless we want to hold onto that information and pass it through dynamically, which seems heavy for a debug feature.
I don't think Rust should continue down this road. I consider the usage of row / column numbers in failure messages to be a serious design flaw. It's a severe code bloat / performance issue along with resulting in terrible messages with only the local context (like |
@thestinger what's your alternative? I rely on this error information to produce proper debug information. Taking it away without providing a replacement is not exactly a good idea. Obviously it's not fast, but that's hardly the point of a debug helper. |
+1 to this. Also I've always wondered if there could be a macro for the 'enclosing' function name in the case of inlined generic code.. you want to know where its' invoked from (e.g. iterators etc). |
I think this RFC should be seen separate to finding alternatives to line/file etc. I understand that @thestinger is concerned with compiling too much bloat into binaries but there are plenty of situations where this is actually a much more reasonable approach than using |
|
||
# Drawbacks | ||
|
||
Maybe `function!` is a bit generic of a name. Alternative names could be considered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function!()
does strike me as too generic. I much prefer the descriptiveness of function_name!()
. I don't mind the underscore because ideally you'd have this wrapped in some more general error handling device.
+1 to this - would find this kind of information very useful, and there's precedent in systems languages already: C/C++ compilers provide the |
cc rust-lang/rust#9668, quite an old PR which attempted this some time ago. I do think that the actual output of this macro is somewhat orthogonal to considering its inclusion. Many uses of
In general I don't think any of us have given an inordinate amount of thought to these "debugging related" macros in terms of long term stability. Most of them seem fairly harmless, but committing to provide all of them for all Rust programs forever is a strong commitment to make. We may want to briefly consider the story of these macros in conjunction with considering adding this new macro. Regardless, thank you for taking the time to write this up @mitsuhiko! The work you're doing with error reporting is quite exciting, and I'd love to improve it even more! |
Is this RFC merged normally? I can't find its content in both rfcs repo and @mitsuhiko 's "Rendered View" link. Github shows there is no commit and no file changed in this PR. @alexcrichton |
No this was an accident when @mitsuhiko updated his local master branch, I believe he was going to re-open the PR, or did I mis-hear @mitsuhiko? |
Is this still being worked on? The 'rendered view' link doesn't work. |
I support the addition of a macro like |
EDIT: Well, ignore this current issue, looks like the following one is overriding it AND still open: #1743 |
This RFC proposes the addition of a
function!
macro that expands to the function it's used in. This will greatly help error reporting.Rendered View