about summary refs log tree commit diff
path: root/src/libproc_macro
AgeCommit message (Collapse)AuthorLines
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-5/+6
2017-11-09proc_macro: use the proc_macro API at runtime to construct quasi-quoted ↵Eduard-Mihai Burtescu-130/+118
TokenStream's.
2017-11-09proc_macro: process proc_macro tokens instead of libsyntax ones in the ↵Eduard-Mihai Burtescu-153/+167
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-2/+4
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/+157
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/+157
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
2017-07-28syntax: Capture a `TokenStream` when parsing itemsAlex Crichton-6/+57
This is then later used by `proc_macro` to generate a new `proc_macro::TokenTree` which preserves span information. Unfortunately this isn't a bullet-proof approach as it doesn't handle the case when there's still other attributes on the item, especially inner attributes. Despite this the intention here is to solve the primary use case for procedural attributes, attached to functions as outer attributes, likely bare. In this situation we should be able to now yield a lossless stream of tokens to preserve span information.
2017-07-28proc_macro: Use an item's tokens if availableAlex Crichton-8/+20
This partly resolves the `FIXME` located in `src/libproc_macro/lib.rs` when interpreting interpolated tokens. All instances of `ast::Item` which have a list of tokens attached to them now use that list of tokens to losslessly get converted into a `TokenTree` instead of going through stringification and losing span information. cc #43081
2017-07-17Add #[derive(Clone)] to TokenTreeIterChris Wong-0/+1
2017-07-15Auto merge of #43179 - oli-obk:mark_all_the_expansions, r=jseyfriedbors-2/+11
Reintroduce expansion info for proc macros 1.1 r? @jseyfried
2017-07-12Rollup merge of #43098 - alexcrichton:more-proc-macro, r=jseyfriedMark Simulacrum-1/+1
Add `isize` and `usize` constructors to Literal This commit fills out the remaining integer literal constructors on the `proc_macro::Literal` type with `isize` and `usize`. (I think these were just left out by accident)
2017-07-12Reintroduce expansion info for proc macros 1.1Oliver Schneider-2/+11
2017-07-07Address review commentspetrochenkov-1/+1
Fix regressions after rebase
2017-07-06Add `isize` and `usize` constructors to LiteralAlex Crichton-1/+1
This commit fills out the remaining integer literal constructors on the `proc_macro::Literal` type with `isize` and `usize`. (I think these were just left out by accident)
2017-06-26Address review comments.Jeffrey Seyfried-83/+123
2017-06-26Add `LazyTokenStream`.Jeffrey Seyfried-8/+28
2017-06-26Implement `quote!` and other `proc_macro` API.Jeffrey Seyfried-24/+710
2017-06-26Clean up `tokenstream::Cursor` and `proc_macro`.Jeffrey Seyfried-17/+11
2017-06-26Simplify `hygiene::Mark` application, andJeffrey Seyfried-12/+16
remove variant `Token::SubstNt` in favor of `quoted::TokenTree::MetaVar`.
2017-06-15Update older URLs pointing to the first edition of the BookWonwoo Choi-1/+1
`compiler-plugins.html` is moved into the Unstable Book. Explanation is slightly modified to match the change.
2017-03-12Add doc attributes to proc_macro crateOliver Middleton-0/+7
This adds the same logo and favicon as the rest of the std docs.
2017-03-10rustbuild: Build documentation for `proc_macro`Alex Crichton-1/+1
This commit fixes #38749 by building documentation for the `proc_macro` crate by default for configured hosts. Unfortunately did not turn out to be a trivial fix. Currently rustbuild generates documentation into multiple locations: one for std, one for test, and one for rustc. The initial fix for this issue simply actually executed `cargo doc -p proc_macro` which was otherwise completely elided before. Unfortunately rustbuild was the left to merge two documentation trees together. One for the standard library and one for the rustc tree (which only had docs for the `proc_macro` crate). Rustdoc itself knows how to merge documentation files (specifically around search indexes, etc) but rustbuild was unaware of this, so an initial fix ended up destroying the sidebar and the search bar from the libstd docs. To solve this issue the method of documentation has been tweaked slightly in rustbuild. The build system will not use symlinks (or directory junctions on Windows) to generate all documentation into the same location initially. This'll rely on rustdoc's logic to weave together all the output and ensure that it ends up all consistent. Closes #38749
2017-03-03Integrate `TokenStream`.Jeffrey Seyfried-4/+3
2017-03-02Rollup merge of #40129 - abonander:proc_macro_bang, r=jseyfriedCorey Farwell-0/+4
Implement function-like procedural macros ( `#[proc_macro]`) Adds the `#[proc_macro]` attribute, which expects bare functions of the kind `fn(TokenStream) -> TokenStream`, which can be invoked like `my_macro!()`. cc rust-lang/rfcs#1913, #38356 r? @jseyfried cc @nrc
2017-02-28Implement function-like procedural macros ( `#[proc_macro]`)Austin Bonander-0/+4
2017-02-28Add `syntax::ext::tt::quoted::{TokenTree, ..}` and remove ↵Jeffrey Seyfried-2/+1
`tokenstream::TokenTree::Sequence`.
2017-01-22Refactor `TokenStream`.Jeffrey Seyfried-5/+6
2017-01-15Refactor `proc_macro::TokenStream` to use ↵Austin Bonander-26/+47
`syntax::tokenstream::TokenStream`; fix tests for changed semantics
2017-01-08Auto merge of #38679 - alexcrichton:always-deny-warnings, r=nrcbors-1/+1
Remove not(stage0) from deny(warnings) Historically this was done to accommodate bugs in lints, but there hasn't been a bug in a lint since this feature was added which the warnings affected. Let's completely purge warnings from all our stages by denying warnings in all stages. This will also assist in tracking down `stage0` code to be removed whenever we're updating the bootstrap compiler.
2017-01-04Document custom derive.Steve Klabnik-4/+2
These are some bare-bones documentation for custom derive, needed to stabilize "macros 1.1", https://github.com/rust-lang/rust/issues/35900 The book chapter is based off of a blog post by @cbreeden, https://cbreeden.github.io/Macros11/ Normally, we have a policy of not mentioning external crates in documentation. However, given that syn/quote are basically neccesary for properly using macros 1.1, I feel that not including them here would make the documentation very bad. So the rules should be bent in this instance.
2017-01-02rustc: Stabilize the `proc_macro` featureAlex Crichton-3/+6
This commit stabilizes the `proc_macro` and `proc_macro_lib` features in the compiler to stabilize the "Macros 1.1" feature of the language. Many more details can be found on the tracking issue, #35900. Closes #35900
2016-12-29Remove not(stage0) from deny(warnings)Alex Crichton-1/+1
Historically this was done to accommodate bugs in lints, but there hasn't been a bug in a lint since this feature was added which the warnings affected. Let's completely purge warnings from all our stages by denying warnings in all stages. This will also assist in tracking down `stage0` code to be removed whenever we're updating the bootstrap compiler.