about summary refs log tree commit diff
path: root/src/libproc_macro
AgeCommit message (Collapse)AuthorLines
2018-06-01Update recursion limitsJohn Kåre Alsaker-0/+2
2018-05-26Auto merge of #51072 - petrochenkov:ifield, r=eddybbors-3/+3
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-26Add `Ident::as_str` helperVadim Petrochenkov-3/+3
2018-05-25Rename TokenStream::empty to TokenStream::newDavid Tolnay-3/+3
There is no precedent for the `empty` name -- we do not have `Vec::empty` or `HashMap::empty` etc.
2018-05-17Fix rebaseVadim Petrochenkov-1/+1
2018-05-16Fix stability annotations for already stable bits of proc macro API 1.1Vadim Petrochenkov-5/+5
Remove unnecessary proc-macro-related `feature`s
2018-05-15Represent lifetimes as two joint tokens in proc macrosVadim Petrochenkov-16/+18
2018-05-15Address feedback, remove remaining review comments, add some more docsVadim Petrochenkov-53/+30
2018-05-15proc_macro: Validate inputs to `Punct::new` and `Ident::new`Vadim Petrochenkov-22/+47
2018-05-15proc_macro: Properly support raw identifiersVadim Petrochenkov-14/+13
2018-05-15TokenTree: Op -> Punct, Term -> IdentVadim Petrochenkov-113/+97
2018-05-15Extend documentation and add review commentsVadim Petrochenkov-38/+152
2018-05-10Auto merge of #49823 - Zoxc:term-str, r=alexcrichtonbors-3/+4
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-04proc_macro: Explicitly make everything !Send/SyncAlex Crichton-1/+46
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-04-30Remove usages of Term::as_str and mark it for removalJohn Kåre Alsaker-3/+4
2018-04-26Fix review nitsbobtwinkles-1/+1
2018-04-23Implement parent() on `syntax_pos::Span`bobtwinkles-1/+1
... and reimplement proc_macro::Span::parent using it. This function turns out to be useful in the compiler as well
2018-04-12Change the hashcounts in raw `Lit` variants from usize to u16.Nicholas Nethercote-3/+3
This reduces the size of `Token` from 32 bytes to 24 bytes on 64-bit platforms.
2018-04-12Rollup merge of #49734 - alexcrichton:generalize-token-stream, r=nikomatsakiskennytm-2/+9
proc_macro: Generalize `FromIterator` impl While never intended to be stable we forgot that trait impls are insta-stable! This construction of `FromIterator` wasn't our first choice of how to stabilize the impl but our hands are tied at this point, so revert back to the original definition of `FromIterator` before #49597 Closes #49725
2018-04-08Move deny(warnings) into rustbuildMark Simulacrum-1/+0
This permits easier iteration without having to worry about warnings being denied. Fixes #49517
2018-04-07Auto merge of #49661 - alexcrichton:bump-bootstrap, r=nikomatsakisbors-1/+0
Bump the bootstrap compiler to 1.26.0 beta Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language features!
2018-04-06Print proc_macro spans as a half-open rangeDavid Tolnay-1/+1
A span covering a single byte, such as for an operator `+` token, should print as e.g. `80..81` rather than `80...81`. The lo end of the range is inclusive and the hi end is exclusive.
2018-04-06proc_macro: Improve Debug representationsAlex Crichton-35/+63
This commit improves the `fmt::Debug` output of `proc_macro` data structures by primarily focusing on the representation exposed by `proc_macro` rather than the compiler's own internal representation. This cuts down quite a bit on assorted wrapper types and ensure a relatively clean output. Closes #49720
2018-04-06proc_macro: Generalize `FromIterator` implAlex Crichton-2/+9
While never intended to be stable we forgot that trait impls are insta-stable! This construction of `FromIterator` wasn't our first choice of how to stabilize the impl but our hands are tied at this point, so revert back to the original definition of `FromIterator` before #49597 Closes #49725
2018-04-06Remove more duplicated spansVadim Petrochenkov-7/+9
2018-04-06Use `Span` instead of `SyntaxContext` in `Ident`Vadim Petrochenkov-1/+1
2018-04-05Bump the bootstrap compiler to 1.26.0 betaAlex Crichton-1/+0
Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language features!
2018-04-04Tweak doc comment expansionAlex Crichton-1/+7
* Expand `!` tokens for inner doc comments * Trim leading doc comment decoration in the string literal Both of these should help bring the expansion inline with what `macro_rules!` already does. Closes #49655 Closes #49656
2018-04-02proc_macro: Reorganize public APIAlex Crichton-240/+645
This commit is a reorganization of the `proc_macro` crate's public user-facing API. This is the result of a number of discussions at the recent Rust All-Hands where we're hoping to get the `proc_macro` crate into ship shape for stabilization of a subset of its functionality in the Rust 2018 release. The reorganization here is motivated by experiences from the `proc-macro2`, `quote`, and `syn` crates on crates.io (and other crates which depend on them). The main focus is future flexibility along with making a few more operations consistent and/or fixing bugs. A summary of the changes made from today's `proc_macro` API is: * The `TokenNode` enum has been removed and the public fields of `TokenTree` have also been removed. Instead the `TokenTree` type is now a public enum (what `TokenNode` was) and each variant is an opaque struct which internally contains `Span` information. This makes the various tokens a bit more consistent, require fewer wrappers, and otherwise provides good future-compatibility as opaque structs are easy to modify later on. * `Literal` integer constructors have been expanded to be unambiguous as to what they're doing and also allow for more future flexibility. Previously constructors like `Literal::float` and `Literal::integer` were used to create unsuffixed literals and the concrete methods like `Literal::i32` would create a suffixed token. This wasn't immediately clear to all users (the suffixed/unsuffixed aspect) and having *one* constructor for unsuffixed literals required us to pick a largest type which may not always be true. To fix these issues all constructors are now of the form `Literal::i32_unsuffixed` or `Literal::i32_suffixed` (for all integral types). This should allow future compatibility as well as being immediately clear what's suffixed and what isn't. * Each variant of `TokenTree` internally contains a `Span` which can also be configured via `set_span`. For example `Literal` and `Term` now both internally contain a `Span` rather than having it stored in an auxiliary location. * Constructors of all tokens are called `new` now (aka `Term::intern` is gone) and most do not take spans. Manufactured tokens typically don't have a fresh span to go with them and the span is purely used for error-reporting **except** the span for `Term`, which currently affects hygiene. The default spans for all these constructed tokens is `Span::call_site()` for now. The `Term` type's constructor explicitly requires passing in a `Span` to provide future-proofing against possible hygiene changes. It's intended that a first pass of stabilization will likely only stabilize `Span::call_site()` which is an explicit opt-in for "I would like no hygiene here please". The intention here is to make this explicit in procedural macros to be forwards-compatible with a hygiene-specifying solution. * Some of the conversions for `TokenStream` have been simplified a little. * The `TokenTreeIter` iterator was renamed to `token_stream::IntoIter`. Overall the hope is that this is the "final pass" at the API of `TokenStream` and most of `TokenTree` before stabilization. Explicitly left out here is any changes to `Span`'s API which will likely need to be re-evaluated before stabilization. All changes in this PR have already been reflected to the [`proc-macro2`], `quote`, and `syn` crates. New versions of all these crates have also been published to crates.io. Once this lands in nightly I plan on making an internals post again summarizing the changes made here and also calling on all macro authors to give the APIs a spin and see how they work. Hopefully pending no major issues we can then have an FCP to stabilize later this cycle! [`proc-macro2`]: https://docs.rs/proc-macro2/0.3.1/proc_macro2/
2018-03-31proc_macro: Tweak doc comments and negative literalsAlex Crichton-51/+80
This commit tweaks the tokenization of a doc comment to use `#[doc = "..."]` like `macro_rules!` does (instead of treating it as a `Literal` token). Additionally it fixes treatment of negative literals in the compiler, for exapmle `Literal::i32(-1)`. The current fix is a bit of a hack around the current compiler implementation, providing a fix at the proc-macro layer rather than the libsyntax layer.
2018-03-26Stabilize i128_typeMark Mansi-1/+1
2018-03-18Initial implementation of RFC 2151, Raw IdentifiersLymia Aluysia-2/+9
2018-03-17syntax: Make `_` an identifierVadim Petrochenkov-2/+0
2018-03-02Impl !Send and !Sync for SourceFileJohn Kåre Alsaker-0/+6
2018-03-02Replace Rc with Lrc for shared dataJohn Kåre Alsaker-3/+5
2018-02-28Rollup merge of #48359 - jsgf:remap-path-prefix, r=sanxiynManish Goregaokar-1/+1
Fixes #47311. r? @nrc
2018-02-22Implement --remap-path-prefixJeremy Fitzhardinge-1/+1
Remove experimental -Zremap-path-prefix-from/to, and replace it with the stabilized --remap-path-prefix=from=to variant. This is an implementation for issue of #41555.
2018-02-20Do not run the default panic hook inside procedural macros. Fixes #47812John Kåre Alsaker-0/+6
2018-02-06proc_macro: don't panic parsing ..= (fix #47950)Alex Burka-1/+1
2018-01-12Auto merge of #46551 - jseyfried:improve_legacy_modern_macro_interaction, r=nrcbors-1/+1
macros: improve 1.0/2.0 interaction This PR supports using unhygienic macros from hygienic macros without breaking the latter's hygiene. ```rust // crate A: #[macro_export] macro_rules! m1 { () => { f(); // unhygienic: this macro needs `f` in its environment fn g() {} // (1) unhygienic: `g` is usable outside the macro definition } } // crate B: #![feature(decl_macro)] extern crate A; use A::m1; macro m2() { fn f() {} // (2) m1!(); // After this PR, `f()` in the expansion resolves to (2), not (3) g(); // After this PR, this resolves to `fn g() {}` from the above expansion. // Today, it is a resolution error. } fn test() { fn f() {} // (3) m2!(); // Today, `m2!()` can see (3) even though it should be hygienic. fn g() {} // Today, this conflicts with `fn g() {}` from the expansion, even though it should be hygienic. } ``` Once this PR lands, you can make an existing unhygienic macro hygienic by wrapping it in a hygienic macro. There is an [example](https://github.com/rust-lang/rust/pull/46551/commits/b766fa887dc0e4b923a38751fe4d570e35a75710) of this in the tests. r? @nrc
2018-01-06Auto merge of #47099 - SergioBenitez:master, r=jseyfriedbors-0/+15
Add 'Span::parent()' and 'Span::source()' to proc_macro API. As the title suggests: a couple of useful methods for `proc_macro`.
2018-01-05Rollup merge of #47150 - dtolnay:join, r=jseyfriedkennytm-1/+1
Return None from Span::join if in different files Fixes #47148. r? @abonander
2018-01-03Add 'Span.parent()' and 'Span.source()' to proc_macro API.Sergio Benitez-0/+15
2018-01-02Span::resolved_at and Span::located_at to combine behavior of two spansDavid Tolnay-0/+14
Proc macro spans serve two mostly unrelated purposes: controlling name resolution and controlling error messages. It can be useful to mix the name resolution behavior of one span with the line/column error message locations of a different span. In particular, consider the case of a trait brought into scope within the def_site of a custom derive. I want to invoke trait methods on the fields of the user's struct. If the field type does not implement the right trait, I want the error message to underline the corresponding struct field. Generating the method call with the def_site span is not ideal -- it compiles and runs but error messages sadly always point to the derive attribute like we saw with Macros 1.1. ``` | 4 | #[derive(HeapSize)] | ^^^^^^^^ ``` Generating the method call with the same span as the struct field's ident or type is not correct -- it shows the right underlines but fails to resolve to the trait in scope at the def_site. ``` | 7 | bad: std::thread::Thread, | ^^^^^^^^^^^^^^^^^^^^^^^^ ``` The correct span for the method call is one that combines the def_site's name resolution with the struct field's line/column. ``` field.span.resolved_at(Span::def_site()) // equivalently Span::def_site().located_at(field.span) ``` Adding both because which one is more natural will depend on context.
2018-01-02Return None from Span::join if in different filesDavid Tolnay-1/+1
2017-12-15Rollup merge of #46690 - mystor:pub_line_column, r=jseyfriedSteve Klabnik-2/+4
Expose the line and column fields from the proc_macro::LineColumn struct Right now the `LineColumn` struct is pretty useless because the fields are private. This patch just marks the fields as public, which seems like the easiest solution.
2017-12-14Use PathBuf instead of String where applicableOliver Schneider-10/+10
2017-12-13Improve interaction between macros 2.0 and `macro_rules!`.Jeffrey Seyfried-1/+1
2017-12-12Expose the line and column fields from the proc_macro::LineColumn structNika Layzell-2/+4
2017-11-28Fix hygiene bug.Jeffrey Seyfried-1/+1