Commit Graph

129 Commits

Author SHA1 Message Date
Sergio Benitez 10bb5edb19 Add multispan support to proc-macro diagnostics.
Also updates the issue number for 'proc_macro_diagnostic'.
2018-09-13 01:19:48 -07:00
Sergio Benitez 50d869333b Add inspection and setter methods to proc_macro::Diagnostic. 2018-09-12 23:34:12 -07:00
bors 6810f5286b Auto merge of #53793 - toidiu:ak-stabalize, r=nikomatsakis
stabilize outlives requirements

https://github.com/rust-lang/rust/issues/44493

r? @nikomatsakis
2018-09-12 11:27:48 +00:00
toidiu 731f4efae5 stabalize infer outlives requirements (RFC 2093).
Co-authored-by: nikomatsakis
2018-09-11 11:40:04 -04:00
David Tolnay 7acd4b12da Remove documentation about proc_macro being bare-bones 2018-09-09 09:56:14 -07:00
David Tolnay a1dd39e724 Track distinct spans for open and close delimiter 2018-09-08 19:01:48 -07:00
David Tolnay c5a561c0ab proc_macro::Group::span_open and span_close
Before this addition, every delimited group like (...) [...] {...} has
only a single Span that covers the full source location from opening
delimiter to closing delimiter. This makes it impossible for a
procedural macro to trigger an error pointing to just the opening or
closing delimiter. The Rust compiler does not seem to have the same
limitation:

    mod m {
        type T =
    }

    error: expected type, found `}`
     --> src/main.rs:3:1
      |
    3 | }
      | ^

On that same input, a procedural macro would be forced to trigger the
error on the last token inside the block, on the entire block, or on the
next token after the block, none of which is really what you want for an
error like above.

This commit adds group.span_open() and group.span_close() which access
the Span associated with just the opening delimiter and just the closing
delimiter of the group. Relevant to Syn as we implement real error
messages for when parsing fails in a procedural macro.
2018-09-02 14:34:45 -07:00
Niko Matsakis 73fb1622b3 check that adding infer-outlives requirement to all crates works 2018-08-24 17:10:50 -04:00
kennytm b5519db323 Rollup merge of #53496 - matthiaskrgr:codespell_08_2018, r=varkor
Fix typos found by codespell.
2018-08-21 17:51:49 +08:00
Donato Sciarra 6138c82803 fix tidy errors 2018-08-19 23:01:01 +02:00
Donato Sciarra d3fe97f3d3 mv codemap() source_map() 2018-08-19 23:01:01 +02:00
Donato Sciarra cbd0595710 mv filemap source_file 2018-08-19 23:00:59 +02:00
Donato Sciarra d6dcbcd4e1 mv FileMap SourceFile 2018-08-19 23:00:59 +02:00
Matthias Krüger 71120ef1e5 Fix typos found by codespell. 2018-08-19 17:41:28 +02:00
bors b2028828db Auto merge of #53433 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests

Successful merges:

 - #52946 (Documented impl From on line 367 of libserialize/json.rs)
 - #53234 (Remove Travis shutdown debug scripts, and remove CI-specific DNS settings)
 - #53313 (Two small improvements)
 - #53360 (Addressed #51602)
 - #53364 (Warn if the user tries to use GATs)
 - #53373 (Tweak unclosed delimiter parser error)
 - #53377 (std: Use target_pointer_width for BACKTRACE_ELF_SIZE)
 - #53395 (Use #[non_exhaustive] on internal enums)
 - #53399 (Tidy: ignore non-Markdown files when linting for the Unstable Book)
 - #53412 (syntax_ext: remove leftover span_err_if_not_stage0 macro.)
2018-08-16 17:53:29 +00:00
bors b5590423e6 Auto merge of #53304 - dtolnay:extend, r=dtolnay
TokenStream::extend

Two new insta-stable impls in libproc_macro:

```rust
impl Extend<TokenTree> for TokenStream
impl Extend<TokenStream> for TokenStream
```

`proc_macro::TokenStream` already implements `FromIterator<TokenTree>` and `FromIterator<TokenStream>` so I elected to support the same input types for `Extend`.

**This commit reduces compile time of Serde derives by 60% (takes less than half as long to compile)** as measured by building our test suite:

```console
$ git clone https://github.com/serde-rs/serde
$ cd serde/test_suite
$ cargo check --tests --features proc-macro2/nightly
$ rm -f ../target/debug/deps/libtest_*.rmeta
$ time cargo check --tests --features proc-macro2/nightly
Before: 20.8 seconds
After: 8.6 seconds
```

r? @alexcrichton
2018-08-16 15:44:30 +00:00
varkor a50224804d Make proc_macro Level #[non_exhaustive] 2018-08-15 17:11:42 +01:00
David Tolnay 2fa1da9919 TokenStream::extend 2018-08-12 22:45:32 -07:00
memoryruins 48616432ba [nll] libproc_macro: enable feature(nll) for bootstrap 2018-08-09 15:32:45 -04:00
Tatsuyuki Ishi e098985939 Deny bare_trait_objects globally 2018-07-25 10:25:29 +09:00
Eduard-Mihai Burtescu 99eac011c6 proc_macro: avoid exposing internal details in formatting impls. 2018-07-20 06:27:16 +03:00
Eduard-Mihai Burtescu bc2b21cc4e proc_macro: move some implementation details to a rustc module. 2018-07-20 06:26:33 +03:00
Eduard-Mihai Burtescu e5e29d1a19 proc_macro: don't expose compiler-internal FileName in public API. 2018-07-20 00:15:11 +03:00
Eduard-Mihai Burtescu 56aaa53278 proc_macro: clean up the implementation of quasi-quoting. 2018-07-20 00:15:11 +03:00
Eduard-Mihai Burtescu d10d0b3e9e proc_macro: don't try to reflect literals in quasi-quoting. 2018-07-20 00:15:11 +03:00
Eduard-Mihai Burtescu c0adb05d34 proc_macro: don't use DiagnosticBuilder for building up Diagnostics. 2018-07-20 00:15:11 +03:00
Alex Crichton 65f3007fa8 rustc: Stabilize much of the proc_macro feature
This commit stabilizes some of the `proc_macro` language feature as well as a
number of APIs in the `proc_macro` crate as [previously discussed][1]. This
means that on stable Rust you can now define custom procedural macros which
operate as attributes attached to items or `macro_rules!`-like bang-style
invocations. This extends the suite of currently stable procedural macros,
custom derives, with custom attributes and custom bang macros.

Note though that despite the stabilization in this commit procedural macros are
still not usable on stable Rust. To stabilize that we'll need to stabilize at
least part of the `use_extern_macros` feature. Currently you can define a
procedural macro attribute but you can't import it to call it!

A summary of the changes made in this PR (as well as the various consequences)
is:

* The `proc_macro` language and library features are now stable.
* Other APIs not stabilized in the `proc_macro` crate are now named under a
  different feature, such as `proc_macro_diagnostic` or `proc_macro_span`.
* A few checks in resolution for `proc_macro` being enabled have switched over
  to `use_extern_macros` being enabled. This means that code using
  `#![feature(proc_macro)]` today will likely need to move to
  `#![feature(use_extern_macros)]`.

It's intended that this PR, once landed, will be followed up with an attempt to
stabilize a small slice of `use_extern_macros` just for procedural macros to
make this feature 100% usable on stable.

[1]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
2018-07-16 07:58:06 -07:00
Manish Goregaokar 58f3f7b081 Clarify how the quote macro is loaded 2018-07-14 12:06:50 -07:00
ljedrz 5058af7003 Deny bare trait objects in the rest of rust 2018-07-12 13:50:22 +02:00
Vadim Petrochenkov 94ef9f57f5 hygiene: Decouple transparencies from expansion IDs 2018-07-08 16:17:37 +03:00
Vadim Petrochenkov 84f1bc8b66 Address comments 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov 9f92fce77c Fortify dummy span checking 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov 297109ea32 proc-macro: Use transparent marks for call-site hygiene 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov c00f5af4d6 hygiene: Do not reset expansion info for quote! 2018-06-23 20:40:25 +03:00
John Kåre Alsaker b7aabaa3fc Update recursion limits 2018-06-01 14:56:01 +02:00
bors 1e504d301c Auto merge of #51072 - petrochenkov:ifield, r=eddyb
Use `Ident`s for fields in HIR

Continuation of https://github.com/rust-lang/rust/pull/49718, part of https://github.com/rust-lang/rust/issues/49300
2018-05-26 16:56:22 +00:00
Vadim Petrochenkov 1e4269cb83 Add Ident::as_str helper 2018-05-26 15:20:23 +03:00
David Tolnay a49bc9ce59 Rename TokenStream::empty to TokenStream::new
There is no precedent for the `empty` name -- we do not have
`Vec::empty` or `HashMap::empty` etc.
2018-05-25 19:44:10 -07:00
Vadim Petrochenkov d8bbc1ee1a Fix rebase 2018-05-17 23:32:47 +03:00
Vadim Petrochenkov dab8c0ab28 Fix stability annotations for already stable bits of proc macro API 1.1
Remove unnecessary proc-macro-related `feature`s
2018-05-16 00:09:15 +03:00
Vadim Petrochenkov c106125431 Represent lifetimes as two joint tokens in proc macros 2018-05-15 23:54:08 +03:00
Vadim Petrochenkov 5b820a694c Address feedback, remove remaining review comments, add some more docs 2018-05-15 23:24:17 +03:00
Vadim Petrochenkov 780616ed74 proc_macro: Validate inputs to Punct::new and Ident::new 2018-05-15 23:24:16 +03:00
Vadim Petrochenkov f116ab6e6e proc_macro: Properly support raw identifiers 2018-05-15 23:24:16 +03:00
Vadim Petrochenkov 47d4089e10 TokenTree: Op -> Punct, Term -> Ident 2018-05-15 23:24:16 +03:00
Vadim Petrochenkov decc619a1f Extend documentation and add review comments 2018-05-15 23:24:16 +03:00
bors 9e3caa23f9 Auto merge of #49823 - Zoxc:term-str, r=alexcrichton
Remove usages of Term::as_str and mark it for removal

Returning references to rustc internal data structures is a bad idea since their lifetimes are unrelated to the lifetimes of proc_macro values.

See https://github.com/rust-lang/rust/pull/46972 and the `Taming thread-local storage` section of https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606

r? @alexcrichton
2018-05-10 16:27:32 +00:00
Alex Crichton 3e0ed2fc05 proc_macro: Explicitly make everything !Send/Sync
This commit adds explicit imp blocks to ensure that all publicly exported types
(except simple enums) are not `Send` nor `Sync` in the `proc_macro` crate.

cc #38356
2018-05-04 14:12:57 -07:00
John Kåre Alsaker 221b7ca3c2 Remove usages of Term::as_str and mark it for removal 2018-04-30 05:27:05 +02:00
bobtwinkles 73e0c1e968 Fix review nits 2018-04-26 18:28:34 -04:00