summary refs log tree commit diff
path: root/library/proc_macro/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2022-08-19use <[u8]>::escape_ascii instead of core::ascii::escape_defaultKaDiWa-6/+1
2022-07-24Expose size_hint() for TokenStream's iteratorDavid Tolnay-0/+8
2022-07-20Rollup merge of #99516 - m-ou-se:proc-macro-tracked-tracking-issue, ↵Matthias Krüger-4/+4
r=Mark-Simulacrum Use new tracking issue for proc_macro::tracked_*.
2022-07-20Use new tracking issue for proc_macro::tracked_*.Mara Bos-4/+4
2022-07-18proc_macro: Move subspan to be a method on Span in the bridgeNika Layzell-6/+1
This method is still only used for Literal::subspan, however the implementation only depends on the Span component, so it is simpler and more efficient for now to pass down only the information that is needed. In the future, if more information about the Literal is required in the implementation (e.g. to validate that spans line up as expected with source text), that extra information can be added back with extra arguments.
2022-07-18proc_macro: stop using a remote object handle for LiteralNika Layzell-28/+110
This builds on the symbol infrastructure built for `Ident` to replicate the `LitKind` and `Lit` structures in rustc within the `proc_macro` client, allowing literals to be fully created and interacted with from the client thread. Only parsing and subspan operations still require sync RPC.
2022-07-18proc_macro: stop using a remote object handle for IdentNika Layzell-16/+31
Doing this for all unicode identifiers would require a dependency on `unicode-normalization` and `rustc_lexer`, which is currently not possible for `proc_macro` due to it being built concurrently with `std` and `core`. Instead, ASCII identifiers are validated locally, and an RPC message is used to validate unicode identifiers when needed. String values are interned on the both the server and client when deserializing, to avoid unnecessary copies and keep Ident cheap to copy and move. This appears to be important for performance. The client-side interner is based roughly on the one from rustc_span, and uses an arena inspired by rustc_arena. RPC messages passing symbols always include the full value. This could potentially be optimized in the future if it is revealed to be a performance bottleneck. Despite now having a relevant implementaion of Display for Ident, ToString is still specialized, as it is a hot-path for this object. The symbol infrastructure will also be used for literals in the next part.
2022-07-18proc_macro: Specialize Punct::to_stringNika Layzell-0/+7
This was removed in a previous part, however it should be specialized for to_string performance and consistency.
2022-06-28review changesNika Layzell-2/+6
longer names for RPC generics and reduced dependency on macros in the server.
2022-06-26proc_macro: stop using a remote object handle for GroupNika Layzell-11/+15
This greatly reduces round-trips to fetch relevant extra information about the token in proc macro code, and avoids RPC messages to create Group tokens.
2022-06-26proc_macro: stop using a remote object handle for PunctNika Layzell-19/+17
This greatly reduces round-trips to fetch relevant extra information about the token in proc macro code, and avoids RPC messages to create Punct tokens.
2022-06-25proc_macro: cache static spans in client's thread-local stateNika Layzell-1/+1
This greatly improves the performance of the very frequently called `call_site()` macro when running in a cross-thread configuration.
2022-06-17review fixupsNika Layzell-15/+15
2022-06-17Try to reduce codegen complexity of TokenStream's FromIterator and Extend implsNika Layzell-16/+92
This is an experimental patch to try to reduce the codegen complexity of TokenStream's FromIterator and Extend implementations for downstream crates, by moving the core logic into a helper type. This might help improve build performance of crates which depend on proc_macro as iterators are used less, and the compiler may take less time to do things like attempt specializations or other iterator optimizations. The change intentionally sacrifices some optimization opportunities, such as using the specializations for collecting iterators derived from Vec::into_iter() into Vec. This is one of the simpler potential approaches to reducing the amount of code generated in crates depending on proc_macro, so it seems worth trying before other more-involved changes.
2022-06-17proc_macro: reduce the number of messages required to create, extend, and ↵Nika Layzell-24/+54
iterate TokenStreams This significantly reduces the cost of common interactions with TokenStream when running with the CrossThread execution strategy, by reducing the number of RPC calls required.
2022-06-03Fully stabilize NLLJack Huey-1/+0
2022-06-02Revert #96682.Nicholas Nethercote-3/+2
The change was "Show invisible delimiters (within comments) when pretty printing". It's useful to show these delimiters, but is a breaking change for some proc macros. Fixes #97608.
2022-05-04Show invisible delimeters (within comments) when pretty printing.Nicholas Nethercote-2/+3
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-2/+2
2022-04-09Rollup merge of #95308 - bjorn3:more_stable_proc_macro, r=Mark-SimulacrumDylan DPC-3/+3
Reduce the amount of unstable features used in libproc_macro This makes it easier to adapt the source for stable when copying it into rust-analyzer to load rustc compiled proc macros.
2022-04-05trivial cfg(bootstrap) changesPietro Albini-2/+0
2022-03-25Add note about feature gatesbjorn3-0/+3
2022-03-25Remove usage of extern_types feature gatebjorn3-1/+0
2022-03-25Remove usage of panic_update_hook feature gatebjorn3-1/+0
2022-03-25Remove unused auto_traits feature gatebjorn3-1/+0
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-4/+4
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-07Stabilize const_fn_fn_ptr_basics and const_fn_trait_boundEric Holk-2/+2
2022-01-07Implement panic::update_hookBadel2-0/+1
2021-12-14made compiler happyAnuvrat-1/+0
2021-11-12proc_macro: Add an expand_expr method to TokenStreamNika Layzell-7/+41
This feature is aimed at giving proc macros access to powers similar to those used by builtin macros such as `format_args!` or `concat!`. These macros are able to accept macros in place of string literal parameters, such as the format string, as they perform recursive macro expansion while being expanded. This can be especially useful in many cases thanks to helper macros like `concat!`, `stringify!` and `include_str!` which are often used to construct string literals at compile-time in user code. For now, this method only allows expanding macros which produce literals, although more expresisons will be supported before the method is stabilized.
2021-10-25Append .0 to unsuffixed float if it would otherwise become int tokenDavid Tolnay-2/+10
2021-10-10Stabilize proc_macro::is_availablebjorn3-1/+1
2021-09-10Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnayManish Goregaokar-0/+12
Add proc_macro::Span::{before, after}. This adds `proc_macro::Span::before()` and `proc_macro::Span::after()` to get a zero width span at the start or end of the span. These are equivalent to rustc's `Span::shrink_to_lo()` and `Span::shrink_to_hi()` but with a less cryptic name. They are useful when generating diagnostlics like "missing \<thing\> after \<thing\>". E.g. ```rust syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error() ```
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-08-04Auto merge of #87712 - est31:line-column-1-based, r=petrochenkovbors-4/+10
Proc macro spans: make columns 1 based This makes proc macro spans consistent with the `column!()` macro as well as `std::panic::Location`, as both are 1-based. https://github.com/rust-lang/rust/issues/54725#issuecomment-497246753
2021-08-03Remove space after negative sign in Literal to_stringDavid Tolnay-1/+1
2021-08-03Make the UTF-8 statement more explicit and explicitly test for itest31-2/+2
2021-08-03Make columns 1 basedest31-3/+9
2021-07-29Fix may not to appropriate might not or must notAli Malik-9/+9
2021-07-28Add tracking issue number to proc_macro_span_shrink.Mara Bos-2/+2
2021-07-03Rollup merge of #84029 - drahnr:master, r=petrochenkovYuki Okushi-0/+14
add `track_path::path` fn for usage in `proc_macro`s Adds a way to declare a dependency on external files without including them, to either re-trigger the build of a file as well as covering the use case of including dependencies within the `rustc` invocation, such that tools like `sccache`/`cachepot` are able to handle references to external files which are not included. Ref #73921
2021-07-02add track_path::path fn for proc-macro usageBernhard Schuster-0/+14
Ref #73921
2021-07-01Stabilize `Bound::cloned()`Aris Merchant-1/+0
2021-06-24Use `#[non_exhaustive]` where appropriateJacob Pratt-4/+3
Due to the std/alloc split, it is not possible to make `alloc::collections::TryReserveError::AllocError` non-exhaustive without having an unstable, doc-hidden method to construct (which negates the benefits from `#[non_exhaustive]`.
2021-06-20Improve documentationr00ster91-6/+9
2021-06-19Rollup merge of #86136 - m-ou-se:proc-macro-open-close-span, r=m-ou-seYuki Okushi-2/+2
Stabilize span_open() and span_close(). This proposes to stabilize `Group::span_open()` and `Group::span_close()`. These are part of the `proc_macro_span` feature gate tracked in https://github.com/rust-lang/rust/issues/54725 Most of the features gated behind `proc_macro_span` are about source location information (file path, line and column information), expansion information (parent()), source_text(), etc. Those are not ready for stabilizaiton. However, getting the span of the `(` and `)` separately instead of only of the entire `(...)` can be very useful in proc macros, and doesn't seem blocked on anything that all the other parts of `proc_macro_span` are blocked on. So, this renames the feature gate for those two functions to `proc_macro_group_span` and stabilizes them.
2021-06-09Add proc_macro::Span::{before, after}.Mara Bos-0/+12
2021-06-08Simplify proc_macro code using Bound::cloned().Mara Bos-11/+3
2021-06-08Stabilize span_open() and span_close().Mara Bos-2/+2
2021-06-04rustdoc: link to stable/beta docs consistently in documentationJoshua Nelson-1/+0
## User-facing changes - Intra-doc links to primitives that currently go to rust-lang.org/nightly/std/primitive.x.html will start going to channel that rustdoc was built with. Nightly will continue going to /nightly; Beta will link to /beta; stable compilers will link to /1.52.1 (or whatever version they were built as). - Cross-crate links from std to core currently go to /nightly unconditionally. They will start going to /1.52.0 on stable channels (but remain the same on nightly channels). - Intra-crate links from std to std (or core to core) currently go to the same URL they are hosted at; they will continue to do so. Notably, this is different from everything else because it can preserve the distinction between /stable and /1.52.0 by using relative links. Note that "links" includes both intra-doc links and rustdoc's own automatically generated hyperlinks. ## Implementation changes - Update the testsuite to allow linking to /beta and /1.52.1 in docs - Use an html_root_url for the standard library that's dependent on the channel This avoids linking to nightly docs on stable. - Update rustdoc to use channel-dependent links for primitives from an unknown crate - Set DOC_RUST_LANG_ORG_CHANNEL from bootstrap to ensure it's in sync - Include doc.rust-lang.org in the channel