382 Commits

Author SHA1 Message Date
David Tolnay
298b5a37bd
Make pounded_var_names nonrecursive 2019-07-18 12:02:09 -07:00
David Tolnay
142c28cb26
Simplify pounded_var_names 2019-07-18 11:37:43 -07:00
David Tolnay
b044307915
More compact way to deal with unreachable code warning 2019-07-18 11:34:07 -07:00
David Tolnay
b3388027b9
Simplify quote_bind_into_iter 2019-07-18 11:26:22 -07:00
David Tolnay
831532f965
Simplify quote_bind_next_or_break 2019-07-18 11:23:40 -07:00
David Tolnay
2e5ebb7a9c
Drop support for compilers without i128 2019-07-18 11:20:55 -07:00
David Tolnay
7977715292
Rename the ident used for interpolated vars 2019-07-18 11:14:10 -07:00
David Tolnay
8abb94d498
Quote $sep as a single token 2019-07-18 11:10:58 -07:00
David Tolnay
7972c73c87
Flatten a layer of calls in quote_token_with_context
This improves expand time of serde_derive by 10% as measured by:
$ time cargo expand --ugly >/dev/null
2019-07-18 10:57:43 -07:00
David Tolnay
3703744017
Resolve conflicts in 112 merge 2019-07-18 10:54:50 -07:00
David Tolnay
c26e8203fc
Merge pull request 112 from qnighy/constant-depth 2019-07-18 10:53:53 -07:00
David Tolnay
4c1e82d6ac
Add tests for doc comments and attributes 2019-07-18 10:38:28 -07:00
David Tolnay
62fb4bd44d
Replace local_inner_macros with $crate 2019-07-18 09:30:44 -07:00
David Tolnay
3aeee7f849
Stricter about trailing commas in format_ident
The implementation previously allowed multiple trailing commas.
2019-07-18 09:26:21 -07:00
David Tolnay
f67035c143
Clarify names of format_ident macro variables 2019-07-18 09:22:50 -07:00
David Tolnay
d29563e785
Split format_ident private rules to a hidden macro
Removes the distracting extra rules from the macro's rendered rustdoc.
2019-07-18 09:15:20 -07:00
David Tolnay
6261bfdbea
Give format_ident macro its own module 2019-07-18 09:10:19 -07:00
David Tolnay
6831a5b303
Remove indiscriminate use of inline
We can add these back later as motivated by benchmarks.
2019-07-18 09:08:42 -07:00
David Tolnay
715114313d
Merge pull request 114 from mystor/format_ident 2019-07-16 11:52:49 -07:00
David Tolnay
18fc49dc9e
Merge pull request #119 from dtolnay/nonrep
Reject repetitions not containing any iterator
2019-07-15 21:27:35 -07:00
David Tolnay
63db5e8789
Improve require_has_iter error message 2019-07-15 21:19:03 -07:00
David Tolnay
2ee59e27cd
Merge pull request #120 from dtolnay/span
Validate that quote_spanned is given a span
2019-07-14 19:52:22 -07:00
David Tolnay
7db33987e0
Validate that quote_spanned is given a span 2019-07-14 19:46:29 -07:00
David Tolnay
eda75fac00
Reject repetitions not containing any iterator 2019-07-14 19:03:15 -07:00
Nika Layzell
e9bf09fbf3 Add a format_ident! helper macro (#110)
This is similar to the initial proposal in #110, with a few changes.

1. If an `Ident` was used to provide a fragment within the final formatted
   string, the default behaviour has been changed to inheret the `Span` from it.
   The idea here is to produce good spans for formatted identifiers by default,
   attributing them to the source of their name.

   The `span` named argument can still be used to override this decision.

2. `Ident::new(...)` doesn't support creating raw identifiers, and
   `Ident::new_raw` is still unstable, so the initial behaviour of directly
   passing the result of `format!` into `Ident::new(...)` turned out not to
   work.

   Instead, a helper method was added, `__rt::mk_ident`, which will handle
   creating raw identifiers using the roundabout "parse as TokenStream and
   unwrap" approach.

   I thought it was important to support raw identifiers in `format_ident!` as
   people may want to be able to write `format_ident!("r#{}_{}", a, b)` or
   similar to ensure that their identifiers are never confused for keywords.

3. It turns out it's basically impossible to compare spans right now, and
   there's no stable way to produce a span other than `Span::call_site()`, so no
   tests check that the spans are passed around correctly.
2019-07-14 20:57:38 -04:00
David Tolnay
5673e5f28b
Merge pull request #118 from mystor/quote_next_minver
Bump minimum rust version to 1.31.0 for quote-next
2019-07-14 17:44:45 -07:00
Nika Layzell
5db1f4b63c Bump minimum rust version to 1.31.0 for quote-next 2019-07-14 20:25:52 -04:00
David Tolnay
5e42c848ae
Simplify the example behavior of quote_bind macros 2019-07-14 17:11:59 -07:00
David Tolnay
e7a19300dc
Update not-repeatable ui test error message 2019-07-14 16:43:45 -07:00
David Tolnay
7f1640e58b
Merge pull request 109 from mystor/dup_name_rep 2019-07-14 16:20:26 -07:00
David Tolnay
a78198404d
Add ui tests 2019-07-14 16:19:42 -07:00
David Tolnay
41a3430fc6
Get ready to land breaking changes 2019-07-14 16:10:57 -07:00
Nika Layzell
a5e457094d [breaking] Support nonrepeating interpolations within repetitions (#7) 2019-07-14 13:58:52 -04:00
Masaki Hara
103951095e Make recursion depth constant to number of tts. 2019-07-14 09:40:57 +09:00
David Tolnay
2932973ffd
Release 0.6.13 2019-07-11 09:35:43 -07:00
Nika Layzell
a4eb731f73 Support duplicate interpolations within repetitions (#8)
This eliminates the restrictions around duplicate interpolations by taking
advantage of shadowing of let bindings within generated loops and rust deref
coersion within a desugared loop.

Duplicate calls to `IntoIter::into_iter` are handled, as the duplicates will be
called on the already-bound iterator objects, meaning that the call is a no-op.

Duplicate calls to `next()` are also handled by wrapping each interpolation
within the loop into a `RepInterp<T>` wrapper. This wrapper provides a dummy
inherent `next` method which ensures that `next` is only called once per
iterator per loop.

As a side-benefit, this has the effect of producing `unused_code` warnings when
no interpolations occur within a repetition block, as rustc can see an
unconditional break statement before code to generate the repetition body.

This has been tested working in rustc 1.15.1, although extraneous `unused_mut`
warnings are emitted due to `#[allow(unused_mut)]` being ignored on statements
in that release.

The generated code looks similar to the following:
```rust
// quote!(#(#a #b #a),*);

// ...
{
    let mut _i = 0; // Only used if sep is present.

    // Get and bind iterators to use for the capture repetition.
    #[allow(unused_mut)] let mut a = a.into_iter();
    #[allow(unused_mut)] let mut b = b.into_iter();

    // Duplicate names are a no-op, as IntoIter::into_iter is idempotent.
    #[allow(unused_mut)] let mut a = a.into_iter();

    loop {
        // Calls `Iterator::next` and wraps the result in `RepInterp` if `Some`.
        let a = match a.next() {
            Some(_x) => $crate::__rt::RepInterp(_x),
            None => break,
        };
        let b = match b.next() {
            Some(_x) => $crate::__rt::RepInterp(_x),
            None => break,
        };

        // No-op `next()` call for duplicate names, as `RepInterp` defines an
        // inherent `next(self) -> Option<T>` method.
        let a = match a.next() {
            Some(_x) => $crate::__rt::RepInterp(_x),
            None => break,
        };

        if _i > 0 {
            quote_each_token!(tokens span ,);
        }
        _i += 1;

        quote_each_token!(tokens span #a #b #a);
    }
}
// ...
```
2019-06-30 01:42:14 -04:00
CreepySkeleton
a5227dab20 Simplify is_ident function (#104)
It's a way over-complicated
2019-05-23 21:44:28 -07:00
David Tolnay
57038ba5e4
Smaller format for license section 2019-05-18 17:21:27 -07:00
David Tolnay
2085c7eed8
Switch to SPDX 2.1 license expression 2019-05-09 15:26:20 -07:00
David Tolnay
b3a3d76815
Update tests for new proc-macro2 escape behavior 2019-04-23 21:31:58 -07:00
David Tolnay
837b511389
Release 0.6.12 2019-04-09 10:36:22 -07:00
David Tolnay
62b705d26f
Merge pull request #102 from eddyb/rc
Support Rc<T> in ToTokens.
2019-04-09 10:35:24 -07:00
Eduard-Mihai Burtescu
f2d0dda92d Support Rc<T> in ToTokens. 2019-04-09 19:47:24 +03:00
David Tolnay
5a2ba6d550
Format with rustfmt 2018-12-10 2019-02-05 11:26:50 +01:00
David Tolnay
af20c8ac19
Adjust indentation of quote macro rules 2019-02-05 11:26:36 +01:00
David Tolnay
fcc424258c
Move runtime support to its own module 2019-02-03 22:54:27 +01:00
David Tolnay
2012cea327
Add benchmark of a representative impl 2019-02-03 22:53:57 +01:00
David Tolnay
f81fdb4b0c
Document limitations of interpolation in a repetition 2019-01-28 00:06:17 -08:00
David Tolnay
6338cd9d6b
Release 0.6.11 2019-01-19 18:51:53 -08:00
David Tolnay
b248452fa2
Port examples from readme to rustdoc 2019-01-19 18:50:09 -08:00