-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Try rethinking the format_args! macro #11838
Comments
(I think calling it |
Currently the formatting code does a bunch of function calls with references, and I wasn't able to get it to work out. I think that this may be the crux of it though: struct Foo<'a> {
v: &'a int
}
fn foo<'a>(f: &'a int) -> Foo<'a> {
Foo { v: f }
}
fn main() {
let args = foo(&1);
} That code does not compile today
@nikomatsakis, should that code compile? |
Nope. This is one of the cases of temporary lifetimes that won't work well without inference. Though you could write:
and that ought to work. Somewhat goofy. |
Another option is to remove the intermediate function. If it expanded to: |
Sadly, I don't think this is possible for now then. Function calls are used to enforce trait bounds of formatting traits and to get nice error messages, so it looks like we're stuck with the closure/function solution. |
This macro was written when rvalue lifetimes were pretty short, so the first argument is a closure or a bare function taking a local as an argument (the local is restrained to an inserted scope).
With our newly minted rvalue lifetime rules, this macro should be re-evaluated. It really wants to look like this:
The text was updated successfully, but these errors were encountered: