Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,14 +1008,17 @@ pub fn write(ts: TokenStream) -> TokenStream {
let fmt = &write.fmt;
// FIXME: Introduce a new `"write"` tag and decode it in a loop (breaking change).
let sym = mksym(&ls, "fmt", false);
quote!(match (#fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// HACK conditional should not be here; see FIXME in `format`
if _fmt_.needs_tag() {
_fmt_.istr(&defmt::export::istr(#sym));
quote!({
let fmt: ::defmt::Formatter<'_> = #fmt;
match (fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// HACK conditional should not be here; see FIXME in `format`
if _fmt_.needs_tag() {
_fmt_.istr(&defmt::export::istr(#sym));
}
#(#exprs;)*
_fmt_.finalize();
}
#(#exprs;)*
_fmt_.finalize();
}
})
.into()
Expand Down
16 changes: 6 additions & 10 deletions tests/ui/write-for-loop.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
error[E0382]: use of moved value: `f.inner`
--> $DIR/write-for-loop.rs:6:13
error[E0382]: use of moved value: `f`
--> $DIR/write-for-loop.rs:6:27
|
4 | fn format(&self, f: defmt::Formatter) {
| - move occurs because `f` has type `defmt::Formatter<'_>`, which does not implement the `Copy` trait
5 | for _ in 0..3 {
6 | defmt::write!(f, "hello");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ value moved here, in previous iteration of loop
|
= note: move occurs because `f.inner` has type `&mut InternalFormatter`, which does not implement the `Copy` trait
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider creating a fresh reborrow of `f.inner` here
|
6 | &mut *defmt::write!(f, "hello");
| ^^^^^^
| ^ value moved here, in previous iteration of loop
13 changes: 6 additions & 7 deletions tests/ui/write-twice.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
error[E0382]: use of moved value: `f.inner`
--> $DIR/write-twice.rs:6:9
error[E0382]: use of moved value: `f`
--> $DIR/write-twice.rs:6:23
|
4 | fn format(&self, f: defmt::Formatter) {
| - move occurs because `f` has type `defmt::Formatter<'_>`, which does not implement the `Copy` trait
5 | defmt::write!(f, "hello");
| -------------------------- value moved here
| - value moved here
6 | defmt::write!(f, "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
|
= note: move occurs because `f.inner` has type `&mut InternalFormatter`, which does not implement the `Copy` trait
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
| ^ value used here after move