diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-10 13:53:40 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-15 23:22:06 -0700 |
| commit | 854d95f9ffe83c8f77782b5dc76d18799579ba95 (patch) | |
| tree | 9b4f11bf0ad81ae05e004ccc4fca3c9e30f2d548 /src/test/compile-fail/use-after-move-implicity-coerced-object.rs | |
| parent | 00f9263914da3d18c556d7ebc3941f9638721ac2 (diff) | |
| download | rust-854d95f9ffe83c8f77782b5dc76d18799579ba95.tar.gz rust-854d95f9ffe83c8f77782b5dc76d18799579ba95.zip | |
syntax: Add a macro, format_args_method!()
Currently, the format_args!() macro takes as its first argument an expression
which is the callee of an ExprCall. This means that if format_args!() is used
with calling a method a closure must be used. Consider this code, however:
format_args!(|args| { foo.writer.write_fmt(args) }, "{}", foo.field)
The closure borrows the entire `foo` structure, disallowing the later borrow of
`foo.field`. To preserve the semantics of the `write!` macro, it is also
impossible to borrow specifically the `writer` field of the `foo` structure
because it must be borrowed mutably, but the `foo` structure is not guaranteed
to be mutable itself.
This new macro is invoked like:
format_args_method!(foo.writer, write_fmt, "{}", foo.field)
This macro will generate an ExprMethodCall which allows the borrow checker to
understand that `writer` and `field` should be borrowed separately.
This macro is not strictly necessary, with DST or possibly UFCS other
workarounds could be used. For now, though, it looks like this is required to
implement the `write!` macro.
Diffstat (limited to 'src/test/compile-fail/use-after-move-implicity-coerced-object.rs')
0 files changed, 0 insertions, 0 deletions
