Commit Graph

446 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 93a8283614 Move builtin attribute logic to new rustc_attr crate.
For now, this is all the crate contains, but more
attribute logic & types will be moved there over time.
2020-02-01 18:54:56 +01:00
Mazdak Farrokhzad 1af8c10bd4 simplify feature_err imports 2020-01-11 03:19:50 +01:00
Mazdak Farrokhzad ebfd8673a7 Remove rustc_hir reexports in rustc::hir. 2020-01-05 12:49:22 +01:00
Mazdak Farrokhzad 7901c7f707 canonicalize FxHash{Map,Set} imports 2020-01-04 18:57:22 +01:00
Mazdak Farrokhzad b1aad76586 Normalize `syntax::edition` imports. 2020-01-02 19:31:38 +01:00
Vadim Petrochenkov 70f1d57048 Rename `syntax_pos` to `rustc_span` in source code 2020-01-01 09:15:18 +03:00
Vadim Petrochenkov 7608f21b27 Rename `rustc_resolve/resolve_imports.rs` -> `rustc_resolve/imports.rs` 2019-12-30 19:18:18 +03:00
Vadim Petrochenkov a2823e3af6 Rename `libsyntax_ext` and `libsyntax_expand` in code 2019-12-30 19:18:17 +03:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad 79077f13ff move GateIssue to rustc_feature & simplify emit_feature_err 2019-11-30 07:40:28 +01:00
Mazdak Farrokhzad 70234f16df builtin_attrs.rs -> rustc_feature 2019-11-30 02:34:18 +01:00
Vadim Petrochenkov f89e6c8811 rustc_plugin: Remove support for syntactic plugins 2019-11-24 12:05:10 +03:00
Vadim Petrochenkov f74fe812fe resolve: Give derive helpers highest priority during resolution 2019-11-19 00:50:53 +03:00
Yuki Okushi 54998d1b3f
Rollup merge of #66344 - petrochenkov:noregattr, r=matthewjasper
rustc_plugin: Remove `Registry::register_attribute`

Legacy plugins cannot register inert attributes anymore.

The preferred replacement is to use `register_tool` ([tracking issue](https://github.com/rust-lang/rust/issues/66079)).
```rust
#![register_tool(servo)]

#[servo::must_root]
struct S;
```

The more direct replacement is `register_attribute` ([tracking issue](https://github.com/rust-lang/rust/issues/66080))
```rust
#![register_attr(must_root)]

#[must_root]
struct S;
```
, but it requires registering each attribute individually rather than registering the tool once, and is more likely to be removed rather than stabilized.
2019-11-17 13:36:13 +09:00
Vadim Petrochenkov 8575743793 rustc_plugin: Remove `Registry::register_attribute` 2019-11-16 18:50:23 +03:00
Vadim Petrochenkov 808522894b expand: Stop marking derive helper attributes as known
Pass them through name resolution instead
2019-11-16 18:31:47 +03:00
Vadim Petrochenkov a3126a5013 resolve: Introduce a new scope for derive helpers 2019-11-16 18:20:57 +03:00
Vadim Petrochenkov c064630e77 resolve: `Scope::DeriveHelpers` -> `Scope::DeriveHelpersCompat`
These helpers are resolved before their respective derives through a kind of look ahead into future expansions.
Some of these will migrate to proper resolution, others will be deprecated.

```
#[trait_helper] // Deprecate
#[derive(Trait)]
#[trait_helper] // Migrate to proper resolution
```
2019-11-16 18:20:39 +03:00
bors 3fc30d884a Auto merge of #66070 - petrochenkov:regattr, r=matthewjasper
Support registering inert attributes and attribute tools using crate-level attributes

And remove `#[feature(custom_attribute)]`.
(`rustc_plugin::Registry::register_attribute` is not removed yet, I'll do it in a follow up PR.)

```rust
#![register_attr(my_attr)]
#![register_tool(my_tool)]

#[my_attr] // OK
#[my_tool::anything] // OK
fn main() {}
```

---
Some tools (`rustfmt` and `clippy`) used in tool attributes are hardcoded in the compiler.
We need some way to introduce them without hardcoding as well.

This PR introduces a way to do it with a crate level attribute.
The previous attempt to introduce them through command line (https://github.com/rust-lang/rust/pull/57921) met some resistance.

This probably needs to go through an RFC before stabilization.
However, I'd prefer to land *this* PR without an RFC to able to remove `#[feature(custom_attribute)]` and `Registry::register_attribute` while also providing a replacement.

---
`register_attr` is a direct replacement for `#![feature(custom_attribute)]` (https://github.com/rust-lang/rust/issues/29642), except it doesn't rely on implicit fallback from unresolved attributes to custom attributes (which was always hacky and is the primary reason for the removal of `custom_attribute`) and requires registering the attribute explicitly.
It's not clear whether it should go through stabilization or not.
It's quite possible that all the uses should migrate to `#![register_tool]` (https://github.com/rust-lang/rust/issues/66079) instead.

---

Details:
- The naming is `register_attr`/`register_tool` rather than some `register_attributes` (plural, no abbreviation) for consistency with already existing attributes like `cfg_attr`, or `feature`, etc.
---
Previous attempt: https://github.com/rust-lang/rust/pull/57921
cc https://github.com/rust-lang/rust/issues/44690
Tracking issues: #66079 (`register_tool`), #66080 (`register_attr`)
Closes https://github.com/rust-lang/rust/issues/29642
2019-11-10 15:53:35 +00:00
Mark Rousskov 516a817dbd Move next_node_id to Resolver
This doesn't migrate the pretty-printing everybody loops, which will be
done in the next few commits.
2019-11-09 11:10:13 -05:00
Vadim Petrochenkov 83f553c95c Address review comments 2019-11-09 18:19:34 +03:00
Vadim Petrochenkov 09fff50637 resolve: Factor out some common binding creation functionality 2019-11-09 17:50:51 +03:00
Vadim Petrochenkov 41a7c8be8b resolve: Remove some bits relevant only to legacy plugins
They are unstable and going to be removed anyway and the removed code would complicate the next commit
2019-11-09 17:50:51 +03:00
Vadim Petrochenkov 441e5aed25 Remove `#[feature(custom_attribute)]` 2019-11-09 17:50:51 +03:00
Vadim Petrochenkov 3a223a9173 Support registering attributes and attribute tools using crate-level attributes 2019-11-09 17:50:51 +03:00
Nicholas Nethercote eea6f23a0e Make doc comments cheaper with `AttrKind`.
`AttrKind` is a new type with two variants, `Normal` and `DocComment`. It's a
big performance win (over 10% in some cases) because `DocComment` lets doc
comments (which are common) be represented very cheaply.

`Attribute` gets some new helper methods to ease the transition:
- `has_name()`: check if the attribute name matches a single `Symbol`; for
  `DocComment` variants it succeeds if the symbol is `sym::doc`.
- `is_doc_comment()`: check if it has a `DocComment` kind.
- `{get,unwrap}_normal_item()`: extract the item from a `Normal` variant;
  panic otherwise.

Fixes #60935.
2019-11-06 23:05:07 +11:00
Nicholas Nethercote 69bc4aba78 Remove unnecessary `Deref` impl for `Attribute`.
This kind of thing just makes the code harder to read.
2019-11-06 23:01:02 +11:00
Felix S. Klock II 99243616cc Review feedback: alpha-rename field from `copy_derives` to `containers_derving_copy`. 2019-11-05 14:59:29 +01:00
Felix S. Klock II 0dfe0ed8e1 Review feedback: Remove more stuff! Simplify simplify simplify! 2019-11-05 14:59:29 +01:00
Mark Rousskov bb0c930f82 Migrate resolver over to internal lint buffer 2019-11-03 21:52:42 -05:00
Mazdak Farrokhzad fb12c70852 rustc, rustc_passes: don't depend on syntax_expand.
This is done by moving some data definitions to syntax::expand.
2019-10-27 17:05:57 +01:00
Vadim Petrochenkov 7ce85f2dca expand: Simplify expansion of derives
And make it more uniform with other macros.
By merging placeholders for future derives' outputs into the derive container's output fragment early.
2019-10-19 00:23:57 +03:00
Mazdak Farrokhzad d420d719c4 move syntax::ext to new crate syntax_expand 2019-10-16 10:59:53 +02:00
Mazdak Farrokhzad 742ec4b9bf ast: remove implicit pprust dependency via Display.
Instead just use `pprust::path_to_string(..)` where needed.

This has two benefits:

a) The AST definition is now independent of printing it.
   (Therefore we get closer to extracting a data-crate.)

b) Debugging should be easier as program flow is clearer.
2019-10-13 06:58:51 +02:00
Vadim Petrochenkov ceb4c3fa30 stability: Do not use `buffer_lint` after lowering to HIR 2019-10-10 23:38:35 +03:00
Vadim Petrochenkov fcd98cf5dc resolve: Remove an incorrect assert 2019-10-05 23:46:29 +03:00
Aleksey Kladov 645cdca9ba reduce visibility of a bunch of stuff in ext::tt 2019-09-22 20:29:31 +03:00
Vadim Petrochenkov f7f8d6584b resolve: Remove `!` from "cannot find" diagnostics for macros 2019-09-15 13:22:07 +03:00
Vadim Petrochenkov 42a19dde82 resolve: Tweak "cannot find" wording for attributes 2019-09-15 13:10:12 +03:00
Vadim Petrochenkov f6a5b29d19 resolve: Tweak some expected/found wording 2019-09-14 22:36:58 +03:00
Caio 63a5f399ae Resolve attributes in several places
Arm, Field, FieldPat, GenericParam, Param, StructField and Variant
2019-09-09 09:27:15 -03:00
Vadim Petrochenkov f7434aef26 Support "soft" feature-gating using a lint
Use it for feature-gating `#[bench]`
2019-09-07 21:37:51 +03:00
Mazdak Farrokhzad db493ef613
Rollup merge of #63919 - matthewjasper:remove-gensymmed, r=petrochenkov
Use hygiene for AST passes

AST passes are now able to have resolve consider their expansions as if they were opaque macros defined either in some module in the current crate, or a fake empty module with `#[no_implicit_prelude]`.

* Add an ExpnKind for AST passes.
* Remove gensyms in AST passes.
* Remove gensyms in`#[test]`, `#[bench]` and `#[test_case]`.
* Allow opaque macros to define tests.
* Move tests for unit tests to their own directory.
* Remove `Ident::{gensym, is_gensymed}` - `Ident::gensym_if_underscore` still exists.

cc #60869, #61019

r? @petrochenkov
2019-09-07 08:06:04 +02:00
Matthew Jasper 3f3fc52bfa Simplify std lib injection 2019-09-05 22:48:03 +01:00
Vadim Petrochenkov c8cf9f5a02 Add `with_{def_site,call_site,legacy}_ctxt,` methods to `Span`
Use these to create call-site spans for AST passes when needed.
2019-09-05 15:07:17 +01:00
Matthew Jasper 6fcdb36ccb Make use of hygiene in AST passes 2019-09-05 15:07:16 +01:00
Matthew Jasper 4082cd95a8 Allow ast passes to create hygienic spans 2019-09-05 15:07:16 +01:00
Mazdak Farrokhzad e4e6b01ca1
Rollup merge of #63867 - petrochenkov:dhelpers, r=matthewjasper
resolve: Block expansion of a derive container until all its derives are resolved

So, it turns out there's one more reason to block expansion of a `#[derive]` container until all the derives inside it are resolved, beside `Copy` (https://github.com/rust-lang/rust/pull/63248).

The set of derive helper attributes registered by derives in the container also has to be known before the derives themselves are expanded, otherwise it may be too late (see https://github.com/rust-lang/rust/pull/63468#issuecomment-524550872 and the `#[stable_hasher]`-related test failures in https://github.com/rust-lang/rust/pull/63468).

So, we stop our attempts to unblock the container earlier, as soon as the `Copy` status is known, and just block until all its derives are resolved.
After all the derives are resolved we immediately go and process their helper attributes in the item, without delaying it until expansion of the individual derives.

Unblocks https://github.com/rust-lang/rust/pull/63468
r? @matthewjasper (as a reviewer of https://github.com/rust-lang/rust/pull/63248)
cc @c410-f3r
2019-08-29 13:17:52 +02:00
Vadim Petrochenkov 2065ee9acc metadata: Eliminate `FullProcMacro`
Fix caching of loaded proc macros
2019-08-27 01:34:07 +03:00
Vadim Petrochenkov ec45b87957 resolve: Block expansion of a derive container until all its derives are resolved
Also mark derive helpers as known as a part of the derive container's expansion instead of expansion of the derives themselves which may happen too late.
2019-08-27 00:31:55 +03:00