about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2023-10-26Auto merge of #116818 - Nilstrieb:stop-submitting-bug-reports, r=wesleywiserbors-1/+10
Stop telling people to submit bugs for internal feature ICEs This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported. I thought about several ways to do this but now used the explicit threading of an `Arc<AtomicBool>` through `Session`. This is not exactly incremental-safe, but this is fine, as this is set during macro expansion, which is pre-incremental, and also only affects the output of ICEs, at which point incremental correctness doesn't matter much anyways. See [MCP 620.](https://github.com/rust-lang/compiler-team/issues/596) ![image](https://github.com/rust-lang/rust/assets/48135649/be661f05-b78a-40a9-b01d-81ad2dbdb690)
2023-10-25Stop telling people to submit bugs for internal feature ICEsNilstrieb-1/+10
This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported. See MCP 620.
2023-10-21Mention the syntax for `use` on `mod foo;` if `foo` doesn't existEsteban Küber-0/+1
Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`. Fix #69492.
2023-10-16docs: add Rust logo to more compiler cratesMichael Howell-0/+2
c6e6ecb1afea9695a42d0f148ce153536b279eb5 added it to some of the compiler's crates, but avoided adding it to all of them to reduce bit-rot. This commit adds to more.
2023-10-16Rename `ACTIVE_FEATURES` as `UNSTABLE_FEATURES`.Nicholas Nethercote-3/+3
It's a better name, and lets "active features" refer to the features that are active in a particular program, due to being declared or enabled by the edition. The commit also renames `Features::enabled` as `Features::active` to match this; I changed my mind and have decided that "active" is a little better thatn "enabled" for this, particularly because a number of pre-existing comments use "active" in this way. Finally, the commit renames `Status::Stable` as `Status::Accepted`, to match `ACCEPTED_FEATURES`.
2023-10-16Remove `rustc_feature::State`.Nicholas Nethercote-29/+19
`State` is used to distinguish active vs accepted vs removed features. However, these can also be distinguished by their location, in `ACTIVE_FEATURES`, `ACCEPTED_FEATURES`, and `REMOVED_FEATURES`. So this commit removes `State` and moves the internals of its variants next to the `Feature` in each element of `*_FEATURES`, introducing new types `ActiveFeature` and `RemovedFeature`. (There is no need for `AcceptedFeature` because `State::Accepted` had no fields.) This is a tighter type representation, avoids the need for some runtime checks, and makes the code a bit shorter.
2023-10-13Format all the let chains in compilerMichael Goulet-33/+38
2023-10-05Add two setter functions to `Features`.Nicholas Nethercote-11/+6
2023-10-05Record all declared features.Nicholas Nethercote-0/+4
Currently `rust_20XX_preview` features aren't recorded as declared even when they are explicit declared. Similarly, redundant edition-dependent features (e.g. `test_2018_feature`) aren't recorded as declared. This commit marks them as recorded. There is no detectable functional change, but it makes things more consistent.
2023-10-05Rename `Features::active_features`.Nicholas Nethercote-3/+3
The word "active" is currently used in two different and confusing ways: - `ACTIVE_FEATURES` actually means "available unstable features" - `Features::active_features` actually means "features declared in the crate's code", which can include feature within `ACTIVE_FEATURES` but also others. (This is also distinct from "enabled" features which includes declared features but also some edition-specific features automatically enabled depending on the edition in use.) This commit changes the `Features::active_features` to `Features::declared_features` which actually matches its meaning. Likewise, `Features::active` becomes `Features::declared`.
2023-10-05Overhaul `config::features`.Nicholas Nethercote-57/+46
The new way of doing things: - Avoids some code duplication. - Distinguishes the `crate_edition` (which comes from `--edition`) and the `features_edition` (which combines `--edition` along with any `rustc_20XX_preview` features), which is useful. - Has a simpler initial loop, one that just looks for `rustc_20XX_preview` features in order to compute `features_edition`. - Creates a fallible alternative to `Features::enabled`, which is useful. It's not easy to see how exactly the old and new code are equivalent, but it's reassuring to know that the test coverage is quite good for this stuff.
2023-10-05Merge `STABLE_REMOVED_FEATURES` list into `REMOVED_FEATURES`.Nicholas Nethercote-9/+3
There is a single features (`no_stack_check`) in `STABLE_REMOVED_FEATURES`. But the treatment of `STABLE_REMOVED_FEATURES` and `REMOVED_FEATURES` is actually identical. So this commit just merges them, and uses a comment to record `no_stack_check`'s unique "stable removed" status. This also lets `State::Stabilized` (which was a terrible name) be removed.
2023-10-05Inline and remove `feature_removed` function.Nicholas Nethercote-8/+4
It has a single call site. This increases consistency because other errors within `features` are emitted directly.
2023-10-05Factor out some repeated feature-getting code.Nicholas Nethercote-18/+11
2023-10-05Add comments to `config::features`.Nicholas Nethercote-5/+30
I found this function very confusing, and it took me quite some time to work out what it was doing. These comments capture that hard-earned knowledge.
2023-10-05Remove unused `Span` from the `set` function in `State::Active`.Nicholas Nethercote-4/+4
2023-09-07Enable incremental-relative-spans by default.Camille GILLOT-1/+1
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-18Auto merge of #114915 - nnethercote:Nonterminal-cleanups, r=petrochenkovbors-8/+7
`Nonterminal`-related cleanups In #114647 I am trying to remove `Nonterminal`. It has a number of preliminary cleanups that are worth merging even if #114647 doesn't merge, so let's do them in this PR. r? `@petrochenkov`
2023-08-18Rename `NtOrTt` as `ParseNtResult`.Nicholas Nethercote-3/+3
It's more descriptive, and future-proofs it if/when additional variants get added.
2023-08-17[RFC-3086] Restrict the parsing of `count`Caio-1/+11
2023-08-17Remove unnecessary braces on `PatWithOr` patterns.Nicholas Nethercote-1/+1
2023-08-17Remove some unnecessary (and badly named) local variables.Nicholas Nethercote-4/+3
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-15/+18
Removes two pieces of mutable state. Follow up to #114622.
2023-08-04Auto merge of #114104 - oli-obk:syn2, r=compiler-errorsbors-14/+19
Lots of tiny incremental simplifications of `EmitterWriter` internals ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version. Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them. After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Remove `MacDelimiter`.Nicholas Nethercote-1/+2
It's the same as `Delimiter`, minus the `Invisible` variant. I'm generally in favour of using types to make impossible states unrepresentable, but this one feels very low-value, and the conversions between the two types are annoying and confusing. Look at the change in `src/tools/rustfmt/src/expr.rs` for an example: the old code converted from `MacDelimiter` to `Delimiter` and back again, for no good reason. This suggests the author was confused about the types.
2023-08-01Auto merge of #114273 - nnethercote:move-doc-comment-desugaring, r=petrochenkovbors-12/+16
Move doc comment desugaring out of `TokenCursor`. It's awkward that `TokenCursor` sometimes desugars doc comments on the fly, but usually doesn't. r? `@petrochenkov`
2023-07-31Remove a `bool` for color in favor of the `WriteColor` trait wrapping ↵Oli Scherer-4/+18
colored and uncolored printing
2023-07-31Use builder pattern instead of lots of arguments for `EmitterWriter::new`Oli Scherer-14/+5
2023-07-31Remove `desugar_doc_comments` arg from `Parser::new()`.Nicholas Nethercote-4/+9
It's only true at one call site; do the desugaring there instead.
2023-07-31No need to desugar doc comments when parsing decl macro definitions.Nicholas Nethercote-1/+1
2023-07-31Reflow an overlong comment.Nicholas Nethercote-2/+2
2023-07-31Remove more unnecessary `return` keywords.Nicholas Nethercote-6/+5
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-24/+23
2023-07-28Parse generic const itemsLeón Orell Valerian Liehr-1/+10
2023-07-28Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkovbors-34/+31
Less `TokenTree` cloning `TokenTreeCursor` has this comment on it: ``` // FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones. ``` This PR completes that FIXME. It doesn't have much perf effect, but at least we now know that. r? `@petrochenkov`
2023-07-27Remove `Iterator` impl for `TokenTreeCursor`.Nicholas Nethercote-5/+5
This is surprising, but the new comment explains why. It's a logical conclusion in the drive to avoid `TokenTree` clones. `TokenTreeCursor` is now only used within `Parser`. It's still needed due to `replace_prev_and_rewind`.
2023-07-27Avoid some token tree cloning in decl macro parsing.Nicholas Nethercote-23/+23
By changing `into_trees` into `trees`. Some of the subsequent paths require explicit clones, but not all.
2023-07-27Replace `into_trees` with `trees` in a test.Nicholas Nethercote-3/+2
There's no need for token tree cloning here.
2023-07-27Simplify the `ttdelim_span` test.Nicholas Nethercote-3/+1
The existing code is a very complex and inefficient way to the get the span of the last token.
2023-07-26Squelch a noisy rustc_expand unittestEric Huss-24/+57
2023-07-25Use a builder instead of boolean/option argumentsOli Scherer-1/+1
2023-07-20Don't translate compiler-internal bug messagesOli Scherer-1/+1
2023-07-20Auto merge of #108714 - estebank:ice_dump, r=oli-obkbors-1/+1
On nightly, dump ICE backtraces to disk Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected. <img width="1032" alt="Screenshot 2023-03-03 at 2 13 25 PM" src="https://user-images.githubusercontent.com/1606434/222842420-8e039740-4042-4563-b31d-599677171acf.png"> The current behavior will *always* write to disk on nightly builds, regardless of whether the backtrace is printed to the terminal, unless the environment variable `RUSTC_ICE_DISK_DUMP` is set to `0`. This is a compromise and can be changed.
2023-07-19Make it clearer that edition functions are >=, not ==Michael Goulet-1/+1
2023-07-19On nightly, dump ICE backtraces to diskEsteban Küber-1/+1
Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected.
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-23/+26
2023-07-03perform TokenStream replacement in-place when possible in expand_macroThe 8472-2/+1
2023-06-28Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-seDylan DPC-12/+11
Implement proposed API for `proc_macro_span` As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range). `@rustbot` label +A-proc-macros r? `@m-ou-se`