about summary refs log tree commit diff
path: root/src/libproc_macro/lib.rs
AgeCommit message (Collapse)AuthorLines
2018-04-30Remove usages of Term::as_str and mark it for removalJohn Kåre Alsaker-2/+3
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-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-26/+57
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-185/+562
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/+4
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
2017-11-14Rename `Span::default` -> `Span::def_site`.Jeffrey Seyfried-4/+5
2017-11-09proc_macro: use the proc_macro API at runtime to construct quasi-quoted ↵Eduard-Mihai Burtescu-1/+1
TokenStream's.
2017-11-09proc_macro: process proc_macro tokens instead of libsyntax ones in the ↵Eduard-Mihai Burtescu-1/+1
quasi-quoter.
2017-10-08Make the result of `Literal::string()` more readableChris Wong-1/+1
Closes #45076
2017-10-05`proc_macro::Span` API improvementsAustin Bonander-3/+128
2017-09-22Add support for `..=` syntaxAlex Burka-0/+2
Add ..= to the parser Add ..= to libproc_macro Add ..= to ICH Highlight ..= in rustdoc Update impl Debug for RangeInclusive to ..= Replace `...` to `..=` in range docs Make the dotdoteq warning point to the ... Add warning for ... in expressions Updated more tests to the ..= syntax Updated even more tests to the ..= syntax Updated the inclusive_range entry in unstable book
2017-09-18rustc: Forbid interpolated tokens in the HIRAlex Crichton-71/+5
Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays these can contain arbitrary tokens. One variant of the `Token` enum is an "interpolated" token which basically means to shove all the tokens for a nonterminal in this position. A "nonterminal" in this case is roughly analagous to a macro argument: macro_rules! foo { ($a:expr) => { // $a is a nonterminal as an expression } } Currently nonterminals contain namely items and expressions, and this poses a problem for incremental compilation! With incremental we want a stable hash of all HIR items, but this means we may transitively need a stable hash *of the entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today there's a "bug" where the "stable hash" of an AST is just the raw hash value of the AST, and this only arises with interpolated nonterminals. The downside of this approach, however, is that a bunch of errors get spewed out during compilation about how this isn't a great idea. This PR is focused at fixing these warnings, basically deleting them from the compiler. The implementation here is to alter attributes as they're lowered from the AST to HIR, expanding all nonterminals in-place as we see them. This code for expanding a nonterminal to a token stream already exists for the `proc_macro` crate, so we basically just reuse the same implementation there. After this PR it's considered a bug to have an `Interpolated` token and hence the stable hash implementation simply uses `bug!` in this location. Closes #40946
2017-08-30Rollup merge of #44125 - SergioBenitez:master, r=nrcAlex Crichton-0/+22
Initial diagnostic API for proc-macros. This commit introduces the ability to create and emit `Diagnostic` structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does. The API is somewhat based on the diagnostic API already present in `rustc` with several changes that improve usability. The entry point into the diagnostic API is a new `Diagnostic` type which is primarily created through new `error`, `warning`, `help`, and `note` methods on `Span`. The `Diagnostic` type records the diagnostic level, message, and optional `Span` for the top-level diagnostic and contains a `Vec` of all of the child diagnostics. Child diagnostics can be added through builder methods on `Diagnostic`. A typical use of the API may look like: ```rust let token = parse_token(); let val = parse_val(); val.span .error(format!("expected A but found {}", val)) .span_note(token.span, "because of this token") .help("consider using a different token") .emit(); ``` cc @jseyfried @nrc @dtolnay @alexcrichton
2017-08-30Make fields of `Span` privateVadim Petrochenkov-9/+6
2017-08-28Initial diagnostic API for proc-macros.Sergio Benitez-0/+22
This commit introduces the ability to create and emit `Diagnostic` structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does.
2017-08-25*: remove crate_{name,type} attributesTamir Duberstein-3/+0
Fixes #41701.
2017-08-23Rollup merge of #44016 - steffengy:master, r=alexcrichtonCorey Farwell-2/+2
libproc_macro docs: fix brace and bracket mixup The documentation indicates that brace is `[`. Brace is mapped token::Brace which (expectedly) is `{`. So the documentation is simply confusing brace and bracket there. Even though it's just a very small issue, it can lead to quite some confusion.
2017-08-21libproc_macro docs: fix brace and bracket mixupSteffen-2/+2
the documentation indicates that brace is `[` but maps to token::Brace which (expectedly) is `{`. Just a little confusion in the docs.
2017-08-20Add PartialEq/Eq impls to proc_macro::{Spacing, Delimiter}Lukas Kalbertodt-2/+2
I don't see a reason why those two types shouldn't be tested for equality.
2017-08-11Fix some more typos, this time words that are duplicated.Bastien Orivel-1/+1