diff --git a/Cargo.toml b/Cargo.toml index f733d79..ae0fafe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["edition"] - [package] name = "auto_impl" version = "0.2.0" @@ -15,7 +13,7 @@ keywords = ["plugin"] categories = ["development-tools"] readme = "README.md" autotests = true -edition = '2018' +edition = "2018" [badges] travis-ci = { repository = "KodrAus/auto_impl" } diff --git a/src/analyze.rs b/src/analyze.rs index d8d44b8..afc83c4 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -36,7 +36,7 @@ const PROXY_LT_PARAM_NAME: &str = "'__auto_impl_proxy_lifetime"; /// name, we'll use the ugly `PROXY_TY_PARAM_NAME` and `PROXY_LT_PARAM_NAME`. /// /// This method returns two idents: (type_parameter, lifetime_parameter). -crate fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) { +pub(crate) fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) { // Define the visitor that just collects names struct IdentCollector<'ast> { ty_names: HashSet<&'ast Ident>, @@ -101,7 +101,7 @@ crate fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) { /// but this is cleaner and just the correct thing to do. #[cfg(feature = "nightly")] fn param_span() -> Span2 { - ::proc_macro::Span::def_site().into() + crate::proc_macro::Span::def_site().into() } /// On stable, we use `call_site()` hygiene. That means that our names could diff --git a/src/attr.rs b/src/attr.rs index a350d97..98e3845 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -16,7 +16,7 @@ use crate::{ /// Removes all `#[auto_impl]` attributes that are attached to methods of the /// given trait. -crate fn remove_our_attrs(trait_def: &mut syn::ItemTrait) { +pub(crate) fn remove_our_attrs(trait_def: &mut syn::ItemTrait) { struct AttrRemover; impl VisitMut for AttrRemover { fn visit_trait_item_method_mut(&mut self, m: &mut TraitItemMethod) { @@ -29,7 +29,7 @@ crate fn remove_our_attrs(trait_def: &mut syn::ItemTrait) { /// Checks if the given attribute is "our" attribute. That means that it's path /// is `auto_impl`. -crate fn is_our_attr(attr: &Attribute) -> bool { +pub(crate) fn is_our_attr(attr: &Attribute) -> bool { attr.path.segments.len() == 1 && attr.path.segments.iter().next().map(|seg| { seg.ident == "auto_impl" && seg.arguments.is_empty() @@ -40,7 +40,7 @@ crate fn is_our_attr(attr: &Attribute) -> bool { /// attributes. If it's invalid, an error is emitted and `Err(())` is returned. /// You have to make sure that `attr` is one of our attrs with `is_our_attr` /// before calling this function! -crate fn parse_our_attr(attr: &Attribute) -> Result { +pub(crate) fn parse_our_attr(attr: &Attribute) -> Result { assert!(is_our_attr(attr)); // Get the body of the attribute (which has to be a ground, because we @@ -119,6 +119,6 @@ crate fn parse_our_attr(attr: &Attribute) -> Result { /// Attributes of the form `#[auto_impl(...)]` that can be attached to items of /// the trait. #[derive(Clone, PartialEq, Debug)] -crate enum OurAttr { +pub(crate) enum OurAttr { KeepDefaultFor(Vec), } diff --git a/src/diag.rs b/src/diag.rs index 1ffb0de..20cf06c 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -12,7 +12,7 @@ //! `.err()` on spans. //! -use proc_macro::{Span, TokenStream}; +use crate::proc_macro::{Span, TokenStream}; /// Extension trait that adds a convenience method to `Diagnostic`. This is @@ -44,10 +44,10 @@ impl DiagnosticExt for Diagnostic { // `Diagnostic`. #[cfg(feature = "nightly")] -crate type Diagnostic = ::proc_macro::Diagnostic; +pub(crate) type Diagnostic = crate::proc_macro::Diagnostic; #[cfg(not(feature = "nightly"))] -crate struct Diagnostic { +pub(crate) struct Diagnostic { span: Span, msg: String, } @@ -86,19 +86,19 @@ crate struct Diagnostic { // required. #[cfg(not(feature = "nightly"))] impl Diagnostic { - crate fn note(mut self, msg: impl Into) -> Diagnostic { + pub(crate) fn note(mut self, msg: impl Into) -> Diagnostic { self.msg += &format!("\n\nnote: {}", msg.into()); self } - crate fn span_note(mut self, _: Span, msg: impl Into) -> Diagnostic { + pub(crate) fn span_note(mut self, _: Span, msg: impl Into) -> Diagnostic { // With out span fake method, we can only handle one span. We take the // one of the original error and ignore additional ones. self.msg += &format!("\n\nnote: {}", msg.into()); self } - crate fn emit(self) { + pub(crate) fn emit(self) { // Create the error token stream that contains the `compile_error!()` // invocation. let msg = &self.msg; @@ -149,7 +149,7 @@ thread_local! { /// On stable, we just copy the error token streams from the global variable. #[cfg(not(feature = "nightly"))] -crate fn error_tokens() -> TokenStream { +pub(crate) fn error_tokens() -> TokenStream { ERROR_TOKENS.with(|toks| toks.borrow().iter().cloned().collect()) } @@ -157,20 +157,20 @@ crate fn error_tokens() -> TokenStream { /// we just return an empty token stream. That's not a problem because all of /// our errors were already printed. #[cfg(feature = "nightly")] -crate fn error_tokens() -> TokenStream { +pub(crate) fn error_tokens() -> TokenStream { TokenStream::new() } /// Extension trait to add the `err()` method to `Span`. This makes it easy to /// start a `Diagnostic` from a span. -crate trait SpanExt { +pub(crate) trait SpanExt { fn err(self, msg: impl Into) -> Diagnostic; } impl SpanExt for Span { #[cfg(feature = "nightly")] fn err(self, msg: impl Into) -> Diagnostic { - Diagnostic::spanned(self, ::proc_macro::Level::Error, msg) + Diagnostic::spanned(self, crate::proc_macro::Level::Error, msg) } #[cfg(not(feature = "nightly"))] diff --git a/src/gen.rs b/src/gen.rs index 17fa298..e768a90 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -1,4 +1,4 @@ -use proc_macro::Span; +use crate::proc_macro::Span; use proc_macro2::TokenStream as TokenStream2; use quote::{ToTokens, TokenStreamExt}; use syn::{ @@ -18,7 +18,7 @@ use crate::{ /// Generates one complete impl of the given trait for each of the given proxy /// types. All impls are returned as token stream. -crate fn gen_impls( +pub(crate) fn gen_impls( proxy_types: &[ProxyType], trait_def: &syn::ItemTrait, ) -> Result { diff --git a/src/lib.rs b/src/lib.rs index db2b794..109b025 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,11 @@ #![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic, proc_macro_span))] +extern crate proc_macro; #[macro_use] extern crate quote; -use proc_macro::TokenStream; +use crate::proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::ToTokens; diff --git a/src/proxy.rs b/src/proxy.rs index 7ac47ae..16dfaab 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -1,12 +1,12 @@ use std::iter::Peekable; -use proc_macro::{token_stream, TokenStream, TokenTree}; +use crate::proc_macro::{token_stream, TokenStream, TokenTree}; use crate::diag::SpanExt; /// Types for which a trait can automatically be implemented. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -crate enum ProxyType { +pub(crate) enum ProxyType { Ref, RefMut, Arc, @@ -18,7 +18,7 @@ crate enum ProxyType { } impl ProxyType { - crate fn is_fn(&self) -> bool { + pub(crate) fn is_fn(&self) -> bool { match *self { ProxyType::Fn | ProxyType::FnMut | ProxyType::FnOnce => true, _ => false, @@ -34,7 +34,7 @@ impl ProxyType { /// /// If the given TokenStream is not valid, errors are emitted as appropriate /// and `Err(())` is returned. -crate fn parse_types(args: TokenStream) -> Result, ()> { +pub(crate) fn parse_types(args: TokenStream) -> Result, ()> { let mut out = Vec::new(); let mut iter = args.into_iter().peekable(); @@ -141,7 +141,7 @@ fn eat_type(iter: &mut Peekable) -> Result