about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-20/+26
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2023-02-21Use `ThinVec` in `ast::Generics` and related types.Nicholas Nethercote-1/+1
2023-02-20Remove a redundant function argumentOli Scherer-4/+2
2023-02-20create dummy placeholder crate to prevent compilerPatrik Kårlin-0/+5
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-6/+4
2023-02-13Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisaMatthias Krüger-1/+2
Introduce `-Zterminal-urls` to use OSC8 for error codes Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `<a href="URL">` does in HTML. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-02-09Introduce `-Zterminal-urls` to use OSC8 for error codesEsteban Küber-1/+2
Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `<a href="URL">` does in HTML. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-02-07Add ~const bounds trait bounds when using derive_constMichael Goulet-2/+6
2023-02-05rustc_expand: remove huge error importsest31-23/+25
2023-02-03Rename `Cursor`/`CursorRef` as `TokenTreeCursor`/`RefTokenTreeCursor`.Nicholas Nethercote-6/+6
This makes it clear they return token trees, and makes for a nice comparison against `TokenCursor` which returns tokens.
2023-02-02Rollup merge of #107488 - nnethercote:fix-PartialEq-syntax, r=RalfJungMatthias Krüger-0/+4
Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`. If you do `derive(PartialEq)` on a packed struct, the output shown by `-Zunpretty=expanded` includes expressions like this: ``` { self.x } == { other.x } ``` This is invalid syntax. This doesn't break compilation, because the AST nodes are constructed within the compiler. But it does mean anyone using `-Zunpretty=expanded` output as a guide for hand-written impls could get a nasty surprise. This commit fixes things by instead using this form: ``` ({ self.x }) == ({ other.x }) ``` r? ``@RalfJung``
2023-02-01Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.Nicholas Nethercote-0/+4
If you do `derive(PartialEq)` on a packed struct, the output shown by `-Zunpretty=expanded` includes expressions like this: ``` { self.x } == { other.x } ``` This is invalid syntax. This doesn't break compilation, because the AST nodes are constructed within the compiler. But it does mean anyone using `-Zunpretty=expanded` output as a guide for hand-written impls could get a nasty surprise. This commit fixes things by instead using this form: ``` ({ self.x }) == ({ other.x }) ```
2023-01-31Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obkGuillaume Gomez-1/+1
Improve enum checks Some light refactoring.
2023-01-30session: diagnostic migration lint on more fnsDavid Wood-3/+10
Apply the diagnostic migration lint to more functions on `Session`. Signed-off-by: David Wood <david.wood@huawei.com>
2023-01-30Replace some `_ == _ || _ == _`s with `matches!(_, _ | _)`sMaybe Waffle-1/+1
2023-01-20preserve delim spans during `macro_rules!` expansion if ableLukas Markeffsky-6/+18
2023-01-20Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstriebbors-82/+75
Remove some `ref` patterns from the compiler Previous PR: https://github.com/rust-lang/rust/pull/105368 r? `@Nilstrieb`
2023-01-17Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726Matthias Krüger-3/+3
Remove double spaces after dots in comments Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-3/+3
2023-01-17`rustc_expand`: remove `ref` patternsMaybe Waffle-82/+75
2023-01-13Update `rental` hack to work with remapped paths.Tim Neumann-4/+6
2023-01-12parse const closuresDeadbeef-0/+1
2023-01-05Shrink `ParseResult` in the hot path.Nilstrieb-30/+81
A recent PR increased the size, which caused regressions. This uses the existing generic infrastructure to differentiate between the hot path and the diagnostics path.
2023-01-02Auto merge of #84762 - cjgillot:resolve-span-opt, r=petrochenkovbors-1/+1
Encode spans relative to the enclosing item -- enable on nightly Follow-up to #84373 with the flag `-Zincremental-relative-spans` set by default. This PR seeks to remove one of the main shortcomings of incremental: the handling of spans. Changing the contents of a function may require redoing part of the compilation process for another function in another file because of span information is changed. Within one file: all the spans in HIR change, so typechecking had to be re-done. Between files: spans of associated types/consts/functions change, so type-based resolution needs to be re-done (hygiene information is stored in the span). The flag `-Zincremental-relative-spans` encodes local spans relative to the span of an item, stored inside the `source_span` query. Trap: stashed diagnostics are referenced by the "raw" span, so stealing them requires to remove the span's parent. In order to avoid too much traffic in the span interner, span encoding uses the `ctxt_or_tag` field to encode: - the parent when the `SyntaxContext` is 0; - the `SyntaxContext` when the parent is `None`. Even with this, the PR creates a lot of traffic to the Span interner, when a Span has both a LocalDefId parent and a non-root SyntaxContext. They appear in lowering, when we add a parent to all spans, including those which come from macros, and during inlining when we mark inlined spans. The last commit changes how queries of `LocalDefId` manage their cache. I can put this in a separate PR if required. Possible future directions: - validate that all spans are marked in HIR validation; - mark macro-expanded spans relative to the def-site and not the use-site.
2023-01-01Merge multiple mutable borrows of immutable binding errorsEsteban Küber-2/+2
Fix #53466.
2022-12-29Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, ↵Matthias Krüger-2/+2
r=compiler-errors Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-28Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-errorsMatthias Krüger-15/+44
Properly calculate best failure in macro matching Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream. This needs a little cleanup as the `best_failure` field is getting out of hand but it should be mostly good to go. I hope I didn't violate too many abstraction boundaries..
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-2/+2
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-27Recover `fn` keyword as `Fn` trait in boundsMichael Goulet-1/+1
2022-12-25Only enable relative span hashing on nightly.Camille GILLOT-1/+1
2022-12-25Enable relative span hashing.Camille GILLOT-1/+1
2022-12-25fix more clippy::style findingsMatthias Krüger-5/+1
match_result_ok obfuscated_if_else single_char_add writeln_empty_string collapsible_match iter_cloned_collect unnecessary_mut_passed
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-1/+1
2022-12-18don't restuct references just to reborrowMatthias Krüger-3/+3
2022-12-12Properly calculate best failure in macro matchingNilstrieb-15/+44
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream.
2022-12-12Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkovbors-24/+24
Remove `token::Lit` from `ast::MetaItemLit`. Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time. r? `@petrochenkov`
2022-12-11Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-deadMatthias Krüger-1/+0
compiler: remove unnecessary imports and qualified paths Some of these imports were necessary before Edition 2021, others were already in the prelude. I hope it's fine that this PR is so spread-out across files :/
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-12-10Migrate parts of `rustc_expand` to session diagnosticsnils-207/+488
This migrates everything but the `mbe` and `proc_macro` modules. It also contains a few cleanups and drive-by/accidental diagnostic improvements which can be seen in the diff for the UI tests.
2022-12-07Use `Symbol` for the crate name instead of `String`/`str`Oli Scherer-2/+2
2022-12-05Remove three uses of `LitKind::synthesize_token_lit`.Nicholas Nethercote-2/+2
2022-12-05Remove `ExtCtxt::expr_lit`.Nicholas Nethercote-22/+21
2022-12-03Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillotMatthias Krüger-0/+3
Keep track of the start of the argument block of a closure This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by #97417. VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem. r? `@cjgillot`
2022-12-02Add `StrStyle` to `ast::LitKind::ByteStr`.Nicholas Nethercote-3/+4
This is required to distinguish between cooked and raw byte string literals in an `ast::LitKind`, without referring to an adjacent `token::Lit`. It's a prerequisite for the next commit.
2022-12-02Rename `LitKind::to_token_lit` as `LitKind::synthesize_token_lit`.Nicholas Nethercote-2/+2
This makes it clearer that it's not a lossless conversion, which I find helpful.
2022-12-01Rollup merge of #105078 - TaKO8Ki:fix-105011, r=nnethercoteMatthias Krüger-1/+5
Fix `expr_to_spanned_string` ICE Fixes #105011
2022-11-30report literal errors when `token_lit` has errorsTakayuki Maeda-1/+5
2022-11-29Avoid more `MetaItem`-to-`Attribute` conversions.Nicholas Nethercote-4/+16
There is code for converting `Attribute` (syntactic) to `MetaItem` (semantic). There is also code for the reverse direction. The reverse direction isn't really necessary; it's currently only used when generating attributes, e.g. in `derive` code. This commit adds some new functions for creating `Attributes`s directly, without involving `MetaItem`s: `mk_attr_word`, `mk_attr_name_value_str`, `mk_attr_nested_word`, and `ExtCtxt::attr_{word,name_value_str,nested_word}`. These new methods replace the old functions for creating `Attribute`s: `mk_attr_inner`, `mk_attr_outer`, and `ExtCtxt::attribute`. Those functions took `MetaItem`s as input, and relied on many other functions that created `MetaItems`, which are also removed: `mk_name_value_item`, `mk_list_item`, `mk_word_item`, `mk_nested_word_item`, `{MetaItem,MetaItemKind,NestedMetaItem}::token_trees`, `MetaItemKind::attr_args`, `MetaItemLit::{from_lit_kind,to_token}`, `ExtCtxt::meta_word`. Overall this cuts more than 100 lines of code and makes thing simpler.
2022-11-29Remove an out-of-date comment.Nicholas Nethercote-2/+0
This comment dates back to at least 2013, and is no longer relevant. (There used to be an `allow` attribute, but that's no longer present.)