Commit Graph

732 Commits

Author SHA1 Message Date
Jeffrey Seyfried
44575f708a Rename mtwt to hygiene 2016-07-17 17:12:35 +00:00
Jeffrey Seyfried
76ed445622 Clean up and encapsulate syntax::ext::mtwt 2016-07-17 17:12:32 +00:00
bors
4db1874f4c Auto merge of #34570 - jseyfried:no_rename, r=nrc
Simplify the macro hygiene algorithm

This PR removes renaming from the hygiene algorithm and treats differently marked identifiers as unequal.

This change makes the scope of identifiers in `macro_rules!` items empty. That is, identifiers in `macro_rules!` definitions do not inherit any semantics from the `macro_rules!`'s scope.

Since `macro_rules!` macros are items, the scope of their identifiers "should" be the same as that of other items; in particular, the scope should contain only items. Since all items are unhygienic today, this would mean the scope should be empty.

However, the scope of an identifier in a `macro_rules!` statement today is the scope that the identifier would have if it replaced the `macro_rules!` (excluding anything unhygienic, i.e. locals only).

To continue to support this, this PR tracks the scope of each `macro_rules!` and uses it in `resolve` to ensure that an identifier expanded from a `macro_rules!` gets a chance to resolve to the locals in the `macro_rules!`'s scope.

This PR is a pure refactoring. After this PR,
 - `syntax::ext::expand` is much simpler.
 - We can expand macros in any order without causing problems for hygiene (needed for macro modularization).
 - We can deprecate or remove today's `macro_rules!` scope easily.
 - Expansion performance improves by 25%, post-expansion memory usage decreases by ~5%.
 - Expanding a block is no longer quadratic in the number of `let` statements (fixes #10607).

r? @nrc
2016-07-15 08:48:41 -07:00
Jeffrey Seyfried
c83e31e7c9 Include the MacroDefinition rib in the label ribs. 2016-07-15 05:16:21 +00:00
Jeffrey Seyfried
0701571fe7 Implement macro_rules! placeholders and the macro scope map 2016-07-14 01:34:37 +00:00
Jeffrey Seyfried
a15dfca54f Instead of renaming, treat differently marked identifiers as unequal 2016-07-14 01:34:31 +00:00
Jeffrey Seyfried
195a27faab Move node id assigning into resolve 2016-07-14 01:30:19 +00:00
Michael Rosenberg
5a99d79857 Fixed issue where importing a trait method directly and then calling the method causes a compiler panic 2016-07-13 02:34:10 -04:00
petrochenkov
d27e55c5d8 Stabilize FnOnce::Output + Fix rebase 2016-07-08 13:35:17 +03:00
Vadim Petrochenkov
eb32440d45 Do not generate Def::Err in bindings
Instead of Def::Err erroneous bindings can get usual definitions that doesn't require special cases later on and have less chances to generate ICE.
2016-07-08 12:42:57 +03:00
Vadim Petrochenkov
d3c94b25cb Don't generate Def::Err if it's not stored in def_map immediately 2016-07-08 12:36:45 +03:00
bors
b4e11c2af8 Auto merge of #34655 - jseyfried:improve_resolver_api, r=nrc
Add to `resolve`'s public API

This adds a public method `with_module_lexical_scope` to `Resolver` to allow users to resolve a path in the lexical scope of an arbitrary module.
r? @nrc
2016-07-06 23:18:23 -07:00
Steve Klabnik
26821a6f88 Rollup merge of #34636 - tshepang:shorten, r=GuillaumeGomez
doc: fix and shorten comment
2016-07-06 19:13:08 -04:00
Jeffrey Seyfried
58dd06d9e5 Add FIXME comment 2016-07-05 22:38:41 +00:00
Jeffrey Seyfried
6e0bd44fa3 Add method with_module_lexical_scope to Resolver. 2016-07-05 08:50:43 +00:00
Tshepang Lekhonkhobe
5efc780e14 doc: fix and shorten comment 2016-07-03 22:03:45 +02:00
Jeffrey Seyfried
d1e3d6272e Add the after_expand entry point between import resolution and the rest of name resolution 2016-07-01 00:07:32 +00:00
Manish Goregaokar
8e2598c3d2 Rollup merge of #34542 - jseyfried:fix_recursive_modules, r=nrc
Fix non-termination on recursive module re-exports in extern crates

Fixes #33776.
r? @nrc
2016-06-29 21:21:24 +05:30
Manish Goregaokar
2a0c2c3b3a Rollup merge of #34467 - GuillaumeGomez:err-codes, r=brson
Add new error codes and improve some explanations

r? @brson

cc @steveklabnik
cc @jonathandturner
2016-06-29 21:21:22 +05:30
Jeffrey Seyfried
232783c914 Fix infinite loop on recursive module exports in an extern crate 2016-06-28 23:03:56 +00:00
Jeffrey Seyfried
e58963d3e4 groundwork: create the Resolver earlier in phase 2 2016-06-28 05:28:27 +00:00
Jeffrey Seyfried
ec0c150152 groundwork: refactor the interface that resolve exposes to driver 2016-06-28 05:28:26 +00:00
Jeffrey Seyfried
4a13bcb4fb groundwork: use resolve_identifier instead of resolve_path to classify ident patterns 2016-06-28 05:28:23 +00:00
Jeffrey Seyfried
8748cd92d0 Rollup merge of #34316 - jseyfried:refactor_ast_stmt, r=eddyb
Refactor away `ast::Decl`, refactor `ast::Stmt`, and rename `ast::ExprKind::Again` to `ast::ExprKind::Continue`.
2016-06-26 02:17:27 +00:00
Jeffrey Seyfried
33ea1e330c Rollup merge of #33943 - jseyfried:libsyntax_cleanup, r=nrc
Miscellaneous low priority cleanup in `libsyntax`.
2016-06-26 02:15:04 +00:00
Guillaume Gomez
58955dee66 Add new error codes and improve some explanations 2016-06-26 02:26:42 +02:00
Jeffrey Seyfried
d3ae56d755 Rollup merge of #34403 - jonathandturner:move_liberror, r=alexcrichton
This PR refactors the 'errors' part of libsyntax into its own crate (librustc_errors).  This is the first part of a few refactorings to simplify error reporting and potentially support more output formats (like a standardized JSON output and possibly an --explain mode that can work with the user's code), though this PR stands on its own and doesn't assume further changes.

As part of separating out the errors crate, I have also refactored the code position portion of codemap into its own crate (libsyntax_pos).  While it's helpful to have the common code positions in a separate crate for the new errors crate, this may also enable further simplifications in the future.
2016-06-25 22:35:09 +00:00
Jeffrey Seyfried
4e2e31c118 Rollup merge of #34368 - petrochenkov:astqpath, r=Manishearth
The AST part of https://github.com/rust-lang/rust/pull/34365

plugin-[breaking-change] cc https://github.com/rust-lang/rust/issues/31645
2016-06-25 22:35:06 +00:00
Jeffrey Seyfried
f0310e061b Rollup merge of #34213 - josephDunne:trait_item_macros, r=jseyfried
**syntax-[breaking-change]** cc #31645
New `TraitItemKind::Macro` variant

This change adds support for macro expansion inside trait items by adding the new `TraitItemKind::Macro` and associated parsing code.
2016-06-25 22:35:01 +00:00
Jonathan Turner
6ae3502134 Move errors from libsyntax to its own crate 2016-06-23 08:07:35 -04:00
Liigo Zhuang
2d7bac7d86 Improve diagnostics E0425: use (public) items
E0425: unresolved name
2016-06-23 12:51:10 +08:00
Vadim Petrochenkov
f903c97959 Merge PatKind::QPath into PatKind::Path in AST 2016-06-20 23:39:02 +03:00
Guillaume Gomez
8637b4b034 Remove unused functions calls and unused E0406 2016-06-18 17:02:41 +02:00
Jeffrey Seyfried
f0b21c2d1e Rename ast::ExprKind::Again -> ast::ExprKind::Continue 2016-06-17 05:21:25 +00:00
Jeffrey Seyfried
962d5c16b5 Fix fallout 2016-06-17 05:21:23 +00:00
Jeffrey Seyfried
0644aba0b3 Remove the type parameter from syntax::visit::Visitor 2016-06-14 07:40:32 +00:00
Joseph Dunne
dc3d878e0f Add support for macro expansion inside trait items 2016-06-13 21:46:43 +01:00
Vadim Petrochenkov
6d7b35bd98 Address review comments + fix rebase 2016-06-10 01:06:37 +03:00
Vadim Petrochenkov
ee4e55398b Introduce TyCtxt::expect_def/expect_resolution helpers and use them where possible 2016-06-10 01:03:54 +03:00
Vadim Petrochenkov
4c30f6405c Move the hack with fake partial resolution for <A>::B from typeck to resolve 2016-06-10 01:03:54 +03:00
Vadim Petrochenkov
91b9dabdeb resolve: Rewrite resolve_pattern 2016-06-10 01:03:54 +03:00
Jeffrey Seyfried
49de80d7ea Refactor away the prelude injection pass 2016-06-07 00:31:42 +00:00
Jeffrey Seyfried
0f37edb758 Refactor away method resolve_name_in_lexical_scope of ModuleS 2016-06-06 21:51:11 +00:00
Eduard-Mihai Burtescu
0e98d1dc8f Rollup merge of #33955 - zackmdavis:explain_E0429, r=GuillaumeGomez
add explanation for E0429 (`self` use declaration must use brace syntax)

This is an item under #32777.

r? @GuillaumeGomez
2016-06-06 06:48:32 +03:00
bors
0646e8ae6e Auto merge of #33878 - GuillaumeGomez:improve_helps, r=jonathandturner
Improve help messages for E0425

Fixes #33876.

r? @Manishearth

cc @steveklabnik
cc @jonathandturner
2016-06-02 18:10:37 -07:00
ggomez
f4e6f3c186 Improve help messages for E0425 2016-06-02 13:58:21 +02:00
bors
c2cab1fd58 Auto merge of #33794 - petrochenkov:sanity, r=nrc
Add AST validation pass and move some checks to it

The purpose of this pass is to catch constructions that fit into AST data structures, but not permitted by the language. As an example, `impl`s don't have visibilities, but for convenience and uniformity with other items they are represented with a structure `Item` which has `Visibility` field.

This pass is intended to run after expansion of macros and syntax extensions (and before lowering to HIR), so it can catch erroneous constructions that were generated by them. This pass allows to remove ad hoc semantic checks from the parser, which can be overruled by syntax extensions and occasionally macros.

The checks can be put here if they are simple, local, don't require results of any complex analysis like name resolution or type checking and maybe don't logically fall into other passes. I expect most of errors generated by this pass to be non-fatal and allowing the compilation to proceed.

I intend to move some more checks to this pass later and maybe extend it with new checks, like, for example, identifier validity. Given that syntax extensions are going to be stabilized in the measurable future, it's important that they would not be able to subvert usual language rules.

In this patch I've added two new checks - a check for labels named `'static` and a check for lifetimes and labels named `'_`. The first one gives a hard error, the second one - a future compatibility warning.
Fixes https://github.com/rust-lang/rust/issues/33059 ([breaking-change])
cc https://github.com/rust-lang/rfcs/pull/1177

r? @nrc
2016-06-01 06:21:53 -07:00
Manish Goregaokar
eba82bb569 Rollup merge of #33967 - dsprenkels:enum_pattern_resolve_ice, r=petrochenkov
resolve: record pattern def when `resolve_pattern` returns `Err(true)`

I propose a fix for issue #33293.

In 1a374b8, (pr #33046) fixed the error reporting of a specific case, but the change that was introduced did not make sure that `record_def` was called in all cases, which lead to an ICE in [1].
This change restores the original `else` case, but keeps the changes that were committed in 1a374b8.

[1] `rustc::middle::mem_categorization::MemCategorizationContext::cat_pattern_`
2016-06-01 12:57:42 +05:30
Zack M. Davis
06ebda837e revise explanation for E0429 (focus on error first) 2016-05-30 16:45:41 -07:00
Daan Sprenkels
cde0f94a52 librustc_resolve: make sure pattern def gets recorded if resolve_path returns Err(true)
In 1a374b8, (pr #33046) fixed the error reporting of a specific
case, but the change that was introduced did not make sure that
`record_def` was called in all cases, which lead to an ICE in [1].
This change restores the original `else` case, but keeps the changes
that were committed in 1a374b8.

This commit fixes issue #33293.

[1] `rustc::middle::mem_categorization::MemCategorizationContext::cat_pattern_`
2016-05-30 18:31:01 +02:00