Skip to content

Commit

Permalink
Merge pull request #82 from auto-impl-rs/chore/fmt
Browse files Browse the repository at this point in the history
Run fmt
  • Loading branch information
KodrAus authored Jun 1, 2022
2 parents 8a830f1 + aac67de commit 708a4c5
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 61 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ jobs:
- name: Run compile-fail tests
if: matrix.rust-version == 'stable'
run: cargo test -- ui_compile_fail

- name: Build with nightly feature
if: matrix.rust-version == 'nightly'
run: cargo build --features=nightly
- name: Run tests with nightly feature
if: matrix.rust-version == 'nightly'
run: cargo test --features=nightly -- --skip ui_compile_fail
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ rust-version = "1.37"
[lib]
proc-macro = true

[features]
nightly = []

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
2 changes: 0 additions & 2 deletions examples/error_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use auto_impl::auto_impl;


// Shows the error message for the case that `#[auto_impl]` was used with
// incorrect proxy types. Only proxy types like `&` and `Box` are allowed. Add
// this next line to see the error!
Expand All @@ -24,5 +23,4 @@ struct Bar {
x: u32,
}


fn main() {}
3 changes: 0 additions & 3 deletions examples/greet_closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use auto_impl::auto_impl;


/// This simple trait can be implemented for `Fn` types, but not for `FnMut` or
/// `FnOnce` types. The latter two types require a mutable reference to `self`
/// or a `self` by value to be called, but `greet()` only has an immutable
Expand All @@ -21,13 +20,11 @@ trait Greeter {
fn greet(&self, name: &str);
}


fn greet_people(greeter: impl Greeter) {
greeter.greet("Anna");
greeter.greet("Bob");
}


fn main() {
// We can simply pass a closure here, since this specific closure
// implements `Fn(&str)` and therefore also `Greeter`. Note that we need
Expand Down
1 change: 0 additions & 1 deletion examples/keep_default_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! type.
use auto_impl::auto_impl;


#[auto_impl(&, Box)]
trait Foo {
fn required(&self) -> String;
Expand Down
1 change: 0 additions & 1 deletion examples/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::Display;

use auto_impl::auto_impl;


/// This trait can be implemented for all reference or pointer types: &, &mut,
/// Box, Rc and Arc.
///
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ unstable_features = true

blank_lines_upper_bound = 3
format_macro_matchers = true
merge_imports = true
imports_granularity="Crate"
normalize_comments = true
reorder_impl_items = true
16 changes: 0 additions & 16 deletions src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use syn::{
Block, Ident, ItemTrait, Lifetime,
};


/// The type parameter used in the proxy type. Usually, one would just use `T`,
/// but this could conflict with type parameters on the trait.
///
Expand All @@ -21,7 +20,6 @@ const PROXY_TY_PARAM_NAME: &str = "__AutoImplProxyT";
/// `&mut`. For more information see `PROXY_TY_PARAM_NAME`.
const PROXY_LT_PARAM_NAME: &str = "'__auto_impl_proxy_lifetime";


/// We need to introduce our own type and lifetime parameter. Regardless of
/// what kind of hygiene we use for the parameter, it would be nice (for docs
/// and compiler errors) if the names are as simple as possible ('a and T, for
Expand Down Expand Up @@ -68,7 +66,6 @@ pub(crate) fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifeti
};
visit_item_trait(&mut visitor, trait_def);


fn char_to_ident(c: u8) -> Ident {
let arr = [c];
let s = ::std::str::from_utf8(&arr).unwrap();
Expand All @@ -95,19 +92,6 @@ pub(crate) fn find_suitable_param_names(trait_def: &ItemTrait) -> (Ident, Lifeti
(ty_name, lt)
}

/// On nightly, we use `def_site` hygiene which puts our names into another
/// universe than the names of the user. This is not strictly required as our
/// name is already pretty much guaranteed to not conflict with another name,
/// but this is cleaner and just the correct thing to do.
#[cfg(feature = "nightly")]
fn param_span() -> Span2 {
crate::proc_macro::Span::def_site().into()
}

/// On stable, we use `call_site()` hygiene. That means that our names could
/// theoretically collide with names of the user. But we made sure this doesn't
/// happen.
#[cfg(not(feature = "nightly"))]
fn param_span() -> Span2 {
Span2::call_site()
}
26 changes: 0 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,31 +202,6 @@
//! }
//! }
//! ```
//!
//!
//! # The `nightly` feature gate
//!
//! By default, this crate compiles on stable. If you don't need stable support,
//! you can enable the `nightly` feature of this crate:
//!
//! ```toml
//! [dependencies]
//! auto_impl = { version = "*", features = ["nightly"] }
//! ```
//!
//! The nightly feature enables a few additional features that are not
//! available on stable yet. Currently, you get these advantages:
//! - All idents generated by auto_impl use the `def_site` hygiene and
//! therefore will never ever have name collisions with user written idents.
//! Note that `auto_impl` already (even without nightly feature) takes care
//! that idents never collide, if possible. But `def_site` hygiene is still
//! technically the more correct solution.
#![cfg_attr(
feature = "nightly",
feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)
)]

extern crate proc_macro;
#[macro_use]
Expand All @@ -237,7 +212,6 @@ use proc_macro2::TokenStream as TokenStream2;
use proc_macro_error::{abort_call_site, proc_macro_error, set_dummy};
use quote::ToTokens;


mod analyze;
mod attr;
mod gen;
Expand Down
1 change: 0 additions & 1 deletion src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ fn eat_type(iter: &mut Peekable<token_stream::IntoIter>) -> Result<ProxyType, ()
Ok(ty)
}


// Right now, we can't really write useful tests. Many functions from
// `proc_macro` use a compiler internal session. This session is only valid
// when we were actually called as a proc macro. We need to add tests once
Expand Down

0 comments on commit 708a4c5

Please sign in to comment.