1 // SPDX-License-Identifier: Apache-2.0 OR MIT 2 3 use proc_macro::{TokenStream, TokenTree}; 4 5 pub(crate) fn pinned_drop(_args: TokenStream, 6 let mut toks = input.into_iter().collect:: 7 assert!(!toks.is_empty()); 8 // Ensure that we have an `impl` item. 9 assert!(matches!(&toks[0], TokenTree::Iden 10 // Ensure that we are implementing `Pinned 11 let mut nesting: usize = 0; 12 let mut pinned_drop_idx = None; 13 for (i, tt) in toks.iter().enumerate() { 14 match tt { 15 TokenTree::Punct(p) if p.as_char() 16 nesting += 1; 17 } 18 TokenTree::Punct(p) if p.as_char() 19 nesting = nesting.checked_sub( 20 continue; 21 } 22 _ => {} 23 } 24 if i >= 1 && nesting == 0 { 25 // Found the end of the generics, 26 assert!( 27 matches!(tt, TokenTree::Ident( 28 "expected 'PinnedDrop', found: 29 tt 30 ); 31 pinned_drop_idx = Some(i); 32 break; 33 } 34 } 35 let idx = pinned_drop_idx 36 .unwrap_or_else(|| panic!("Expected an 37 // Fully qualify the `PinnedDrop`, as to a 38 toks.splice(idx..idx, quote!(::kernel::ini 39 // Take the `{}` body and call the declara 40 if let Some(TokenTree::Group(last)) = toks 41 let last = last.stream(); 42 quote!(::kernel::__pinned_drop! { 43 @impl_sig(#(#toks)*), 44 @impl_body(#last), 45 }) 46 } else { 47 TokenStream::from_iter(toks) 48 } 49 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.