Skip to content

Commit

Permalink
Merge pull request #25 from dtolnay/up
Browse files Browse the repository at this point in the history
Update to proc-macro-hack 0.5
  • Loading branch information
dtolnay authored Nov 29, 2018
2 parents 200ac9d + cd5ce1c commit 5017e59
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: rust

matrix:
include:
- rust: 1.15.0
- rust: 1.30.0
- rust: stable
- rust: beta
- rust: nightly
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ unstable = ["indoc-impl/unstable"]

[dependencies]
indoc-impl = { version = "0.2", path = "impl" }
proc-macro-hack = "0.4"
proc-macro-hack = "0.5"

[workspace]
members = ["impl", "tests", "unindent"]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Release notes are available under [GitHub releases](https://github.com/dtolnay/i
## Using Indoc

```rust
#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
let testing = indoc!("
Expand All @@ -36,8 +36,8 @@ fn main() {
Indoc also works with raw string literals:

```rust
#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
let testing = indoc!(r#"
Expand All @@ -54,8 +54,8 @@ fn main() {
And byte string literals:

```rust
#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
let testing = indoc!(b"
Expand Down
2 changes: 1 addition & 1 deletion impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unstable = []
proc-macro = true

[dependencies]
proc-macro-hack = "0.4"
proc-macro-hack = "0.5"
proc-macro2 = { version = "0.4", default-features = false }
quote = { version = "0.6", default-features = false }
syn = { version = "0.15", default-features = false, features = ["derive", "parsing", "printing"] }
Expand Down
34 changes: 8 additions & 26 deletions impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,30 @@

#![doc(html_root_url = "https://docs.rs/indoc-impl/0.2.8")]

#[cfg(feature = "unstable")]
extern crate proc_macro;

#[cfg(not(feature = "unstable"))]
#[macro_use]
extern crate proc_macro_hack;

#[cfg(not(feature = "unstable"))]
use proc_macro_hack::proc_macro_hack;

extern crate proc_macro2;
extern crate syn;

#[macro_use]
extern crate quote;
use quote::quote;

extern crate unindent;
use unindent::*;

use proc_macro2::TokenStream;
use syn::{Lit, LitByteStr, LitStr};

use std::fmt::Debug;
use std::str::FromStr;

#[cfg(feature = "unstable")]
#[proc_macro]
#[cfg_attr(feature = "unstable", proc_macro)]
#[cfg_attr(not(feature = "unstable"), proc_macro_hack)]
pub fn indoc(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand(&input)
}

#[cfg(not(feature = "unstable"))]
proc_macro_expr_impl! {
pub fn indoc_impl(input: &str) -> String {
expand(input)
}
}

fn expand<T, R>(input: &T) -> R
where
T: ?Sized + ToString,
R: FromStr,
R::Err: Debug,
{
let source = input.to_string().parse::<TokenStream>().unwrap();
let source = TokenStream::from(input);

let len = source.clone().into_iter().count();
if len != 1 {
Expand Down Expand Up @@ -80,5 +62,5 @@ where
}
};

quote!(#lit).to_string().parse().unwrap()
proc_macro::TokenStream::from(quote!(#lit))
}
27 changes: 7 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
doc = " #![feature(proc_macro_hygiene)]"
)]
#![cfg_attr(feature = "unstable", doc = "")]
#![cfg_attr(not(feature = "unstable"), doc = " #[macro_use]")]
//! extern crate indoc;
#![cfg_attr(feature = "unstable", doc = " use indoc::indoc;")]
//! use indoc::indoc;
//!
//! fn main() {
//! let testing = indoc!("
Expand All @@ -49,9 +48,8 @@
doc = " #![feature(proc_macro_hygiene)]"
)]
#![cfg_attr(feature = "unstable", doc = "")]
#![cfg_attr(not(feature = "unstable"), doc = " #[macro_use]")]
//! extern crate indoc;
#![cfg_attr(feature = "unstable", doc = " use indoc::indoc;")]
//! use indoc::indoc;
//!
//! fn main() {
//! let testing = indoc!(r#"
Expand All @@ -73,9 +71,8 @@
doc = " #![feature(proc_macro_hygiene)]"
)]
#![cfg_attr(feature = "unstable", doc = "")]
#![cfg_attr(not(feature = "unstable"), doc = " #[macro_use]")]
//! extern crate indoc;
#![cfg_attr(feature = "unstable", doc = " use indoc::indoc;")]
//! use indoc::indoc;
//!
//! fn main() {
//! let testing = indoc!(b"
Expand Down Expand Up @@ -117,22 +114,12 @@
#![no_std]

#[cfg(not(feature = "unstable"))]
#[macro_use]
extern crate proc_macro_hack;

#[allow(unused_imports)]
#[cfg_attr(not(feature = "unstable"), macro_use)]
pub extern crate indoc_impl;

#[cfg(feature = "unstable")]
pub use indoc_impl::indoc;
extern crate indoc_impl;

#[cfg(not(feature = "unstable"))]
#[doc(hidden)]
pub use indoc_impl::*;
use proc_macro_hack::proc_macro_hack;

#[cfg(not(feature = "unstable"))]
proc_macro_expr_decl! {
#[doc(hidden)]
indoc! => indoc_impl
}
#[cfg_attr(not(feature = "unstable"), proc_macro_hack)]
pub use indoc_impl::indoc;
3 changes: 0 additions & 3 deletions tests/tests/run-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
#![cfg_attr(feature = "unstable", feature(proc_macro_hygiene))]
#![cfg_attr(rustfmt, rustfmt_skip)]

#[cfg_attr(not(feature = "unstable"), macro_use)]
extern crate indoc;

#[cfg(feature = "unstable")]
use indoc::indoc;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-stable/no-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!();
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-stable/non-lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!(fail);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-stable/non-string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!(64);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-stable/two-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!("
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-unstable/no-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!();
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-unstable/non-lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!(fail);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-unstable/non-string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!(64);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/ui-unstable/two-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate indoc;
use indoc::indoc;

fn main() {
indoc!("
Expand Down

0 comments on commit 5017e59

Please sign in to comment.