Skip to content

Commit

Permalink
Merge pull request #31 from LukasKalbertodt/fix-for-2018-rc1
Browse files Browse the repository at this point in the history
Fix for Rust 2018 RC1
  • Loading branch information
KodrAus authored Sep 22, 2018
2 parents 6bdb094 + 058973f commit 6a50edc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition"]

[package]
name = "auto_impl"
version = "0.2.0"
Expand All @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
Expand All @@ -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<OurAttr, ()> {
pub(crate) fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
assert!(is_our_attr(attr));

// Get the body of the attribute (which has to be a ground, because we
Expand Down Expand Up @@ -119,6 +119,6 @@ crate fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
/// 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<ProxyType>),
}
20 changes: 10 additions & 10 deletions src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -86,19 +86,19 @@ crate struct Diagnostic {
// required.
#[cfg(not(feature = "nightly"))]
impl Diagnostic {
crate fn note(mut self, msg: impl Into<String>) -> Diagnostic {
pub(crate) fn note(mut self, msg: impl Into<String>) -> Diagnostic {
self.msg += &format!("\n\nnote: {}", msg.into());
self
}

crate fn span_note(mut self, _: Span, msg: impl Into<String>) -> Diagnostic {
pub(crate) fn span_note(mut self, _: Span, msg: impl Into<String>) -> 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;
Expand Down Expand Up @@ -149,28 +149,28 @@ 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())
}

/// On nightly, we don't use and don't have a strange global variable. Instead,
/// 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<String>) -> Diagnostic;
}

impl SpanExt for Span {
#[cfg(feature = "nightly")]
fn err(self, msg: impl Into<String>) -> Diagnostic {
Diagnostic::spanned(self, ::proc_macro::Level::Error, msg)
Diagnostic::spanned(self, crate::proc_macro::Level::Error, msg)
}

#[cfg(not(feature = "nightly"))]
Expand Down
4 changes: 2 additions & 2 deletions src/gen.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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<TokenStream2, ()> {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/proxy.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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<Vec<ProxyType>, ()> {
pub(crate) fn parse_types(args: TokenStream) -> Result<Vec<ProxyType>, ()> {
let mut out = Vec::new();
let mut iter = args.into_iter().peekable();

Expand Down Expand Up @@ -141,7 +141,7 @@ fn eat_type(iter: &mut Peekable<token_stream::IntoIter>) -> Result<ProxyType, ()

#[cfg(test)]
mod test {
use proc_macro::TokenStream;
use crate::proc_macro::TokenStream;

use super::parse_types;

Expand Down
2 changes: 1 addition & 1 deletion src/spanned.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proc_macro::{Span, TokenStream};
use crate::proc_macro::{Span, TokenStream};
use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;

Expand Down

0 comments on commit 6a50edc

Please sign in to comment.