Skip to content

Commit

Permalink
Remove doc = $ident attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 7, 2020
1 parent f0c0da8 commit 4d9b737
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
39 changes: 0 additions & 39 deletions src/args.rs

This file was deleted.

18 changes: 6 additions & 12 deletions src/expand.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::args::Args;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::visit_mut::{self, VisitMut};
Expand All @@ -9,7 +8,7 @@ use syn::{

type Punctuated = syn::punctuated::Punctuated<Field, Token![,]>;

pub fn readonly(args: Args, input: DeriveInput) -> Result<TokenStream> {
pub fn readonly(input: DeriveInput) -> Result<TokenStream> {
let call_site = Span::call_site();

match &input.data {
Expand All @@ -27,12 +26,10 @@ pub fn readonly(args: Args, input: DeriveInput) -> Result<TokenStream> {

let indices = find_and_strip_readonly_attrs(&mut input);

let original_input = args.doc_cfg.as_ref().map(|doc_cfg| {
quote! {
#[cfg(all(#doc_cfg, doc))]
#input
}
});
let original_input = quote! {
#[cfg(doc)]
#input
};

if !has_defined_repr(&input) {
input.attrs.push(parse_quote!(#[repr(C)]));
Expand Down Expand Up @@ -69,10 +66,7 @@ pub fn readonly(args: Args, input: DeriveInput) -> Result<TokenStream> {
readonly.ident = Ident::new(&format!("ReadOnly{}", input.ident), call_site);
let readonly_ident = &readonly.ident;

if let Some(doc_cfg) = args.doc_cfg {
let not_doc_cfg = parse_quote!(#[cfg(not(all(#doc_cfg, doc)))]);
input.attrs.insert(0, not_doc_cfg);
}
input.attrs.insert(0, parse_quote!(#[cfg(not(doc))]));

Ok(quote! {
#original_input
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,20 @@

extern crate proc_macro;

mod args;
mod expand;

use crate::args::Args;
use proc_macro::TokenStream;
use quote::quote;
use syn::parse::Nothing;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_attribute]
pub fn make(args: TokenStream, tokens: TokenStream) -> TokenStream {
let original = tokens.clone();
let args = parse_macro_input!(args as Args);
parse_macro_input!(args as Nothing);
let input = parse_macro_input!(tokens as DeriveInput);

expand::readonly(args, input)
expand::readonly(input)
.unwrap_or_else(|e| {
let original = proc_macro2::TokenStream::from(original);
let compile_error = e.to_compile_error();
Expand Down

0 comments on commit 4d9b737

Please sign in to comment.