rust/src/libsyntax
bors e1d7e4ae82 Auto merge of #63248 - petrochenkov:nomarker, r=matthewjasper
Move special treatment of `derive(Copy, PartialEq, Eq)` from expansion infrastructure to elsewhere

As described in https://github.com/rust-lang/rust/pull/62086#issuecomment-515195477.

Reminder:
- `derive(PartialEq, Eq)` makes the type it applied to a "structural match" type, so constants of this type can be used in patterns (and const generics in the future).
- `derive(Copy)` notifies other derives that the type it applied to implements `Copy`, so `derive(Clone)` can generate optimized code and other derives can generate code working with `packed` types and types with `rustc_layout_scalar_valid_range` attributes.

First, the special behavior is now enabled after properly resolving the derives, rather than after textually comparing them with `"Copy"`, `"PartialEq"` and `"Eq"` in `fn add_derived_markers`.

The markers are no longer kept as attributes in AST since derives cannot modify items and previously did it through hacks in the expansion infra.
Instead, the markers are now kept in a "global context" available from all the necessary places, namely - resolver.

For `derive(PartialEq, Eq)` the markers are created by the derive macros themselves and then consumed during HIR lowering to add the `#[structural_match]` attribute in HIR.
This is still a hack, but now it's a hack local to two specific macros rather than affecting the whole expansion infra.
Ideally we should find the way to put `#[structural_match]` on the impls rather than on the original item, and then consume it in `rustc_mir`, then no hacks in expansion and lowering will be required.
(I'll make an issue about this for someone else to solve, after this PR lands.)

The marker for `derive(Copy)` cannot be emitted by the `Copy` macro itself because we need to know it *before* the `Copy` macro is expanded for expanding other macros.
So we have to do it in resolve and block expansion of any derives in a `derive(...)` container until we know for sure whether this container has `Copy` in it or not.
Nasty stuff.

r? @eddyb or @matthewjasper
2019-08-05 04:36:51 +00:00
..
ast libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
attr Replace AstBuilder with inherent methods 2019-07-31 08:55:37 -04:00
diagnostics Replace AstBuilder with inherent methods 2019-07-31 08:55:37 -04:00
ext Auto merge of #63248 - petrochenkov:nomarker, r=matthewjasper 2019-08-05 04:36:51 +00:00
mut_visit libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
parse Auto merge of #63213 - varkor:itemkind-tyalias, r=Centril 2019-08-04 20:03:28 +00:00
print Rename ItemImplKind::Type to ItemImplKind::TyAlias 2019-08-04 20:16:41 +01:00
source_map libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
tokenstream libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
util libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
ast.rs Auto merge of #63213 - varkor:itemkind-tyalias, r=Centril 2019-08-04 20:03:28 +00:00
build.rs Remove licenses 2018-12-25 21:08:33 -07:00
Cargo.toml cleanup: Remove extern crate serialize as rustc_serializes 2019-07-23 19:20:16 +03:00
config.rs Lint on 'cfg_attr(,).' 2019-06-22 12:11:01 +02:00
early_buffered_lints.rs Implement checks for meta-variables in macros 2019-07-19 19:59:12 +02:00
entry.rs Remove the equality operation between Symbol and strings. 2019-05-13 09:31:30 +10:00
error_codes.rs Remove lint annotations in specific crates that are already enforced by rustbuild 2019-07-28 18:46:24 +03:00
feature_gate.rs Auto merge of #63248 - petrochenkov:nomarker, r=matthewjasper 2019-08-05 04:36:51 +00:00
json.rs Remove lint annotations in specific crates that are already enforced by rustbuild 2019-07-28 18:46:24 +03:00
lib.rs libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
mut_visit.rs Auto merge of #63213 - varkor:itemkind-tyalias, r=Centril 2019-08-04 20:03:28 +00:00
ptr.rs cleanup: Remove extern crate serialize as rustc_serializes 2019-07-23 19:20:16 +03:00
README.md rustc-guide has moved 2018-11-26 15:03:13 -06:00
show_span.rs Rename rustc_errors dependency in rust 2018 crates 2019-02-13 00:28:52 +09:00
source_map.rs libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
tests.rs libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
tokenstream.rs libsyntax: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
visit.rs Rename ItemImplKind::Type to ItemImplKind::TyAlias 2019-08-04 20:16:41 +01:00

The syntax crate contains those things concerned purely with syntax that is, the AST ("abstract syntax tree"), parser, pretty-printer, lexer, macro expander, and utilities for traversing ASTs.

For more information about how these things work in rustc, see the rustc guide: