Commit Graph

796 Commits

Author SHA1 Message Date
Esteban Küber
2cca435717 Mention the syntax for use on mod foo; if foo doesn't exist
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-21 15:56:01 +00:00
Michael Howell
2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af 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-16 15:38:08 -07:00
Nicholas Nethercote
d284c8a2d7 Rename ACTIVE_FEATURES as UNSTABLE_FEATURES.
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-16 08:17:23 +11:00
Nicholas Nethercote
41b6899487 Remove rustc_feature::State.
`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-16 08:15:30 +11:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Nicholas Nethercote
56fd2531ac Add two setter functions to Features. 2023-10-05 18:01:11 +11:00
Nicholas Nethercote
95d1aa075f Record all declared features.
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-05 18:01:11 +11:00
Nicholas Nethercote
4602d9257d Rename Features::active_features.
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-05 18:01:11 +11:00
Nicholas Nethercote
b229be0127 Overhaul config::features.
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-05 18:00:29 +11:00
Nicholas Nethercote
8ba9137840 Merge STABLE_REMOVED_FEATURES list into REMOVED_FEATURES.
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-05 11:42:32 +11:00
Nicholas Nethercote
5d9559e026 Inline and remove feature_removed function.
It has a single call site. This increases consistency because other
errors within `features` are emitted directly.
2023-10-05 11:18:51 +11:00
Nicholas Nethercote
9e2cd038b0 Factor out some repeated feature-getting code. 2023-10-05 11:16:14 +11:00
Nicholas Nethercote
e24f394404 Add comments to config::features.
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-05 11:16:05 +11:00
Nicholas Nethercote
53fe37de2e Remove unused Span from the set function in State::Active. 2023-10-05 10:18:29 +11:00
Camille GILLOT
717dc1ce21 Enable incremental-relative-spans by default. 2023-09-07 20:21:13 +00:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
bors
ee5cb9e3a6 Auto merge of #114915 - nnethercote:Nonterminal-cleanups, r=petrochenkov
`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-18 16:07:40 +00:00
Nicholas Nethercote
9e22351c74 Rename NtOrTt as ParseNtResult.
It's more descriptive, and future-proofs it if/when additional variants
get added.
2023-08-18 16:50:41 +10:00
Caio
6395dc2cde [RFC-3086] Restrict the parsing of count 2023-08-17 08:52:37 -03:00
Nicholas Nethercote
acd3a5e35f Remove unnecessary braces on PatWithOr patterns. 2023-08-17 09:04:54 +10:00
Nicholas Nethercote
9de696b39f Remove some unnecessary (and badly named) local variables. 2023-08-17 08:26:55 +10:00
Vadim Petrochenkov
7353c96be8 rustc: Move features from Session to GlobalCtxt
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
bors
fe896efa97 Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
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-04 18:46:19 +00:00
Nilstrieb
5830ca216d Add internal_features lint
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-03 14:50:50 +02:00
Nicholas Nethercote
d75ee2a6bc Remove MacDelimiter.
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-03 09:03:30 +10:00
bors
d12c6e947c Auto merge of #114273 - nnethercote:move-doc-comment-desugaring, r=petrochenkov
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-08-01 21:27:48 +00:00
Oli Scherer
51c22154f5 Remove a bool for color in favor of the WriteColor trait wrapping colored and uncolored printing 2023-07-31 09:34:36 +00:00
Oli Scherer
0e7ec9683d Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
Nicholas Nethercote
2e6ce68fba Remove desugar_doc_comments arg from Parser::new().
It's only true at one call site; do the desugaring there instead.
2023-07-31 14:47:08 +10:00
Nicholas Nethercote
c70c8b7196 No need to desugar doc comments when parsing decl macro definitions. 2023-07-31 11:21:30 +10:00
Nicholas Nethercote
a8909b059f Reflow an overlong comment. 2023-07-31 11:21:24 +10:00
Nicholas Nethercote
d16b1f4a8c Remove more unnecessary return keywords. 2023-07-31 11:14:39 +10:00
Matthias Krüger
23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
León Orell Valerian Liehr
afd009a8d8
Parse generic const items 2023-07-28 22:21:33 +02:00
bors
0699d99516 Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkov
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-28 01:21:27 +00:00
Nicholas Nethercote
4ebf2be8bb Remove Iterator impl for TokenTreeCursor.
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-27 11:59:03 +10:00
Nicholas Nethercote
d2f7f67921 Avoid some token tree cloning in decl macro parsing.
By changing `into_trees` into `trees`. Some of the subsequent paths
require explicit clones, but not all.
2023-07-27 11:58:42 +10:00
Nicholas Nethercote
a9d8459299 Replace into_trees with trees in a test.
There's no need for token tree cloning here.
2023-07-27 10:40:39 +10:00
Nicholas Nethercote
53379a7b65 Simplify the ttdelim_span test.
The existing code is a very complex and inefficient way to the get the
span of the last token.
2023-07-27 09:41:49 +10:00
Eric Huss
9914ae3292 Squelch a noisy rustc_expand unittest 2023-07-26 08:12:08 -07:00
Oli Scherer
2b444672e1 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
Oli Scherer
d97ec97b94 Don't translate compiler-internal bug messages 2023-07-20 09:51:47 +00:00
bors
a6cdd81eff Auto merge of #108714 - estebank:ice_dump, r=oli-obk
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-20 01:29:17 +00:00
Michael Goulet
846cc63e38 Make it clearer that edition functions are >=, not == 2023-07-19 16:38:35 +00:00
Esteban Küber
8eb5843a59 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.
2023-07-19 14:10:07 +00:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
The 8472
14e57d7c13 perform TokenStream replacement in-place when possible in expand_macro 2023-07-03 13:29:15 +02:00
Dylan DPC
fa56e01b35
Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-se
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`
2023-06-28 18:28:46 +05:30
Matthias Krüger
d505582ce2
Rollup merge of #113084 - WaffleLapkin:less_map_or, r=Nilstrieb
Simplify some conditions

r? `@Nilstrieb`

Some things taken out of my `is_none_or` pr.
2023-06-27 22:10:15 +02:00
Maybe Waffle
ef05533c39 Simplify some conditions 2023-06-27 07:40:47 +00:00