about summary refs log tree commit diff
path: root/src/libsyntax/parse
AgeCommit message (Collapse)AuthorLines
2018-04-14Rollup merge of #49852 - alexcrichton:fix-more-proc-macros, r=nrckennytm-9/+22
proc_macro: Avoid cached TokenStream more often This commit adds even more pessimization to use the cached `TokenStream` inside of an AST node. As a reminder the `proc_macro` API requires taking an arbitrary AST node and transforming it back into a `TokenStream` to hand off to a procedural macro. Such functionality isn't actually implemented in rustc today, so the way `proc_macro` works today is that it stringifies an AST node and then reparses for a list of tokens. This strategy unfortunately loses all span information, so we try to avoid it whenever possible. Implemented in #43230 some AST nodes have a `TokenStream` cache representing the tokens they were originally parsed from. This `TokenStream` cache, however, has turned out to not always reflect the current state of the item when it's being tokenized. For example `#[cfg]` processing or macro expansion could modify the state of an item. Consequently we've seen a number of bugs (#48644 and #49846) related to using this stale cache. This commit tweaks the usage of the cached `TokenStream` to compare it to our lossy stringification of the token stream. If the tokens that make up the cache and the stringified token stream are the same then we return the cached version (which has correct span information). If they differ, however, then we will return the stringified version as the cache has been invalidated and we just haven't figured that out. Closes #48644 Closes #49846
2018-04-14macros: Do not match on "complex" nonterminals requiring AST comparisonsVadim Petrochenkov-1/+17
2018-04-12Avoid comparing fields by name when possibleVadim Petrochenkov-3/+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-32/+5
2018-04-12Auto merge of #49698 - SimonSapin:unicode-for-everyone, r=alexcrichtonbors-1/+1
Merge the std_unicode crate into the core crate [The standard library facade](https://github.com/rust-lang/rust/issues/27783) has historically contained a number of crates with different roles, but that number has decreased over time. `rand` and `libc` have moved to crates.io, and [`collections` was merged into `alloc`](https://github.com/rust-lang/rust/pull/42648). Today we have `core` that applies everywhere, `std` that expects a full operating system, and `alloc` in-between that only requires a memory allocator (which can be provided by users)… and `std_unicode`, which doesn’t really have a reason to be separate anymore. It contains functionality based on Unicode data tables that can be large, but as long as relevant functions are not called the tables should be removed from binaries by linkers. This deprecates the unstable `std_unicode` crate and moves all of its contents into `core`, replacing them with `pub use` reexports. The crate can be removed later. This also removes the `CharExt` trait (replaced with inherent methods in libcore) and `UnicodeStr` trait (merged into `StrExt`). There traits were both unstable and not intended to be used or named directly. A number of new items are newly-available in libcore and instantly stable there, but only if they were already stable in libstd. Fixes #49319.
2018-04-12Deprecate the std_unicode crateSimon Sapin-1/+1
2018-04-11Rollup merge of #49525 - varkor:sort_by_cached_key-conversion, r=scottmcmkennytm-1/+1
Use sort_by_cached_key where appropriate A follow-up to https://github.com/rust-lang/rust/pull/48639, converting various slice sorting calls to `sort_by_cached_key` when the key functions are more expensive.
2018-04-10proc_macro: Avoid cached TokenStream more oftenAlex Crichton-9/+22
This commit adds even more pessimization to use the cached `TokenStream` inside of an AST node. As a reminder the `proc_macro` API requires taking an arbitrary AST node and transforming it back into a `TokenStream` to hand off to a procedural macro. Such functionality isn't actually implemented in rustc today, so the way `proc_macro` works today is that it stringifies an AST node and then reparses for a list of tokens. This strategy unfortunately loses all span information, so we try to avoid it whenever possible. Implemented in #43230 some AST nodes have a `TokenStream` cache representing the tokens they were originally parsed from. This `TokenStream` cache, however, has turned out to not always reflect the current state of the item when it's being tokenized. For example `#[cfg]` processing or macro expansion could modify the state of an item. Consequently we've seen a number of bugs (#48644 and #49846) related to using this stale cache. This commit tweaks the usage of the cached `TokenStream` to compare it to our lossy stringification of the token stream. If the tokens that make up the cache and the stringified token stream are the same then we return the cached version (which has correct span information). If they differ, however, then we will return the stringified version as the cache has been invalidated and we just haven't figured that out. Closes #48644 Closes #49846
2018-04-10Auto merge of #49390 - Zoxc:sync-syntax, r=michaelwoeristerbors-29/+18
More thread-safety changes r? @michaelwoerister
2018-04-09in which `!` is suggested for erroneous identifier `not`Zack M. Davis-2/+52
Impressing confused Python users with magical diagnostics is perhaps worth this not-grossly-unreasonable (only 40ish lines) extra complexity in the parser? Thanks to Vadim Petrochenkov for guidance. This resolves #46836.
2018-04-09don't suggest placing code in block if next token is open-braceZack M. Davis-0/+5
Thanks to the inestimably inimitable Esteban "Estebank" Küber for pointing this out. This is relevant to #46836.
2018-04-09Convert sort_by to sort_by_cached_keyvarkor-1/+1
2018-04-06Use `Ident` instead of `Name` in `MetaItem`Vadim Petrochenkov-5/+4
2018-04-06Make lifetime nonterminals closer to identifier nonterminalsVadim Petrochenkov-42/+42
2018-04-06Remove more duplicated spansVadim Petrochenkov-33/+24
2018-04-06Rename `ast::Variant_::name` into `ident` + Fix rebaseVadim Petrochenkov-8/+4
2018-04-06Get rid of `SpannedIdent`Vadim Petrochenkov-42/+31
2018-04-06Rename `PathSegment::identifier` to `ident`Vadim Petrochenkov-2/+2
2018-04-06Use `Span` instead of `SyntaxContext` in `Ident`Vadim Petrochenkov-1/+1
2018-04-05Rollup merge of #49350 - abonander:macros-in-extern, r=petrochenkovAlex Crichton-55/+71
Expand macros in `extern {}` blocks This permits macro and proc-macro and attribute invocations (the latter only with the `proc_macro` feature of course) in `extern {}` blocks, gated behind a new `macros_in_extern` feature. A tracking issue is now open at #49476 closes #48747
2018-04-03expand macro invocations in `extern {}` blocksAustin Bonander-55/+71
2018-04-03Remove all unstable placement featuresAidan Hobson Sayers-13/+0
Closes #22181, #27779
2018-04-02Auto merge of #49124 - abonander:attr-macro-stmt-expr, r=abonanderbors-0/+3
Expand Attributes on Statements and Expressions This enables attribute-macro expansion on statements and expressions while retaining the `stmt_expr_attributes` feature requirement for attributes on expressions. closes #41475 cc #38356 @petrochenkov @jseyfried r? @nrc
2018-04-02Expand attribute macros on statements and expressions.Austin Bonander-0/+3
Retains the `stmt_expr_attributes` feature requirement for attributes on expressions. closes #41475 cc #38356
2018-04-01Auto merge of #49478 - Phlosioneer:fix-windows-file-not-found, r=petrochenkovbors-1/+1
Fix escaped backslash in windows file not found message When a module is declared, but no matching file exists, rustc gives an error like `help: name the file either foo.rs or foo/mod.rs inside the directory "src/bar"`. However, at on windows, the backslash was double-escaped when naming the directory. It did this because the string was printed in debug mode (`"{:?}"`) to surround it with quotes. However, it should just be printed like any other directory in an error message and surrounded by escaped quotes, rather than relying on the debug print to add quotes (`"\"{}\""`). I also checked the test suite to see if this output is being correctly tested. It's not - it only tests up to the word "directory". Presumably this is so that the test is not dependent on its exact position in the source tree. I don't know a better way to test this, unless the test suite supports regex?
2018-03-29Fix escaped backslash in windows file not found messagePhlosioneer-1/+1
When a module is declared, but no matching file exists, rustc gives an error like 'help: name the file either foo.rs or foo/mod.rs inside the directory "src/bar"'. However, at on windows, the backslash was double-escaped when naming the directory. It did this because the string was printed in debug mode ( "{:?}" ) to surround it with quotes. However, it should just be printed like any other directory in an error message and surrounded by escaped quotes, rather than relying on the debug print to add quotes ( "\"{}\"" ).
2018-03-28Make ParseSess thread-safeJohn Kåre Alsaker-14/+12
2018-03-28Make LazyTokenStream thread-safeJohn Kåre Alsaker-15/+6
2018-03-27Rollup merge of #49395 - petrochenkov:obsolete, r=alexcrichtonkennytm-74/+0
libsyntax: Remove obsolete.rs This little piece of infra is obsolete (ha-ha) and is unlikely to be used in the future, even if new obsolete syntax appears.
2018-03-27libsyntax: Remove obsolete.rsVadim Petrochenkov-74/+0
2018-03-27Fix pretty-printing for raw identifiersVadim Petrochenkov-1/+8
2018-03-24Better diagnostics for '..' pattern fragment not in the last positionHidehito Yabuuchi-1/+7
2018-03-23Merge branch 'master' of https://github.com/Lymia/rust into rollupAlex Crichton-70/+144
2018-03-22Clean up raw identifier handling when recovering tokens from AST.Lymia Aluysia-1/+1
2018-03-22Rollup merge of #49117 - nivkner:fixme_fixup3, r=estebankkennytm-2/+0
address some FIXME whose associated issues were marked as closed part of #44366
2018-03-20Auto merge of #49190 - kennytm:rollup, r=kennytmbors-10/+1
Rollup of 17 pull requests - Successful merges: #46518, #48810, #48834, #48902, #49004, #49092, #49096, #49099, #49104, #49125, #49139, #49152, #49157, #49161, #49166, #49176, #49184 - Failed merges:
2018-03-20Stabilize slice patterns without `..`Vadim Petrochenkov-1/+1
Merge `feature(advanced_slice_patterns)` into `feature(slice_patterns)`
2018-03-20Rollup merge of #49104 - csmoe:semicolon_error, r=petrochenkovkennytm-10/+1
improve error message of inner attribute syntax Fixes #49040
2018-03-18Return a is_raw parameter from Token::ident rather than having separate methods.Lymia Aluysia-30/+15
2018-03-18Move raw_identifiers check to the lexer.Lymia Aluysia-4/+5
2018-03-18Feature gate raw identifiers.Lymia Aluysia-1/+9
2018-03-18Initial implementation of RFC 2151, Raw IdentifiersLymia Aluysia-73/+153
2018-03-18Auto merge of #48917 - petrochenkov:import, r=oli-obkbors-82/+39
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-17Cleanup import parsingVadim Petrochenkov-54/+23
Fix spans of root segments
2018-03-17Rename `Span::empty` to `Span::shrink_to_lo`, add `Span::shrink_to_hi`Vadim Petrochenkov-2/+2
2018-03-17AST: Keep distinction between `path` and `::path` in imports and visibilitiesVadim Petrochenkov-10/+6
Add the root segment for name resolution purposes only
2018-03-17AST: Make renames in imports closer to the sourceVadim Petrochenkov-3/+1
Fix `unused_import_braces` lint false positive on `use prefix::{self as rename}`
2018-03-17AST/HIR: Clarify what the optional name in extern crate items meanVadim Petrochenkov-13/+7
2018-03-17syntax: Make `_` an identifierVadim Petrochenkov-35/+24
2018-03-17remove FIXME(#8372) since for-loops wont support borrowing iteratorsNiv Kaminer-2/+0