about summary refs log tree commit diff
path: root/library/proc_macro/src/bridge
AgeCommit message (Collapse)AuthorLines
2021-09-10Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnayManish Goregaokar-0/+2
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-03Remove space after negative sign in Literal to_stringDavid Tolnay-0/+1
2021-07-29Fix may not to appropriate might not or must notAli Malik-1/+1
2021-07-03Rollup merge of #84029 - drahnr:master, r=petrochenkovYuki Okushi-0/+1
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/+1
Ref #73921
2021-07-01proc_macro/bridge: Remove dead code Slice typeJade-29/+0
See https://github.com/rust-lang/rust/pull/85390#discussion_r662464868
2021-06-25Fix a few misspellings.Eric Huss-1/+1
2021-06-09Add proc_macro::Span::{before, after}.Mara Bos-0/+2
2021-05-29Write primitive types via array buffersMark Rousskov-2/+17
This allows a more efficient implementation (avoiding a fallback to memmove, which is not optimal for short writes). This saves 0.29% on diesel.
2021-05-29Switch to reserve over extend_from_sliceMark Rousskov-25/+21
This is a 0.15% win on diesel.
2021-05-29Specialize single-element writes to bufferMark Rousskov-1/+16
copy_from_slice generally falls back to memcpy/memmove, which is much more expensive than we need to write a single element in. This saves 0.26% instructions on the diesel benchmark.
2021-05-19impl FromStr for proc_macro::LiteralDavid Tolnay-0/+14
2021-05-12Implement span quoting for proc-macrosAaron Hill-0/+3
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2020-11-19Bump bootstrap compiler versionJake Goulding-12/+6
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-6/+12
2020-09-22Update library functions with stability attributesDylan MacKenzie-0/+6
This may not be strictly minimal, but all unstable functions also need a `rustc_const_unstable` attribute.
2020-09-03Respect `-Z proc-macro-backtrace` flag for panics inside libproc_macroAaron Hill-3/+2
Fixes #76270 Previously, any panic occuring during a call to a libproc_macro method (e.g. calling `Ident::new` with an invalid identifier) would always cause an ICE message to be printed.
2020-08-30Add `-Z proc-macro-backtrace` to allow showing proc-macro panicsAaron Hill-8/+39
Fixes #75050 Previously, we would unconditionally suppress the panic hook during proc-macro execution. This commit adds a new flag -Z proc-macro-backtrace, which allows running the panic hook for easier debugging.
2020-07-27mv std libs to library/mark-0/+1840