about summary refs log tree commit diff
path: root/library/proc_macro/src
AgeCommit message (Collapse)AuthorLines
2022-06-13proc_macro: bypass RandomState to remove ASLR-like effects.Eduard-Mihai Burtescu-3/+19
2022-06-07Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakisbors-1/+0
Remove migrate borrowck mode Closes #58781 Closes #43234 # Stabilization proposal This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile. Tracking issue: #43234 RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable). ## Motivation Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors. The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition. In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker. In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver. While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff. ## What is stabilized As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise. There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl. As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions. ## What isn't stabilized This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck. ## Tests Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll` ## History * On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234) * On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271) * On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094) * On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825) * On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862) * On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083) * On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681) * On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114) * On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221) * On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
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-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-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-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-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