about summary refs log tree commit diff
path: root/library/proc_macro
AgeCommit message (Collapse)AuthorLines
2022-06-04Auto merge of #97604 - nnethercote:inline-bridge-Buffer-methods, r=eddybbors-0/+13
Inline `bridge::Buffer` methods. This fixes a performance regression caused by making `Buffer` non-generic in #97004. r? `@eddyb`
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-06-01Inline `bridge::Buffer` methods.Nicholas Nethercote-0/+13
This fixes a performance regression caused by making `Buffer` non-generic in #97004.
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-90/+163
2022-05-27Cut down `associated_item`.Nicholas Nethercote-20/+18
The part of it dealing with types obfuscates and makes the code less concise. This commit removes that part.
2022-05-27Remove unnecessary blank line.Nicholas Nethercote-1/+0
2022-05-27Rename `b` as `buf` in several places.Nicholas Nethercote-30/+30
Because it's easy to confuse with `bridge`.
2022-05-27Add some comments about `_marker` fields.Nicholas Nethercote-4/+14
There is some non-obvious information required to understand them.
2022-05-27Clarify a comment.Nicholas Nethercote-1/+1
`reverse_encode` isn't necessary to please the borrow checker, it's to match the ordering done by `reverse_decode`.
2022-05-27Make `Buffer<T>` non-generic.Nicholas Nethercote-46/+46
`u8` is the only type that makes sense for `T`, as demonstrated by the fact that several impls and functions are hardwired to `Buffer<u8>`.
2022-05-27Improve formatting in `associated_item!` definition.Nicholas Nethercote-24/+15
2022-05-27Add some comments.Nicholas Nethercote-0/+3
2022-05-27Fix a typo in a comment.Nicholas Nethercote-1/+1
2022-05-13Remove some unnecessary `rustc_allow_const_fn_unstable` attributes.Nicholas Nethercote-6/+0
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-26Rollup merge of #96149 - est31:remove_unused_macro_matchers, r=petrochenkovDylan DPC-1/+0
Remove unused macro rules Removes rules of internal macros that weren't triggered.
2022-04-19proc_macro: Add a workaround for rustdocVadim Petrochenkov-0/+4
2022-04-18Remove unused macro rulesest31-1/+0
2022-04-09Rollup merge of #95308 - bjorn3:more_stable_proc_macro, r=Mark-SimulacrumDylan DPC-32/+54
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-06Use PhantomData directly in Bridgebjorn3-3/+11
2022-04-05trivial cfg(bootstrap) changesPietro Albini-2/+0
2022-03-25Add note about feature gatesbjorn3-0/+3
2022-03-25Avoid negative impls in the bridgebjorn3-20/+32
2022-03-25Remove usage of extern_types feature gatebjorn3-8/+8
2022-03-25Remove usage of panic_update_hook feature gatebjorn3-3/+3
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-16Auto merge of #92598 - Badel2:panic-update-hook, r=yaahcbors-3/+3
Implement `panic::update_hook` Add a new function `panic::update_hook` to allow creating panic hooks that forward the call to the previously set panic hook, without race conditions. It works by taking a closure that transforms the old panic hook into a new one, while ensuring that during the execution of the closure no other thread can modify the panic hook. This is a small function so I hope it can be discussed here without a formal RFC, however if you prefer I can write one. Consider the following example: ```rust let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { println!("panic handler A"); prev(info); })); ``` This is a common pattern in libraries that need to do something in case of panic: log panic to a file, record code coverage, send panic message to a monitoring service, print custom message with link to github to open a new issue, etc. However it is impossible to avoid race conditions with the current API, because two threads can execute in this order: * Thread A calls `panic::take_hook()` * Thread B calls `panic::take_hook()` * Thread A calls `panic::set_hook()` * Thread B calls `panic::set_hook()` And the result is that the original panic hook has been lost, as well as the panic hook set by thread A. The resulting panic hook will be the one set by thread B, which forwards to the default panic hook. This is not considered a big issue because the panic handler setup is usually run during initialization code, probably before spawning any other threads. Using the new `panic::update_hook` function, this race condition is impossible, and the result will be either `A, B, original` or `B, A, original`. ```rust panic::update_hook(|prev| { Box::new(move |info| { println!("panic handler A"); prev(info); }) }); ``` I found one real world use case here: https://github.com/dtolnay/proc-macro2/blob/988cf403e741aadfd5340bbf67e35e1062a526aa/src/detection.rs#L32 the workaround is to detect the race condition and panic in that case. The pattern of `take_hook` + `set_hook` is very common, you can see some examples in this pull request, so I think it's natural to have a function that combines them both. Also using `update_hook` instead of `take_hook` + `set_hook` reduces the number of calls to `HOOK_LOCK.write()` from 2 to 1, but I don't expect this to make any difference in performance. ### Unresolved questions: * `panic::update_hook` takes a closure, if that closure panics the error message is "panicked while processing panic" which is not nice. This is a consequence of holding the `HOOK_LOCK` while executing the closure. Could be avoided using `catch_unwind`? * Reimplement `panic::set_hook` as `panic::update_hook(|_prev| hook)`?
2022-01-08Change panic::update_hook to simplify usageBadel2-10/+8
And to remove possibility of panics while changing the panic handler, because that resulted in a double panic.
2022-01-07Implement panic::update_hookBadel2-10/+12
2021-12-23Switch all libraries to the 2021 editionDeadbeef-1/+1
2021-12-14made compiler happyAnuvrat-11/+10
2021-11-12proc_macro: Add an expand_expr method to TokenStreamNika Layzell-7/+42
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/+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