about summary refs log tree commit diff
path: root/compiler/rustc_span/src/hygiene.rs
AgeCommit message (Collapse)AuthorLines
2025-09-05Some hygiene doc improvementsCameron Steffen-10/+20
2025-08-02Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=AmanieuSamuel Tardieu-1/+3
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2025-07-25Improve and regularize comment placement in doc codeJosh Triplett-1/+3
Because doc code does not get automatically formatted, some doc code has creative placements of comments that automatic formatting can't handle. Reformat those comments to make the resulting code support standard Rust formatting without breaking; this is generally an improvement to readability as well. Some comments are not indented to the prevailing indent, and are instead aligned under some bit of code. Indent them to the prevailing indent, and put spaces *inside* the comments to align them with code. Some comments span several lines of code (which aren't the line the comment is about) and expect alignment. Reformat them into one comment not broken up by unrelated intervening code. Some comments are placed on the same line as an opening brace, placing them effectively inside the subsequent block, such that formatting would typically format them like a line of that block. Move those comments to attach them to what they apply to. Some comments are placed on the same line as a one-line braced block, effectively attaching them to the closing brace, even though they're about the code inside the block. Reformat to make sure the comment will stay on the same line as the code it's commenting.
2025-07-24Inline some methods in rustc_span hygienexizheyin-0/+16
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-05remove `DesugaringKind::CondTemporary`dianne-7/+0
2025-06-22Implement DesugaringKind::FormatLiteralmejrs-0/+16
2025-06-12Introduce `-Zmacro-stats`.Nicholas Nethercote-1/+1
It collects data about macro expansions and prints them in a table after expansion finishes. It's very useful for detecting macro bloat, especially for proc macros. Details: - It measures code snippets by pretty-printing them and then measuring lines and bytes. This required a bunch of additional pretty-printing plumbing, in `rustc_ast_pretty` and `rustc_expand`. - The measurement is done in `MacroExpander::expand_invoc`. - The measurements are stored in `ExtCtxt::macro_stats`.
2025-04-28Move `in_external_macro` to `SyntaxContext`Jason Newcomb-0/+25
2025-04-26hygiene: Use `IndexVec` for syntax context decode cacheVadim Petrochenkov-9/+4
2025-04-26hygiene: Misc cleanupsVadim Petrochenkov-82/+46
Inline some functions used once. Use `impl Trait` more. Tweak some comments.
2025-04-26hygiene: Remove decode placeholdersVadim Petrochenkov-34/+11
They are no longer necessary after #139281
2025-04-19Rollup merge of #139091 - mejrs:format, r=compiler-errorsChris Denton-0/+19
Rewrite on_unimplemented format string parser. This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately. This PR introduces some minor differences though: - `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future. - for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse. - for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"` - Some error messages now have better spans. Fixes https://github.com/rust-lang/rust/issues/130627
2025-04-17Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwcoMatthias Krüger-24/+23
hygiene: Rename semi-transparent to semi-opaque "Semi-transparent" is just too damn long for a name, especially when used multiple times on a single line, it bothered me when working on #139083. An optimist sees a macro as semi-opaque, a pessimist sees it as semi-transparent. Or is it the other way round?
2025-04-14Documentation and finishing touchesmejrs-0/+19
2025-04-12don't store opaque info during encodingbohan-56/+18
2025-04-03hygiene: Avoid recursion in syntax context decodingVadim Petrochenkov-100/+61
2025-04-01Use `sym::dummy` in one more place.Nicholas Nethercote-1/+2
It makes it clearer that the symbol is unused and doesn't matter.
2025-03-31hygiene: Rename semi-transparent to semi-opaqueVadim Petrochenkov-24/+23
The former is just too long, see the examples in `hygiene.rs`
2025-03-28hygiene: Rewrite `apply_mark_internal` to be more understandableVadim Petrochenkov-60/+61
2025-03-15hygiene: Update `$crate` pretty-printing to account for holes in syntax contextsVadim Petrochenkov-14/+15
2025-03-15hygiene: Ensure uniqueness of `SyntaxContextData`sVadim Petrochenkov-26/+34
2025-03-15hygiene: Asserts, comments, code cleanupVadim Petrochenkov-53/+91
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-0/+5
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-06Remove the `Option` part of range ends in the HIROli Scherer-0/+3
2025-02-24Introduce new-style attribute parsers for several attributesJana Dönszelmann-0/+6
note: compiler compiles but librustdoc and clippy don't
2025-02-16Move hashes from rustc_data_structure to rustc_hashes so they can be shared ↵Ben Kimock-1/+2
with rust-analyzer
2025-02-06Auto merge of #136471 - safinaskar:parallel, r=SparrowLiibors-5/+6
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` This is continuation of https://github.com/rust-lang/rust/pull/132282 . I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement. There are other possibilities, through. We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase. So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge. cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 ) r? SparrowLii `@rustbot` label WG-compiler-parallel
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-0/+3
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-5/+6
2025-01-18Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Rémy Rakic-4/+0
r=davidtwco,RalfJung" This reverts commit b57d93d8b9525fa261404b4cd9c0670eeb1264b8, reversing changes made to 0aeaa5eb22180fdf12a8489e63c4daa18da6f236.
2024-12-13Don't retag the `PtrMetadata(&raw const *_n)` in slice indexingScott McMurray-0/+4
2024-11-27rustc_span: Replace a `HashMap<_, ()>` with `HashSet`Josh Stone-5/+6
Now that `HashSet::entry()` exists, we don't need to fake it with a map.
2024-11-12Delete the `cfg(not(parallel))` serial compilerNoratrieb-13/+1
Since it's inception a long time ago, the parallel compiler and its cfgs have been a maintenance burden. This was a necessary evil the allow iteration while not degrading performance because of synchronization overhead. But this time is over. Thanks to the amazing work by the parallel working group (and the dyn sync crimes), the parallel compiler has now been fast enough to be shipped by default in nightly for quite a while now. Stable and beta have still been on the serial compiler, because they can't use `-Zthreads` anyways. But this is quite suboptimal: - the maintenance burden still sucks - we're not testing the serial compiler in nightly Because of these reasons, it's time to end it. The serial compiler has served us well in the years since it was split from the parallel one, but it's over now. Let the knight slay one head of the two-headed dragon!
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-1/+1
2024-08-21Rollup merge of #127279 - bvanjoi:fix-112680, r=petrochenkovMatthias Krüger-0/+8
use old ctx if has same expand environment during decode span Fixes #112680 The root reason why #112680 failed with incremental compilation on the second attempt is the difference in `opaque` between the span of the field [`ident`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_typeck/src/expr.rs#L2348) and the span in the incremental cache at `tcx.def_ident_span(field.did)`. - Let's call the span of `ident` as `span_a`, which is generated by [`apply_mark_internal`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L553-L554). Its content is similar to: ```rs span_a_ctx -> SyntaxContextData { opaque: span_a_ctx, opaque_and_semitransparent: span_a_ctx, // .... } ``` - And call the span of `tcx.def_ident_span` as `span_b`, which is generated by [`decode_syntax_context`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L1390). Its content is: ```rs span_b_ctx -> SyntaxContextData { opaque: span_b_ctx, // note `span_b_ctx` is not same as `span_a_ctx` opaque_and_semitransparent: span_b_ctx, // .... } ``` Although they have the same `parent` (both refer to the root) and `outer_expn`, I cannot find the specific connection between them. Therefore, I chose a solution that may not be the best: give up the incremental compile cache to ensure we can use `span_a` in this case. r? `@petrochenkov` Do you have any advice on this? Or perhaps this solution is acceptable?
2024-07-29Reformat `use` declarations.Nicholas Nethercote-8/+10
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-05use old ctx if has same expand environment during decode spanbohan-0/+8
2024-06-21Auto merge of #123165 - oli-obk:no_ord_def_id3, r=cjgillotbors-1/+7
Stop sorting `Span`s' `SyntaxContext`, as that is incompatible with incremental work towards https://github.com/rust-lang/rust/issues/90317 Luckily no one actually needed these to be sorted, so it didn't even affect diagnostics. I'm guessing they'd have been sorted by creation time anyway, so it wouldn't really have mattered. r? `@cjgillot`
2024-06-16rustc_span: Minor improvementsVadim Petrochenkov-0/+5
Introduce `{IndexNewtype,SyntaxContext}::from_u16` for convenience because small indices are sometimes encoded as `u16`. Use `SpanData::span` instead of `Span::new` where appropriate. Add a clarifying comment about decoding span parents.
2024-05-22Remove `#[macro_use]` extern crate tracing` from `rustc_span`.Nicholas Nethercote-0/+1
Because explicit macro imports are better than implicit macro imports.
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-1/+1
2024-04-25debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and ↵Vadim Petrochenkov-23/+15
`#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local). `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-24chore: fix some typos in commentswhosehang-1/+1
Signed-off-by: whosehang <whosehang@outlook.com>
2024-04-19Stop sorting `Span`s' `SyntaxContext`, as that is incompatible with incrementalOli Scherer-1/+7
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-2/+2
It is commonly used.
2024-03-22Update (doc) commentsLeón Orell Valerian Liehr-1/+1
Several (doc) comments were super outdated or didn't provide enough context. Some doc comments shoved everything in a single paragraph without respecting the fact that the first paragraph should be a single sentence because rustdoc treats these as item descriptions / synopses on module pages.
2024-01-31Add async bound modifier to enable async Fn boundsMichael Goulet-0/+3
2024-01-19Auto merge of #120112 - matthiaskrgr:rollup-48o3919, r=matthiaskrgrbors-5/+14
Rollup of 9 pull requests Successful merges: - #119582 (bootstrap: handle vendored sources when remapping crate paths) - #119730 (docs: fix typos) - #119828 (Improved collapse_debuginfo attribute, added command-line flag) - #119869 (replace `track_errors` usages with bubbling up `ErrorGuaranteed`) - #120037 (Remove `next_root_ty_var`) - #120094 (tests/ui/asm/inline-syntax: adapt for LLVM 18) - #120096 (Set RUSTC_BOOTSTRAP=1 consistently) - #120101 (change `.unwrap()` to `?` on write where `fmt::Result` is returned) - #120102 (Fix typo in munmap_partial.rs) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-17Use UnhashMap for a few more mapsMark Rousskov-2/+2
This avoids hashing data that's already hashed.