about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
AgeCommit message (Collapse)AuthorLines
2016-05-27Auto merge of #33706 - jseyfried:refactor_cfg, r=nrcbors-82/+65
Perform `cfg` attribute processing during macro expansion and fix bugs This PR refactors `cfg` attribute processing and fixes bugs. More specifically: - It merges gated feature checking for stmt/expr attributes, `cfg_attr` processing, and `cfg` processing into a single fold. - This allows feature gated `cfg` variables to be used in `cfg_attr` on unconfigured items. All other feature gated attributes can already be used on unconfigured items. - It performs `cfg` attribute processing during macro expansion instead of after expansion so that macro-expanded items are configured the same as ordinary items. In particular, to match their non-expanded counterparts, - macro-expanded unconfigured macro invocations are no longer expanded, - macro-expanded unconfigured macro definitions are no longer usable, and - feature gated `cfg` variables on macro-expanded macro definitions/invocations are now errors. This is a [breaking-change]. For example, the following would break: ```rust macro_rules! m { () => { #[cfg(attr)] macro_rules! foo { () => {} } foo!(); // This will be an error macro_rules! bar { () => { fn f() {} } } #[cfg(attr)] bar!(); // This will no longer be expanded ... fn g() { f(); } // ... so that `f` will be unresolved. #[cfg(target_thread_local)] // This will be a gated feature error macro_rules! baz { () => {} } } } m!(); ``` r? @nrc
2016-05-27Rollup merge of #33644 - petrochenkov:selfast, r=nrcManish Goregaokar-1/+0
The AST part of https://github.com/rust-lang/rust/pull/33505. https://github.com/rust-lang/rust/pull/33505 isn't landed yet, so this PR is based on top of it. r? @nrc plugin-[breaking-change] cc #31645 @Manishearth
2016-05-27Rollup merge of #33351 - birkenfeld:loop-label-spans, r=pnkfelixManish Goregaokar-7/+7
This makes the \"shadowing labels\" warning *not* print the entire loop as a span, but only the lifetime. Also makes #31719 go away, but does not fix its root cause (the span of the expanded loop is still wonky, but not used anymore).
2016-05-27Refactor `expand_expr`Jeffrey Seyfried-35/+22
2016-05-27Strip unconfigured items during macro expansionJeffrey Seyfried-1/+33
2016-05-27Update spans' `expn_id` during the marking foldJeffrey Seyfried-56/+20
2016-05-25Add a new AST-only type variant `ImplicitSelf`Vadim Petrochenkov-1/+0
2016-05-25Remove ExplicitSelf from ASTVadim Petrochenkov-1/+1
2016-05-24syntax/hir: give loop labels a spanGeorg Brandl-7/+7
This makes the "shadowing labels" warning *not* print the entire loop as a span, but only the lifetime. Also makes #31719 go away, but does not fix its root cause (the span of the expanded loop is still wonky, but not used anymore).
2016-05-24Add comments and fix a nitJeffrey Seyfried-1/+9
2016-05-21Move `placement_in_syntax` gated feature checking from expansion to the ↵Jeffrey Seyfried-16/+0
post-expansion visitor
2016-05-21Refactor away `check_attributes`Jeffrey Seyfried-11/+7
2016-05-21Refactor away `expand_item_mac`Jeffrey Seyfried-159/+85
2016-05-21Refactor out `mac_result` in `expand_mac_invoc`Jeffrey Seyfried-54/+53
2016-05-21Check attributes in `expand_mac_invoc`Jeffrey Seyfried-22/+12
2016-05-21Use `expand_mac_invoc` in `expand_pat`Jeffrey Seyfried-75/+3
2016-05-21Re-fold expanded items in `expand_mac_invoc`Jeffrey Seyfried-63/+13
2016-05-21Improve diagnosticsJeffrey Seyfried-5/+3
2016-05-21Introduce `MacroGenerable` traitJeffrey Seyfried-53/+46
2016-05-18Fix bug in macro expression spansJeffrey Seyfried-7/+1
2016-05-02thread tighter span for closures aroundNiko Matsakis-3/+3
Track the span corresponding to the `|...|` part of the closure.
2016-04-30Auto merge of #32846 - jseyfried:allow_unconfigured_gated_expanded_items, r=nrcbors-3/+1
Avoid gated feature checking unconfigured expanded items Avoid gated feature checking unconfigured macro-expanded items (fixes #32840). Unconfigured items that are not macro-expanded are already not gated feature checked. r? @nrc
2016-04-27Auto merge of #32791 - LeoTestard:feature-gate-clean, r=nikomatsakisbors-30/+37
Feature gate clean This PR does a bit of cleaning in the feature-gate-handling code of libsyntax. It also fixes two bugs (#32782 and #32648). Changes include: * Change the way the existing features are declared in `feature_gate.rs`. The array of features and the `Features` struct are now defined together by a single macro. `featureck.py` has been updated accordingly. Note: there are now three different arrays for active, removed and accepted features instead of a single one with a `Status` item to tell wether a feature is active, removed, or accepted. This is mainly due to the way I implemented my macro in the first time and I can switch back to a single array if needed. But an advantage of the way it is now is that when an active feature is used, the parser only searches through the list of active features. It goes through the other arrays only if the feature is not found. I like to think that error checking (in this case, checking that an used feature is active) does not slow down compilation of valid code. :) But this is not very important... * Feature-gate checking pass now use the `Features` structure instead of looking through a string vector. This should speed them up a bit. The construction of the `Features` struct should be faster too since it is build directly when parsing features instead of calling `has_feature` dozens of times. * The MacroVisitor pass has been removed, it was mostly useless since the `#[cfg]-stripping` phase happens before (fixes #32648). The features that must actually be checked before expansion are now checked at the time they are used. This also allows us to check attributes that are generated by macro expansion and not visible to MacroVisitor, but are also removed by macro expansion and thus not visible to PostExpansionVisitor either. This fixes #32782. Note that in order for `#[derive_*]` to be feature-gated but still accepted when generated by `#[derive(Trait)]`, I had to do a little bit of trickery with spans that I'm not totally confident into. Please review that part carefully. (It's in `libsyntax_ext/deriving/mod.rs`.):: Note: this is a [breaking change], since programs with feature-gated attributes on macro-generated macro invocations were not rejected before. For example: ```rust macro_rules! bar ( () => () ); macro_rules! foo ( () => ( #[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps bar!(); ); ); ``` foo!();
2016-04-25Rollup merge of #33041 - petrochenkov:path, r=nrc,ManishearthManish Goregaokar-7/+7
Paths are mostly parsed without taking whitespaces into account, e.g. `std :: vec :: Vec :: new ()` parses successfully, however, there are some special cases involving keywords `super`, `self` and `Self`. For example, `self::` is considered a path start only if there are no spaces between `self` and `::`. These restrictions probably made sense when `self` and friends weren't keywords, but now they are unnecessary. The first two commits remove this special treatment of whitespaces by removing `token::IdentStyle` entirely and therefore fix https://github.com/rust-lang/rust/issues/14109. This change also affects naked `self` and `super` (which are not tightly followed by `::`, obviously) they can now be parsed as paths, however they are still not resolved correctly in imports (cc @jseyfried, see `compile-fail/use-keyword.rs`), so https://github.com/rust-lang/rust/issues/29036 is not completely fixed. The third commit also makes `super`, `self`, `Self` and `static` keywords nominally (before this they acted as keywords for all purposes) and removes most of remaining \"special idents\". The last commit (before tests) contains some small improvements - some qualified paths with type parameters are parsed correctly, `parse_path` is not used for parsing single identifiers, imports are sanity checked for absence of type parameters - such type parameters can be generated by syntax extensions or by macros when https://github.com/rust-lang/rust/issues/10415 is fixed (~~soon!~~already!). This patch changes some pretty basic things in `libsyntax`, like `token::Token` and the keyword list, so it's a plugin-[breaking-change]. r? @eddyb
2016-04-24syntax: Check paths in visibilities for type parametersVadim Petrochenkov-1/+1
syntax: Merge PathParsingMode::NoTypesAllowed and PathParsingMode::ImportPrefix syntax: Rename PathParsingMode and its variants to better express their purpose syntax: Remove obsolete error message about 'self lifetime syntax: Remove ALLOW_MODULE_PATHS workaround syntax/resolve: Adjust some error messages resolve: Compare unhygienic (not renamed) names with keywords::Invalid, invalid identifiers may appear to be valid after renaming
2016-04-24syntax: Merge keywords and remaining special idents in one listVadim Petrochenkov-6/+6
Simplify the macro used for generation of keywords Make `Keyword::ident` private
2016-04-24syntax: Make static/super/self/Self keywords + special ident cleanupVadim Petrochenkov-5/+5
2016-04-24thread tighter span for closures aroundNiko Matsakis-5/+8
Track the span corresponding to the `|...|` part of the closure.
2016-04-22Remove some useless code.Leo Testard-4/+6
2016-04-22Remove the MacroVisitor pass.Leo Testard-19/+24
This pass was supposed to check use of gated features before `#[cfg]`-stripping but this was not the case since it in fact happens after. Checks that are actually important and must be done before macro expansion are now made where the features are actually used. Close #32648. Also ensure that attributes on macro-generated macro invocations are checked as well. Close #32782 and #32655.
2016-04-21Generate the features structure and arrays with new macros.Leo Testard-7/+7
This is more readable, safer, and allows for a much more efficient parsing.
2016-04-13Fixes #32922, a macro hygiene bugJeffrey Seyfried-8/+9
2016-04-09Remove redundant call to `expand_item_multi_modifier`Jeffrey Seyfried-3/+1
2016-03-25do not overwrite spans as eagerlyNiko Matsakis-6/+36
this was required to preserve the span from the #[structural_match] attribute -- but honestly I am not 100% sure if it makes sense.
2016-03-14Add `default` as contextual keyword, and parse it for impl items.Aaron Turon-0/+1
2016-03-09Auto merge of #31631 - jonas-schievink:agoraphobia, r=nrcbors-3/+3
[breaking-batch] Move more uses of `panictry!` out of libsyntax
2016-03-02Fix the search paths for macro-expanded non-inline modulesJeffrey Seyfried-2/+45
2016-02-16Move more uses of `panictry!` out of libsyntaxJonas Schievink-3/+3
[breaking-change] for syntax extensions
2016-02-13Rename ast::Pat_ and its variantsVadim Petrochenkov-12/+12
2016-02-12Use more autoderef in libsyntaxJonas Schievink-1/+1
2016-02-11Remove some unnecessary indirection from AST structuresVadim Petrochenkov-44/+45
2016-02-11[breaking-change] don't glob export ast::TraitItemKind variantsOliver 'ker' Schneider-3/+3
2016-02-11[breaking-change] don't glob export ast::MetaItem_Oliver 'ker' Schneider-1/+1
2016-02-11[breaking-change] don't glob export ast::MacStmtStyleOliver 'ker' Schneider-1/+1
2016-02-11[breaking-change] don't glob export ast::Item_ variantsOliver 'ker' Schneider-12/+12
2016-02-11[breaking-change] don't pub export ast::Stmt_ variantsOliver Schneider-7/+6
2016-02-11[breaking-change] don't pub export ast::Ty_ variantsOliver Schneider-2/+2
2016-02-11[breaking-change] don't glob export ast::Expr_ variantsOliver Schneider-20/+20
2016-02-11[breaking-change] don't glob export ast::Decl_ variantsOliver Schneider-3/+3
2016-01-22The war on abort_if_errorsNick Cameron-1/+6