~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/rust/macros/pinned_drop.rs

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /rust/macros/pinned_drop.rs (Version linux-6.12-rc7) and /rust/macros/pinned_drop.rs (Version linux-6.9.12)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php