rust/src
Alex Crichton 553c04d9eb proc_macro: Reorganize public API
This commit is a reorganization of the `proc_macro` crate's public user-facing
API. This is the result of a number of discussions at the recent Rust All-Hands
where we're hoping to get the `proc_macro` crate into ship shape for
stabilization of a subset of its functionality in the Rust 2018 release.

The reorganization here is motivated by experiences from the `proc-macro2`,
`quote`, and `syn` crates on crates.io (and other crates which depend on them).
The main focus is future flexibility along with making a few more operations
consistent and/or fixing bugs. A summary of the changes made from today's
`proc_macro` API is:

* The `TokenNode` enum has been removed and the public fields of `TokenTree`
  have also been removed. Instead the `TokenTree` type is now a public enum
  (what `TokenNode` was) and each variant is an opaque struct which internally
  contains `Span` information. This makes the various tokens a bit more
  consistent, require fewer wrappers, and otherwise provides good
  future-compatibility as opaque structs are easy to modify later on.

* `Literal` integer constructors have been expanded to be unambiguous as to what
  they're doing and also allow for more future flexibility. Previously
  constructors like `Literal::float` and `Literal::integer` were used to create
  unsuffixed literals and the concrete methods like `Literal::i32` would create
  a suffixed token. This wasn't immediately clear to all users (the
  suffixed/unsuffixed aspect) and having *one* constructor for unsuffixed
  literals required us to pick a largest type which may not always be true. To
  fix these issues all constructors are now of the form
  `Literal::i32_unsuffixed` or `Literal::i32_suffixed` (for all integral types).
  This should allow future compatibility as well as being immediately clear
  what's suffixed and what isn't.

* Each variant of `TokenTree` internally contains a `Span` which can also be
  configured via `set_span`. For example `Literal` and `Term` now both
  internally contain a `Span` rather than having it stored in an auxiliary
  location.

* Constructors of all tokens are called `new` now (aka `Term::intern` is gone)
  and most do not take spans. Manufactured tokens typically don't have a fresh
  span to go with them and the span is purely used for error-reporting
  **except** the span for `Term`, which currently affects hygiene. The default
  spans for all these constructed tokens is `Span::call_site()` for now.

  The `Term` type's constructor explicitly requires passing in a `Span` to
  provide future-proofing against possible hygiene changes. It's intended that a
  first pass of stabilization will likely only stabilize `Span::call_site()`
  which is an explicit opt-in for "I would like no hygiene here please". The
  intention here is to make this explicit in procedural macros to be
  forwards-compatible with a hygiene-specifying solution.

* Some of the conversions for `TokenStream` have been simplified a little.

* The `TokenTreeIter` iterator was renamed to `token_stream::IntoIter`.

Overall the hope is that this is the "final pass" at the API of `TokenStream`
and most of `TokenTree` before stabilization. Explicitly left out here is any
changes to `Span`'s API which will likely need to be re-evaluated before
stabilization.

All changes in this PR have already been reflected to the [`proc-macro2`],
`quote`, and `syn` crates. New versions of all these crates have also been
published to crates.io.

Once this lands in nightly I plan on making an internals post again summarizing
the changes made here and also calling on all macro authors to give the APIs a
spin and see how they work. Hopefully pending no major issues we can then have
an FCP to stabilize later this cycle!

[`proc-macro2`]: https://docs.rs/proc-macro2/0.3.1/proc_macro2/
2018-04-02 13:48:34 -07:00
..
bootstrap Rollup merge of #49549 - Mark-Simulacrum:bootstrap-cleanup, r=alexcrichton 2018-04-01 18:04:57 +02:00
build_helper Remove filetime dep from build_helper 2018-04-01 04:49:21 -06:00
ci
dlmalloc@9b2dcac06c
doc Rollup merge of #49451 - QuietMisdreavus:epoch-doctests, r=GuillaumeGomez 2018-04-01 18:04:54 +02:00
etc
grammar
jemalloc@1f5a28755e
liballoc Use Alloc and Layout from core::heap. 2018-04-02 16:06:19 +09:00
liballoc_jemalloc Use Alloc and Layout from core::heap. 2018-04-02 16:06:19 +09:00
liballoc_system Use Alloc and Layout from core::heap. 2018-04-02 16:06:19 +09:00
libarena
libbacktrace
libcompiler_builtins@2a2f6d96c8
libcore Update drop.rs 2018-04-01 16:19:42 -07:00
libfmt_macros
libgraphviz
liblibc@ed04152aac
libpanic_abort
libpanic_unwind
libproc_macro proc_macro: Reorganize public API 2018-04-02 13:48:34 -07:00
libprofiler_builtins
librustc Auto merge of #49522 - mbrubeck:fs_read, r=SimonSapin 2018-04-01 02:44:45 +00:00
librustc_allocator
librustc_apfloat
librustc_asan
librustc_back
librustc_borrowck
librustc_const_math
librustc_cratesio_shim
librustc_data_structures Auto merge of #49201 - Phlosioneer:add-trivial-size-hints, r=SimonSapin 2018-03-31 06:40:56 +00:00
librustc_driver Auto merge of #49201 - Phlosioneer:add-trivial-size-hints, r=SimonSapin 2018-03-31 06:40:56 +00:00
librustc_errors
librustc_incremental
librustc_lint
librustc_llvm
librustc_lsan
librustc_metadata
librustc_mir Auto merge of #49500 - oli-obk:mir_dep_graph, r=michaelwoerister 2018-03-31 12:50:13 +00:00
librustc_msan
librustc_passes
librustc_platform_intrinsics
librustc_plugin
librustc_privacy
librustc_resolve
librustc_save_analysis
librustc_traits
librustc_trans rustc: Group linked libraries where needed 2018-03-29 15:07:51 -07:00
librustc_trans_utils
librustc_tsan
librustc_typeck Auto merge of #49201 - Phlosioneer:add-trivial-size-hints, r=SimonSapin 2018-03-31 06:40:56 +00:00
librustdoc Rollup merge of #49451 - QuietMisdreavus:epoch-doctests, r=GuillaumeGomez 2018-04-01 18:04:54 +02:00
libserialize
libstd Auto merge of #49580 - glandium:core-heap, r=SimonSapin 2018-04-02 08:07:10 +00:00
libstd_unicode
libsyntax Auto merge of #49124 - abonander:attr-macro-stmt-expr, r=abonander 2018-04-02 10:38:28 +00:00
libsyntax_ext Expand attribute macros on statements and expressions. 2018-04-02 01:56:12 -07:00
libsyntax_pos
libterm
libtest
libunwind
llvm@6ceaaa4b01
llvm-emscripten@2717444753
rtstartup
rustc
rustllvm
stdsimd@bcb720e558
test proc_macro: Reorganize public API 2018-04-02 13:48:34 -07:00
tools Update clippy 2018-03-30 11:08:06 +02:00
Cargo.lock Rollup merge of #49549 - Mark-Simulacrum:bootstrap-cleanup, r=alexcrichton 2018-04-01 18:04:57 +02:00
Cargo.toml
README.md
stage0.txt

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc guide.

Their is also useful content in the following READMEs, which are gradually being moved over to the guide: