about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2023-01-15allow negative numeric literals in `concat!`Ezra Shaw-1/+14
2023-01-12Update comment explaining format_args!() expansion.Mara Bos-4/+4
2023-01-12Expand format_args!() in rust_ast_lowering.Mara Bos-601/+7
2023-01-02Update format.rsGimbles-1/+1
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-7/+6
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-24Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholkMatthias Krüger-1/+1
rustc: Remove needless lifetimes
2022-12-23Rollup merge of #105978 - jyn514:unused_proc_macro_decl, r=tmiaskoMatthias Krüger-0/+2
Mark `proc_macro_decls_static` as always used This would have avoided a bug in https://github.com/rust-lang/rust/pull/104860. In practice this shouldn't matter since nothing uses the query other than the `dead_code` lint, but this isn't documented as an internal-only query so it seems nice for it to be accurate. I think for `dead_code` it doesn't matter because the relevant code is generated by `rustc_builtin_macros` and isn't linted. I think `@tmiasko` or `@bjorn3` would be a good reviewer? r? `@tmiasko`
2022-12-22Mark `proc_macro_decls_static` as always usedJoshua Nelson-0/+2
This would have avoided a bug in https://github.com/rust-lang/rust/pull/104860. In practice this shouldn't matter since nothing uses the query other than the `dead_code` lint, but this isn't documented as an internal-only query so it seems nice for it to be accurate. I think for `dead_code` it doesn't matter because the relevant code is generated by `rustc_builtin_macros` and isn't linted.
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-1/+1
2022-12-18Rollup merge of #105870 - matthiaskrgr:useless_conv, r=oli-obkMatthias Krüger-2/+1
avoid .into() conversion to identical types
2022-12-18avoid .into() conversion to identical typesMatthias Krüger-2/+1
2022-12-18remove redundant cloneMatthias Krüger-1/+1
2022-12-13Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, ↵Matthias Krüger-2/+2
r=compiler-errors Remove unnecessary uses of `clone`
2022-12-13remove unnecessary uses of `clone`Takayuki Maeda-2/+2
2022-12-12Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkovbors-7/+9
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-2/+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-2/+0
2022-12-10Migrate parts of `rustc_expand` to session diagnosticsnils-3/+3
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-09Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercotebors-1/+1
Shrink `rustc_parse_format::Piece` This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try. r? `@nnethercote`
2022-12-06`rustc_builtin_macros`: remove `ref` patternsMaybe Waffle-196/+176
... and other pattern matching improvements
2022-12-06Box `rustc_parse_format::Piece::NextArgument`Maybe Waffle-1/+1
This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try.
2022-12-02Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8KiMatthias Krüger-0/+37
Add `type_ascribe!` macro as placeholder syntax for type ascription This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription. I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether. Part of #101728
2022-12-02Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillotbors-1/+1
rustc_ast_lowering: Stop lowering imports into multiple items Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-02Remove `token::Lit` from `ast::MetaItemLit`.Nicholas Nethercote-4/+6
`token::Lit` contains a `kind` field that indicates what kind of literal it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has its own `kind` field. This means that `ast::MetaItemLit` encodes the literal kind in two different ways. This commit changes `ast::MetaItemLit` so it no longer wraps `token::Lit`. It now contains the `symbol` and `suffix` fields from `token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-12-02Add `StrStyle` to `ast::LitKind::ByteStr`.Nicholas Nethercote-3/+3
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-01rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov-1/+1
Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01Rollup merge of #105106 - jhpratt:issue-105101, r=TaKO8KiMatthias Krüger-1/+1
Fix ICE from #105101 Fixes #105101 Rather than comparing idents, compare spans, which should be unique to each variant.
2022-12-01Auto merge of #104861 - nnethercote:attr-cleanups, r=petrochenkovbors-95/+67
Attribute cleanups Best reviewed one commit at a time. r? `@petrochenkov`
2022-11-30Fix ICE from #105101Jacob Pratt-1/+1
2022-11-30Fix an ICE parsing a malformed literal in `concat_bytes!`.Nicholas Nethercote-1/+5
Fixes #104769.
2022-11-29Avoid more `MetaItem`-to-`Attribute` conversions.Nicholas Nethercote-65/+30
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-29Avoid more unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote-22/+23
In `Expander::expand` the code currently uses `mk_attr_outer` to convert a `MetaItem` to an `Attribute`, and then follows that with `meta_item_list` which converts back. This commit avoids the unnecessary conversions. There was one wrinkle: the existing conversions caused the bogus `<>` on `Default<>` to be removed. With the conversion gone, we get a second error message about the `<>`. This is a rare case, so I think it probably doesn't matter much.
2022-11-29Avoid unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote-10/+16
`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-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-1/+1
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-2/+2
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-29/+29
2022-11-24Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errorsMatthias Krüger-1/+1
Suggest `.clone()` or `ref binding` on E0382
2022-11-24Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors-3/+3
Use `as_deref` in compiler (but only where it makes sense) This simplifies some code :3 (there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-23Suggest `.clone()` or `ref binding` on E0382Esteban Küber-1/+1
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-16/+16
`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-21Streamline deriving on packed structs.Nicholas Nethercote-70/+24
The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self` The `let` pattern used in the third case is equivalent to the simpler field access in the first case. This commit changes the third case to use a field access. The commit also combines two boolean arguments (`is_packed` and `always_copy`) into a single field (`copy_fields`) earlier, to save passing both around.
2022-11-19Add unstable `type_ascribe` macroNilstrieb-0/+37
This macro serves as a placeholder for future type ascription syntax to make sure that the semantic implementation keeps working.
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-8/+8
patterns.
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-3/+3
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-53/+61
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-15Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726Matthias Krüger-50/+31
Deriving cleanups Fixing some minor problems `@RalfJung` found in #99046. r? `@RalfJung`
2022-11-14Remove TraitDef::generics.Nicholas Nethercote-38/+26
Because it's always empty.
2022-11-14Remove `addr_of` argument from `create_struct_pattern_fields`.Nicholas Nethercote-9/+3
Because it's always false.
2022-11-14Clarify `expand_struct_method_body`.Nicholas Nethercote-4/+3
Spotted by @RalfJung. This causes no behavioural changes.
2022-11-12Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkovbors-1/+21
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.