about summary refs log tree commit diff
path: root/src/libsyntax/ext
AgeCommit message (Collapse)AuthorLines
2018-05-16label-break-value: Parsing and AST/HIR changesest31-1/+1
2018-05-15Represent lifetimes as two joint tokens in proc macrosVadim Petrochenkov-0/+1
2018-05-13stabilize :lifetimeAlex Burka-13/+1
2018-05-13Macros: Add a 'literal' fragment specifierDan Aloni-2/+21
Implements RFC 1576. See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md Changes are mostly in libsyntax, docs, and tests. Feature gate is enabled for 1.27.0. Many thanks to Vadim Petrochenkov for following through code reviews and suggestions. Example: ````rust macro_rules! test_literal { ($l:literal) => { println!("literal: {}", $l); }; ($e:expr) => { println!("expr: {}", $e); }; } fn main() { let a = 1; test_literal!(a); test_literal!(2); test_literal!(-3); } ``` Output: ``` expr: 1 literal: 2 literal: -3 ```
2018-05-03Auto merge of #50413 - kennytm:rollup, r=kennytmbors-1/+7
Rollup of 12 pull requests Successful merges: - #50302 (Add query search order check) - #50320 (Fix invalid path generation in rustdoc search) - #50349 (Rename "show type declaration" to "show declaration") - #50360 (Clarify wordings of the `unstable_name_collision` lint.) - #50365 (Use two vectors in nearest_common_ancestor.) - #50393 (Allow unaligned reads in constants) - #50401 (Revert "Implement FromStr for PathBuf") - #50406 (Forbid constructing empty identifiers from concat_idents) - #50407 (Always inline simple BytePos and CharPos methods.) - #50416 (check if the token is a lifetime before parsing) - #50417 (Update Cargo) - #50421 (Fix ICE when using a..=b in a closure.) Failed merges:
2018-05-03check if the token is a lifetime before parsingrleungx-1/+7
2018-05-02make it compile againflip1995-1/+1
2018-05-02Gate tool_attributes featureSeiichi Uchida-1/+5
2018-05-02Remove Option from the return type of Attribute::name()Seiichi Uchida-1/+2
2018-05-02Allow Path for name of MetaItemSeiichi Uchida-3/+2
2018-04-30Auto merge of #50092 - abonander:issue-49934, r=petrochenkovbors-13/+76
Warn on pointless #[derive] in more places This fixes the regression in #49934 and ensures that unused `#[derive]` invocations on statements, expressions and generic type parameters survive to trip the `unused_attributes` lint. There is a separate warning hardcoded for `#[derive]` on macro invocations since linting (even the early-lint pass) occurs after expansion. This also adds regression tests for some nodes that were already warning properly. closes #49934
2018-04-29Warn on pointless `#[derive]` in more placesAustin Bonander-13/+76
This fixes the regression in #49934 and ensures that unused `#[derive]`s on statements, expressions and generic type parameters survive to trip the `unused_attributes` lint. For `#[derive]` on macro invocations it has a hardcoded warning since linting occurs after expansion. This also adds regression testing for some nodes that were already warning properly. closes #49934
2018-04-26rustc_target: move in syntax::abi and flip dependency.Irina Popa-1/+1
2018-04-20rustc: Tweak custom attribute capabilitiesAlex Crichton-1/+74
This commit starts to lay some groundwork for the stabilization of custom attribute invocations and general procedural macros. It applies a number of changes discussed on [internals] as well as a [recent issue][issue], namely: * The path used to specify a custom attribute must be of length one and cannot be a global path. This'll help future-proof us against any ambiguities and give us more time to settle the precise syntax. In the meantime though a bare identifier can be used and imported to invoke a custom attribute macro. A new feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths and absolute paths. * The set of items which can be annotated by a custom procedural attribute has been restricted. Statements, expressions, and modules are disallowed behind two new feature gates: `proc_macro_expr` and `proc_macro_mod`. * The input to procedural macro attributes has been restricted and adjusted. Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token stream, but after this PR it will only receive `bar` (the delimiters were removed). Invocations like `#[foo]` are still allowed and will be invoked in the same way as `#[foo()]`. This is a **breaking change** for all nightly users as the syntax coming in to procedural macros will be tweaked slightly. * Procedural macros (`foo!()` style) can only be expanded to item-like items by default. A separate feature gate, `proc_macro_non_items`, is required to expand to items like expressions, statements, etc. Closes #50038 [internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252 [issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-18Auto merge of #49993 - nnethercote:shrink-Token, r=alexcrichtonbors-1/+6
Change the hashcounts in raw `Lit` variants from usize to u16. This reduces the size of `Token` from 32 bytes to 24 bytes on 64-bit platforms.
2018-04-16Auto merge of #49719 - mark-i-m:no_sep, r=petrochenkovbors-67/+22
Update `?` repetition disambiguation. **Do not merge** (yet) This is a test implementation of some ideas from discussion in https://github.com/rust-lang/rust/issues/48075 . This PR - disallows `?` repetition from taking a separator, since the separator is never used. - disallows the use of `?` as a separator. This allows patterns like `$(a)?+` to match `+` and `a+` rather than `a?a?a`. This is a _breaking change_, but maybe that's ok? Perhaps a crater run is the right approach? cc @durka @alexreg @nikomatsakis
2018-04-14Add error codes for libsyntax_extGuillaume Gomez-1/+4
2018-04-12Avoid comparing fields by name when possibleVadim Petrochenkov-2/+2
Resolve them into field indices once and then use those resolutions + Fix rebase
2018-04-12AST/HIR: Merge field access expressions for named and numeric fieldsVadim Petrochenkov-2/+2
2018-04-12Change the hashcounts in raw `Lit` variants from usize to u16.Nicholas Nethercote-1/+6
This reduces the size of `Token` from 32 bytes to 24 bytes on 64-bit platforms.
2018-04-10Auto merge of #49390 - Zoxc:sync-syntax, r=michaelwoeristerbors-9/+11
More thread-safety changes r? @michaelwoerister
2018-04-06Use `Ident` instead of `Name` in `MetaItem`Vadim Petrochenkov-12/+14
2018-04-06Make lifetime nonterminals closer to identifier nonterminalsVadim Petrochenkov-2/+2
2018-04-06Remove more duplicated spansVadim Petrochenkov-11/+13
2018-04-06Rename `ast::Variant_::name` into `ident` + Fix rebaseVadim Petrochenkov-2/+2
2018-04-06Use `Span::apply_mark` where possibleVadim Petrochenkov-5/+5
2018-04-06Get rid of `SpannedIdent`Vadim Petrochenkov-19/+14
2018-04-06Rename `PathSegment::identifier` to `ident`Vadim Petrochenkov-9/+9
2018-04-06Use `Span` instead of `SyntaxContext` in `Ident`Vadim Petrochenkov-11/+8
2018-04-05No separator for `?`. No `?` as a separator.Mark Mansi-67/+22
2018-04-03expand macro invocations in `extern {}` blocksAustin Bonander-0/+97
2018-04-02Expand attribute macros on statements and expressions.Austin Bonander-19/+78
Retains the `stmt_expr_attributes` feature requirement for attributes on expressions. closes #41475 cc #38356
2018-03-28Make SyntaxExtension thread-safeJohn Kåre Alsaker-9/+11
2018-03-27Auto merge of #49279 - varkor:generated-closure-return-type, r=alexcrichtonbors-5/+5
Fix implicit closure return type generation for libsyntax The `lambda` function for constructing closures in libsyntax was explicitly setting the return type to `_`, which resulted in incorrect corresponding syntax (as `|| -> _ x` is not valid, without the enclosing brackets). This meant the generated code, when printed, was invalid. I also took the opportunity to slightly improve the generated code for the `RustcEncodable::encode` method for unit structs. Fixes #42213.
2018-03-22Use FunctionRetTy::Default rather than an explicit TyKind::Infer for ↵varkor-5/+5
lambda-building This prevents explicit `-> _` return type annotations for closures generated by `lambda`.
2018-03-22Clean up raw identifier handling when recovering tokens from AST.Lymia Aluysia-3/+4
2018-03-18Return a is_raw parameter from Token::ident rather than having separate methods.Lymia Aluysia-4/+4
2018-03-18Initial implementation of RFC 2151, Raw IdentifiersLymia Aluysia-21/+24
2018-03-18Auto merge of #48917 - petrochenkov:import, r=oli-obkbors-13/+16
syntax: Make imports in AST closer to the source and cleanup their parsing This is a continuation of https://github.com/rust-lang/rust/pull/45846 in some sense.
2018-03-17Rename `Span::empty` to `Span::shrink_to_lo`, add `Span::shrink_to_hi`Vadim Petrochenkov-4/+4
2018-03-17AST: Keep distinction between `path` and `::path` in imports and visibilitiesVadim Petrochenkov-3/+7
Add the root segment for name resolution purposes only
2018-03-17AST: Make renames in imports closer to the sourceVadim Petrochenkov-6/+5
Fix `unused_import_braces` lint false positive on `use prefix::{self as rename}`
2018-03-17Reject `_` in `ident` matcherVadim Petrochenkov-17/+19
2018-03-17syntax: Make `_` an identifierVadim Petrochenkov-3/+1
2018-03-16Auto merge of #48524 - abonander:check-macro-stability, r=petrochenkovbors-17/+56
check stability of macro invocations I haven't implemented tests yet but this should be a pretty solid prototype. I think as-implemented it will also stability-check macro invocations in the same crate, dunno if we want that or not. I don't know if we want this to go through `rustc::middle::stability` or not, considering the information there wouldn't be available at the time of macro expansion (even for external crates, right?). r? @nrc closes #34079 cc @petrochenkov @durka @jseyfried #38356
2018-03-13Fix ICE on malformed plugin attributesMichael Lamparski-2/+4
2018-03-07check stability of macro invocationsAustin Bonander-17/+56
2018-03-05Turn features() into a query.Michael Woerister-17/+15
2018-03-02Replace Rc with Lrc for shared dataJohn Kåre Alsaker-24/+27
2018-02-28Auto merge of #48056 - ExpHP:macro-commas, r=dtolnaybors-2/+4
Comprehensively support trailing commas in std/core macros I carefully organized the changes into four commits: * Test cases * Fixes for `macro_rules!` macros * Fixes for builtin macros * Docs for builtins **I can easily scale this back to just the first two commits for now if such is desired.** ### Breaking (?) changes * This fixes #48042, which is a breaking change that I hope people can agree is just a bugfix for an extremely dark corner case. * To fix five of the builtins, this changes `syntax::ext::base::get_single_str_from_tts` to accept a trailing comma, and revises the documentation so that this aspect is not surprising. **I made this change under the (hopefully correct) understanding that `libsyntax` is private rustc implementation detail.** After reviewing all call sites (which were, you guessed it, *precisely those five macros*), I believe the revised semantics are closer to the intended spirit of the function. ### Changes which may require concensus Up until now, it could be argued that some or all the following macros did not conceptually take a comma-separated list, because they only took one argument: * **`cfg(unix,)`** (most notable since cfg! is unique in taking a meta tag) * **`include{,_bytes,_str}("file.rs",)`** (in item form this might be written as "`include!{"file.rs",}`" which is even slightly more odd) * **`compile_error("message",);`** * **`option_env!("PATH",)`** * **`try!(Ok(()),)`** So I think these particular changes may require some sort of consensus. **All of the fixes for builtins are included this list, so if we want to defer these decisions to later then I can scale this PR back to just the first two commits.** ### Other notes/general requests for comment * Do we have a big checklist somewhere of "things to do when adding macros?" My hope is for `run-pass/macro-comma-support.rs` to remain comprehensive. * Originally I wanted the tests to also comprehensively forbid double trailing commas. However, this didn't work out too well: [see this gist and the giant FIXME in it](https://gist.github.com/ExpHP/6fc40e82f3d73267c4e590a9a94966f1#file-compile-fail_macro-comma-support-rs-L33-L50) * I did not touch `select!`. It appears to me to be a complete mess, and its trailing comma mishaps are only the tip of the iceberg. * There are [some compile-fail test cases](https://github.com/ExpHP/rust/blob/5fa97c35da2f0ee/src/test/compile-fail/macro-comma-behavior.rs#L49-L52) that didn't seem to work (rustc emits errors, but compile-fail doesn't acknowledge them), so they are disabled. Any clues? (Possibly related: These happen to be precisely the set of errors which are tagged by rustc as "this error originates in a macro outside of the current crate".) --- Fixes #48042 Closes #46241