about summary refs log tree commit diff
path: root/library/proc_macro
AgeCommit message (Collapse)AuthorLines
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/+14
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-07Change proc_macro::Diagnostics docsKlim Tsoutsman-5/+4
Add links Fit 100-character limit
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/+2
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-08-02Auto merge of #87535 - lf-:authors, r=Mark-Simulacrumbors-1/+0
rfc3052 followup: Remove authors field from Cargo manifests Since RFC 3052 soft deprecated the authors field, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information for contributors, we may as well remove it from crates in this repo.
2021-07-29rfc3052: Remove authors field from Cargo manifestsJade-1/+0
Since RFC 3052 soft deprecated the authors field anyway, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information, we should remove it from crates in this repo.
2021-07-29Fix may not to appropriate might not or must notAli Malik-10/+10
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/+15
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-02Rollup merge of #86797 - inquisitivecrystal:bound-cloned, r=jyn514Guillaume Gomez-1/+0
Stabilize `Bound::cloned()` This PR stabilizes the function `Bound::cloned()`. Closes #61356.
2021-07-02add track_path::path fn for proc-macro usageBernhard Schuster-0/+15
Ref #73921
2021-07-01Stabilize `Bound::cloned()`Aris Merchant-1/+0
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-26Auto merge of #86637 - ehuss:spellings, r=dtolnaybors-1/+1
Fix a few misspellings.
2021-06-25Fix a few misspellings.Eric Huss-1/+1
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/+14
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
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-24remove cfg(bootstrap)Pietro Albini-2/+1
2021-05-19impl FromStr for proc_macro::LiteralDavid Tolnay-0/+42
2021-05-19Move proc_macro tests to ui testDavid Tolnay-20/+0
2021-05-12Implement span quoting for proc-macrosAaron Hill-5/+24
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`.
2021-04-29don't let const_fn feature flag affect impl-block-level trait boundsRalf Jung-1/+2
2021-02-19`impl PartialEq<Punct> for char`; symmetry for #78636Alexander Ronald Altman-1/+8
Also fixes the "since" version of the original.
2020-12-30Bump bootstrap compiler to 1.50 betaMark Rousskov-2/+1
2020-11-25Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obkbors-1/+2
Rename `optin_builtin_traits` to `auto_traits` They were originally called "opt-in, built-in traits" (OIBITs), but people realized that the name was too confusing and a mouthful, and so they were renamed to just "auto traits". The feature flag's name wasn't updated, though, so that's what this PR does. There are some other spots in the compiler that still refer to OIBITs, but I don't think changing those now is worth it since they are internal and not particularly relevant to this PR. Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>. r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-24Auto merge of #78636 - dtolnay:puncteq, r=petrochenkovbors-1/+16
Add PartialEq<char> for proc_macro::Punct `punct.as_char() == '░'` is pervasive when parsing anything involving punct. I think `punct == '░'` is sufficiently unambiguous that it makes sense to provide the impl. https://github.com/rust-lang/rust/blob/1899c489d4c30b2640d30b77ac04f0a548834d81/library/proc_macro/src/quote.rs#L79 https://github.com/rust-lang/rust/blob/1899c489d4c30b2640d30b77ac04f0a548834d81/library/proc_macro/src/quote.rs#L83 https://github.com/rust-lang/rust/blob/1899c489d4c30b2640d30b77ac04f0a548834d81/src/test/ui/suggestions/auxiliary/issue-61963.rs#L26 https://github.com/rust-lang/rust/blob/1899c489d4c30b2640d30b77ac04f0a548834d81/src/test/ui/proc-macro/auxiliary/three-equals.rs#L23
2020-11-23Rename `optin_builtin_traits` to `auto_traits`Camelid-1/+2
They were originally called "opt-in, built-in traits" (OIBITs), but people realized that the name was too confusing and a mouthful, and so they were renamed to just "auto traits". The feature flag's name wasn't updated, though, so that's what this PR does. There are some other spots in the compiler that still refer to OIBITs, but I don't think changing those now is worth it since they are internal and not particularly relevant to this PR. Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-19Bump bootstrap compiler versionJake Goulding-13/+7
2020-11-05Rollup merge of #78465 - est31:proc_macro_to_string, r=jyn514Mara Bos-1/+1
Change as_str → to_string in proc_macro::Ident::span() docs There is no `as_str` function on Ident any more. Also change it to an intra doc link while we're at it.
2020-11-01Add Punct PartialEq smoke testDavid Tolnay-1/+9
2020-11-01Add PartialEq<char> for proc_macro::PunctDavid Tolnay-0/+7
2020-10-29Change as_str → to_string in proc_macro::Ident::span() docsest31-1/+1
There is no `as_str` function on Ident any more. Also change it to an intra doc link while we're at it.
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-6/+13
2020-10-07Bump to 1.48 bootstrap compilerMark Rousskov-1/+1
2020-09-27Add a feature gate for basic function pointer use in `const fn`Dylan MacKenzie-0/+1
2020-09-22Update library functions with stability attributesDylan MacKenzie-0/+7
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.