mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-23 16:00:10 +00:00
Use 2018-style absolute paths in examples
This commit is contained in:
parent
18c081f5ac
commit
20985b9231
@ -31,12 +31,12 @@ struct Demo<'a, T: ?Sized> {
|
||||
The trait impl generated by the custom derive here would look like:
|
||||
|
||||
```rust
|
||||
impl<'a, T: ?Sized + ::heapsize::HeapSize> ::heapsize::HeapSize for Demo<'a, T> {
|
||||
impl<'a, T: ?Sized + heapsize::HeapSize> heapsize::HeapSize for Demo<'a, T> {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
0 + ::heapsize::HeapSize::heap_size_of_children(&self.a)
|
||||
+ ::heapsize::HeapSize::heap_size_of_children(&self.b)
|
||||
+ ::heapsize::HeapSize::heap_size_of_children(&self.c)
|
||||
+ ::heapsize::HeapSize::heap_size_of_children(&self.d)
|
||||
0 + heapsize::HeapSize::heap_size_of_children(&self.a)
|
||||
+ heapsize::HeapSize::heap_size_of_children(&self.b)
|
||||
+ heapsize::HeapSize::heap_size_of_children(&self.c)
|
||||
+ heapsize::HeapSize::heap_size_of_children(&self.d)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -22,7 +22,7 @@ pub fn derive_heap_size(input: proc_macro::TokenStream) -> proc_macro::TokenStre
|
||||
|
||||
let expanded = quote! {
|
||||
// The generated impl.
|
||||
impl #impl_generics ::heapsize::HeapSize for #name #ty_generics #where_clause {
|
||||
impl #impl_generics heapsize::HeapSize for #name #ty_generics #where_clause {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
#sum
|
||||
}
|
||||
@ -37,7 +37,7 @@ pub fn derive_heap_size(input: proc_macro::TokenStream) -> proc_macro::TokenStre
|
||||
fn add_trait_bounds(mut generics: Generics) -> Generics {
|
||||
for param in &mut generics.params {
|
||||
if let GenericParam::Type(ref mut type_param) = *param {
|
||||
type_param.bounds.push(parse_quote!(::heapsize::HeapSize));
|
||||
type_param.bounds.push(parse_quote!(heapsize::HeapSize));
|
||||
}
|
||||
}
|
||||
generics
|
||||
@ -64,7 +64,7 @@ fn heap_size_sum(data: &Data) -> TokenStream {
|
||||
let recurse = fields.named.iter().map(|f| {
|
||||
let name = &f.ident;
|
||||
quote_spanned! {f.span()=>
|
||||
::heapsize::HeapSize::heap_size_of_children(&self.#name)
|
||||
heapsize::HeapSize::heap_size_of_children(&self.#name)
|
||||
}
|
||||
});
|
||||
quote! {
|
||||
@ -78,7 +78,7 @@ fn heap_size_sum(data: &Data) -> TokenStream {
|
||||
let recurse = fields.unnamed.iter().enumerate().map(|(i, f)| {
|
||||
let index = Index::from(i);
|
||||
quote_spanned! {f.span()=>
|
||||
::heapsize::HeapSize::heap_size_of_children(&self.#index)
|
||||
heapsize::HeapSize::heap_size_of_children(&self.#index)
|
||||
}
|
||||
});
|
||||
quote! {
|
||||
|
@ -98,7 +98,7 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
|
||||
// 10 | static ref PTR: *const () = &();
|
||||
// | ^^^^^^^^^ `*const ()` cannot be shared between threads safely
|
||||
let assert_sync = quote_spanned! {ty.span()=>
|
||||
struct _AssertSync where #ty: ::std::marker::Sync;
|
||||
struct _AssertSync where #ty: std::marker::Sync;
|
||||
};
|
||||
|
||||
// Check for Sized. Not vital to check here, but the error message is less
|
||||
@ -111,7 +111,7 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
|
||||
// 10 | static ref A: str = "";
|
||||
// | ^^^ `str` does not have a constant size known at compile-time
|
||||
let assert_sized = quote_spanned! {ty.span()=>
|
||||
struct _AssertSized where #ty: ::std::marker::Sized;
|
||||
struct _AssertSized where #ty: std::marker::Sized;
|
||||
};
|
||||
|
||||
let init_ptr = quote_spanned! {init.span()=>
|
||||
@ -121,14 +121,14 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
|
||||
let expanded = quote! {
|
||||
#visibility struct #name;
|
||||
|
||||
impl ::std::ops::Deref for #name {
|
||||
impl std::ops::Deref for #name {
|
||||
type Target = #ty;
|
||||
|
||||
fn deref(&self) -> &#ty {
|
||||
#assert_sync
|
||||
#assert_sized
|
||||
|
||||
static ONCE: ::std::sync::Once = ::std::sync::ONCE_INIT;
|
||||
static ONCE: std::sync::Once = std::sync::ONCE_INIT;
|
||||
static mut VALUE: *mut #ty = 0 as *mut #ty;
|
||||
|
||||
unsafe {
|
||||
|
Loading…
Reference in New Issue
Block a user