mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 23:29:50 +00:00
Preserve span of fields in derived Clone impl
This commit is contained in:
parent
4d73379753
commit
f3b89fb23a
@ -163,8 +163,14 @@ fn expand_struct(strct: &Struct) -> TokenStream {
|
||||
quote!(*self)
|
||||
} else {
|
||||
let fields = strct.fields.iter().map(|field| &field.ident);
|
||||
quote!(#ident {
|
||||
#(#fields: ::std::clone::Clone::clone(&self.#fields),)*
|
||||
let values = strct.fields.iter().map(|field| {
|
||||
let ident = &field.ident;
|
||||
let ty = field.ty.to_token_stream();
|
||||
let span = ty.into_iter().last().unwrap().span();
|
||||
quote_spanned!(span=> &self.#ident)
|
||||
});
|
||||
quote_spanned!(derive.span=> #ident {
|
||||
#(#fields: ::std::clone::Clone::clone(#values),)*
|
||||
})
|
||||
};
|
||||
expanded.extend(quote_spanned! {derive.span=>
|
||||
|
@ -1,8 +1,7 @@
|
||||
error[E0277]: the trait bound `ffi::Other: Clone` is not satisfied
|
||||
--> $DIR/derive_nonclone.rs:1:1
|
||||
--> $DIR/derive_nonclone.rs:5:9
|
||||
|
|
||||
1 | #[cxx::bridge]
|
||||
| ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `ffi::Other`
|
||||
5 | other: Other,
|
||||
| ^^^^^^^^^^^^ the trait `Clone` is not implemented for `ffi::Other`
|
||||
|
|
||||
= note: required by `clone`
|
||||
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
Loading…
Reference in New Issue
Block a user