Skip to content

Commit 6a50edc

Browse files
authored
Merge pull request #31 from LukasKalbertodt/fix-for-2018-rc1
Fix for Rust 2018 RC1
2 parents 6bdb094 + 058973f commit 6a50edc

File tree

8 files changed

+27
-28
lines changed

8 files changed

+27
-28
lines changed

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["edition"]
2-
31
[package]
42
name = "auto_impl"
53
version = "0.2.0"
@@ -15,7 +13,7 @@ keywords = ["plugin"]
1513
categories = ["development-tools"]
1614
readme = "README.md"
1715
autotests = true
18-
edition = '2018'
16+
edition = "2018"
1917

2018
[badges]
2119
travis-ci = { repository = "KodrAus/auto_impl" }

src/analyze.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const PROXY_LT_PARAM_NAME: &str = "'__auto_impl_proxy_lifetime";
3636
/// name, we'll use the ugly `PROXY_TY_PARAM_NAME` and `PROXY_LT_PARAM_NAME`.
3737
///
3838
/// This method returns two idents: (type_parameter, lifetime_parameter).
39-
crate fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) {
39+
pub(crate) fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) {
4040
// Define the visitor that just collects names
4141
struct IdentCollector<'ast> {
4242
ty_names: HashSet<&'ast Ident>,
@@ -101,7 +101,7 @@ crate fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifetime) {
101101
/// but this is cleaner and just the correct thing to do.
102102
#[cfg(feature = "nightly")]
103103
fn param_span() -> Span2 {
104-
::proc_macro::Span::def_site().into()
104+
crate::proc_macro::Span::def_site().into()
105105
}
106106

107107
/// On stable, we use `call_site()` hygiene. That means that our names could

src/attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616

1717
/// Removes all `#[auto_impl]` attributes that are attached to methods of the
1818
/// given trait.
19-
crate fn remove_our_attrs(trait_def: &mut syn::ItemTrait) {
19+
pub(crate) fn remove_our_attrs(trait_def: &mut syn::ItemTrait) {
2020
struct AttrRemover;
2121
impl VisitMut for AttrRemover {
2222
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) {
2929

3030
/// Checks if the given attribute is "our" attribute. That means that it's path
3131
/// is `auto_impl`.
32-
crate fn is_our_attr(attr: &Attribute) -> bool {
32+
pub(crate) fn is_our_attr(attr: &Attribute) -> bool {
3333
attr.path.segments.len() == 1
3434
&& attr.path.segments.iter().next().map(|seg| {
3535
seg.ident == "auto_impl" && seg.arguments.is_empty()
@@ -40,7 +40,7 @@ crate fn is_our_attr(attr: &Attribute) -> bool {
4040
/// attributes. If it's invalid, an error is emitted and `Err(())` is returned.
4141
/// You have to make sure that `attr` is one of our attrs with `is_our_attr`
4242
/// before calling this function!
43-
crate fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
43+
pub(crate) fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
4444
assert!(is_our_attr(attr));
4545

4646
// 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<OurAttr, ()> {
119119
/// Attributes of the form `#[auto_impl(...)]` that can be attached to items of
120120
/// the trait.
121121
#[derive(Clone, PartialEq, Debug)]
122-
crate enum OurAttr {
122+
pub(crate) enum OurAttr {
123123
KeepDefaultFor(Vec<ProxyType>),
124124
}

src/diag.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! `.err()` on spans.
1313
//!
1414
15-
use proc_macro::{Span, TokenStream};
15+
use crate::proc_macro::{Span, TokenStream};
1616

1717

1818
/// Extension trait that adds a convenience method to `Diagnostic`. This is
@@ -44,10 +44,10 @@ impl DiagnosticExt for Diagnostic {
4444
// `Diagnostic`.
4545

4646
#[cfg(feature = "nightly")]
47-
crate type Diagnostic = ::proc_macro::Diagnostic;
47+
pub(crate) type Diagnostic = crate::proc_macro::Diagnostic;
4848

4949
#[cfg(not(feature = "nightly"))]
50-
crate struct Diagnostic {
50+
pub(crate) struct Diagnostic {
5151
span: Span,
5252
msg: String,
5353
}
@@ -86,19 +86,19 @@ crate struct Diagnostic {
8686
// required.
8787
#[cfg(not(feature = "nightly"))]
8888
impl Diagnostic {
89-
crate fn note(mut self, msg: impl Into<String>) -> Diagnostic {
89+
pub(crate) fn note(mut self, msg: impl Into<String>) -> Diagnostic {
9090
self.msg += &format!("\n\nnote: {}", msg.into());
9191
self
9292
}
9393

94-
crate fn span_note(mut self, _: Span, msg: impl Into<String>) -> Diagnostic {
94+
pub(crate) fn span_note(mut self, _: Span, msg: impl Into<String>) -> Diagnostic {
9595
// With out span fake method, we can only handle one span. We take the
9696
// one of the original error and ignore additional ones.
9797
self.msg += &format!("\n\nnote: {}", msg.into());
9898
self
9999
}
100100

101-
crate fn emit(self) {
101+
pub(crate) fn emit(self) {
102102
// Create the error token stream that contains the `compile_error!()`
103103
// invocation.
104104
let msg = &self.msg;
@@ -149,28 +149,28 @@ thread_local! {
149149

150150
/// On stable, we just copy the error token streams from the global variable.
151151
#[cfg(not(feature = "nightly"))]
152-
crate fn error_tokens() -> TokenStream {
152+
pub(crate) fn error_tokens() -> TokenStream {
153153
ERROR_TOKENS.with(|toks| toks.borrow().iter().cloned().collect())
154154
}
155155

156156
/// On nightly, we don't use and don't have a strange global variable. Instead,
157157
/// we just return an empty token stream. That's not a problem because all of
158158
/// our errors were already printed.
159159
#[cfg(feature = "nightly")]
160-
crate fn error_tokens() -> TokenStream {
160+
pub(crate) fn error_tokens() -> TokenStream {
161161
TokenStream::new()
162162
}
163163

164164
/// Extension trait to add the `err()` method to `Span`. This makes it easy to
165165
/// start a `Diagnostic` from a span.
166-
crate trait SpanExt {
166+
pub(crate) trait SpanExt {
167167
fn err(self, msg: impl Into<String>) -> Diagnostic;
168168
}
169169

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

176176
#[cfg(not(feature = "nightly"))]

src/gen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use proc_macro::Span;
1+
use crate::proc_macro::Span;
22
use proc_macro2::TokenStream as TokenStream2;
33
use quote::{ToTokens, TokenStreamExt};
44
use syn::{
@@ -18,7 +18,7 @@ use crate::{
1818

1919
/// Generates one complete impl of the given trait for each of the given proxy
2020
/// types. All impls are returned as token stream.
21-
crate fn gen_impls(
21+
pub(crate) fn gen_impls(
2222
proxy_types: &[ProxyType],
2323
trait_def: &syn::ItemTrait,
2424
) -> Result<TokenStream2, ()> {

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
#![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic, proc_macro_span))]
66

7+
extern crate proc_macro;
78
#[macro_use]
89
extern crate quote;
910

10-
use proc_macro::TokenStream;
11+
use crate::proc_macro::TokenStream;
1112
use proc_macro2::TokenStream as TokenStream2;
1213
use quote::ToTokens;
1314

src/proxy.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::iter::Peekable;
22

3-
use proc_macro::{token_stream, TokenStream, TokenTree};
3+
use crate::proc_macro::{token_stream, TokenStream, TokenTree};
44

55
use crate::diag::SpanExt;
66

77
/// Types for which a trait can automatically be implemented.
88
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9-
crate enum ProxyType {
9+
pub(crate) enum ProxyType {
1010
Ref,
1111
RefMut,
1212
Arc,
@@ -18,7 +18,7 @@ crate enum ProxyType {
1818
}
1919

2020
impl ProxyType {
21-
crate fn is_fn(&self) -> bool {
21+
pub(crate) fn is_fn(&self) -> bool {
2222
match *self {
2323
ProxyType::Fn | ProxyType::FnMut | ProxyType::FnOnce => true,
2424
_ => false,
@@ -34,7 +34,7 @@ impl ProxyType {
3434
///
3535
/// If the given TokenStream is not valid, errors are emitted as appropriate
3636
/// and `Err(())` is returned.
37-
crate fn parse_types(args: TokenStream) -> Result<Vec<ProxyType>, ()> {
37+
pub(crate) fn parse_types(args: TokenStream) -> Result<Vec<ProxyType>, ()> {
3838
let mut out = Vec::new();
3939
let mut iter = args.into_iter().peekable();
4040

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

142142
#[cfg(test)]
143143
mod test {
144-
use proc_macro::TokenStream;
144+
use crate::proc_macro::TokenStream;
145145

146146
use super::parse_types;
147147

src/spanned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use proc_macro::{Span, TokenStream};
1+
use crate::proc_macro::{Span, TokenStream};
22
use proc_macro2::TokenStream as TokenStream2;
33
use quote::ToTokens;
44

0 commit comments

Comments
 (0)