about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2022-11-29Avoid unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote-1/+1
`check_builtin_attribute` calls `parse_meta` to convert an `Attribute` to a `MetaItem`, which it then checks. However, many callers of `check_builtin_attribute` start with a `MetaItem`, and then convert it to an `Attribute` by calling `cx.attribute(meta_item)`. This `MetaItem` to `Attribute` to `MetaItem` conversion is silly. This commit adds a new function `check_builtin_meta_item`, which can be called instead from these call sites. `check_builtin_attribute` also now calls it. The commit also renames `check_meta` as `check_attr` to better match its arguments.
2022-11-28Rollup merge of #104804 - nnethercote:MetaItemLit, r=petrochenkovMatthias Krüger-5/+2
Rename `ast::Lit` as `ast::MetaItemLit`. And some other literal cleanups. r? `@petrochenkov`
2022-11-28Rollup merge of #104795 - estebank:multiline-spans, r=TaKO8KiDylan DPC-54/+54
Change multiline span ASCII art visual order Tweak the ASCII art for nested multiline spans so that we minimize line overlaps. Partially addresses https://github.com/rust-lang/rust/issues/61017.
2022-11-28Keep track of the start of the argument block of a closureSarthak Singh-0/+3
2022-11-28Change multiline span ASCII art visual orderEsteban Küber-54/+54
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-4/+1
2022-11-28Remove `Lit::from_included_bytes`.Nicholas Nethercote-2/+2
`Lit::from_included_bytes` calls `Lit::from_lit_kind`, but the two call sites only need the resulting `token::Lit`, not the full `ast::Lit`. This commit changes those call sites to use `LitKind::to_token_lit`, which means `from_included_bytes` can be removed.
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-7/+10
2022-11-25Clarify `SyntaxExtensionKind::LegacyDerive`.Nicholas Nethercote-1/+6
2022-11-22Rollup merge of #104638 - Nilstrieb:macro-diagnostics, r=compiler-errorsManish Goregaokar-237/+268
Move macro_rules diagnostics to diagnostics module This will make it easier to add more diagnostics in the future in a centralized place.
2022-11-22Rollup merge of #104559 - nnethercote:split-MacArgs, r=petrochenkovMatthias Krüger-9/+13
Split `MacArgs` in two. `MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values. r? `@petrochenkov`
2022-11-22Rollup merge of #104416 - clubby789:fix-104414, r=eholkMatthias Krüger-1/+1
Fix using `include_bytes` in pattern position Fix #104414
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-9/+13
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-20Move macro_rules diagnostics to diagnostics moduleNilstrieb-237/+268
2022-11-19Cleanup macro matching recoveryNilstrieb-1/+0
The retry has been implemented already.
2022-11-19Rollup merge of #104566 - matthiaskrgr:clippy_perf_nov18, r=oli-obkDylan DPC-1/+1
couple of clippy::perf fixes
2022-11-18couple of clippy::perf fixesMatthias Krüger-1/+1
2022-11-17Use `ThinVec` in `ast::Path`.Nicholas Nethercote-8/+5
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-7/+7
patterns.
2022-11-16Auto merge of #102944 - nnethercote:ast-Lit-third-time-lucky, r=petrochenkovbors-18/+16
Use `token::Lit` in `ast::ExprKind::Lit`. Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. r? `@petrochenkov`
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-18/+16
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-11-15Only do parser recovery on retried macro matchingNilstrieb-8/+27
This prevents issues with eager parser recovery during macro matching.
2022-11-15Rollup merge of #103439 - Nilstrieb:help-me-with-my-macro, r=estebankMatthias Krüger-11/+76
Show note where the macro failed to match When feeding the wrong tokens, it used to fail with a very generic error that wasn't very helpful. This change tries to help by noting where specifically the matching went wrong. ```rust macro_rules! uwu { (a a a b) => {}; } uwu! { a a a c } ``` ```diff error: no rules expected the token `c` --> macros.rs:5:14 | 1 | macro_rules! uwu { | ---------------- when calling this macro ... 4 | uwu! { a a a c } | ^ no rules expected this token in macro call | +note: while trying to match `b` + --> macros.rs:2:12 + | +2 | (a a a b) => {}; + | ^ ```
2022-11-14Show a note where a macro failed to matchNilstrieb-11/+76
This shows a small note on what the macro matcher was currently processing to aid with "no rules expected the token X" errors.
2022-11-14Fix using `include_bytes` in pattern positionclubby789-1/+1
2022-11-13fix some typos in commentscui fliter-1/+1
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-11-12Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkovbors-0/+7
Delay `include_bytes` to AST lowering Hopefully addresses #65818. This PR introduces a new `ExprKind::IncludedBytes` which stores the path and bytes of a file included with `include_bytes!()`. We can then create a literal from the bytes during AST lowering, which means we don't need to escape the bytes into valid UTF8 which is the cause of most of the overhead of embedding large binary blobs.
2022-11-12Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obkDylan DPC-7/+11
Add the `#[derive_const]` attribute Closes #102371. This is a minimal patchset for the attribute to work. There are no restrictions on what traits this attribute applies to. r? `````@oli-obk`````
2022-11-11Introduce `ExprKind::IncludedBytes`clubby789-0/+7
2022-11-04Small style improvementsnils-12/+13
2022-11-02Add some debug logs to macro matchingNilstrieb-0/+8
These were useful while debugging, so I'll leave them here.
2022-11-02Retry matching with tracking for diagnosticsNilstrieb-9/+109
For now, we only collect the small info for the `best_failure`, but using this tracker, we can easily extend it in the future to track things with more performance overhead. We cannot retry cases where the macro failed with a parser error that was emitted already, as that would cause us to emit the same error to the user twice.
2022-11-02Factor out matching into `try_match_macro`Nilstrieb-124/+129
This moves out the matching part of expansion into a new function. This function will try to match the macro and return an error if it failed to match. A tracker can be used to get more information about the matching.
2022-11-02Add `Tracker` to track matching operationsNilstrieb-17/+48
This should allow us to collect detailed information without slowing down the inital hot path.
2022-11-02Small parser cleanupsNilstrieb-5/+5
2022-11-02Store `ErrorGuaranteed` in `ErrorReported`Nilstrieb-5/+6
2022-11-01Auto merge of #103217 - mejrs:track, r=eholkbors-0/+1
Track where diagnostics were created. This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`. For example, the following code... ```rust struct A; struct B; fn main(){ let _: A = B; } ``` ...now emits the following error message: ``` error[E0308]: mismatched types --> src\main.rs:5:16 | 5 | let _: A = B; | - ^ expected struct `A`, found struct `B` | | | expected due to this -Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31 ```
2022-10-27Rollup merge of #103544 - Nilstrieb:no-recovery-pls, r=compiler-errorsMatthias Krüger-0/+1
Add flag to forbid recovery in the parser To start the effort of fixing #103534, this adds a new flag to the parser, which forbids the parser from doing recovery, which it shouldn't do in macros. This doesn't add any new checks for recoveries yet and is just here to bikeshed the names for the functions here before doing more. r? `@compiler-errors`
2022-10-26Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkovDylan DPC-3/+78
Workaround unstable stmt_expr_attributes for method receiver expressions Fixes https://github.com/rust-lang/rust/issues/103244 cc ``@Mark-Simulacrum`` ``@ehuss``
2022-10-25Add flag to forbid recovery in the parserNilstrieb-0/+1
2022-10-24Auto merge of #94063 - Aaron1011:pretty-print-rental, r=lcnrbors-11/+35
Only apply `ProceduralMasquerade` hack to older versions of `rental` The latest version of `rental` (v0.5.6) contains a fix that allows it to compile without relying on the pretty-print back-compat hack. Hopefully, there are no longer any crates relying on the affected versions of the (much less popular) `procedural-masquerade` crate. This should allow us to target the pretty-print back-compat hack specifically to older versions of `rental`, and specifically mention upgrading to `rental` v0.5.6 in the lint message.
2022-10-23Workaround unstable stmt_expr_attributes for method receiver expressions.Camille GILLOT-3/+78
2022-10-23Migrate all diagnosticsNilstrieb-8/+8
2022-10-21Only apply `ProceduralMasquerade` hack to older versions of `rental`Aaron Hill-11/+35
The latest version of `rental` (v0.5.6) contains a fix that allows it to compile without relying on the pretty-print back-compat hack. Hopefully, there are no longer any crates relying on the affected versions of the (much less popular) `procedural-masquerade` crate. This should allow us to target the pretty-print back-compat hack specifically to older versions of `rental`, and specifically mention upgrading to `rental` v0.5.6 in the lint message.
2022-10-21Rollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obkDylan DPC-2/+3
Filtering spans when emitting json According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.
2022-10-20Implement assertions and fixes to not emit empty spans without suggestionsKevin Per-2/+3
2022-10-19Implement -Ztrack-diagnosticsmejrs-0/+1
2022-10-18Fix the bug of next_point in spanyukang-5/+4
2022-10-14more dupe word typosRageking8-1/+1
2022-10-12Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011bors-73/+71
Remove `TokenStreamBuilder` `TokenStreamBuilder` is used to combine multiple token streams. It can be removed, leaving the code a little simpler and a little faster. r? `@Aaron1011`