summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2022-12-06`rustc_builtin_macros`: remove `ref` patternsMaybe Waffle-196/+176
... and other pattern matching improvements
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-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.
2022-11-12Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obkDylan DPC-20/+56
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-1/+21
2022-11-11Rollup merge of #103445 - fmease:fix-50291, r=estebankDylan DPC-6/+12
`#[test]`: Point at return type if `Termination` bound is unsatisfied Together with #103142 (already merged) this fully fixes #50291. I don't consider my current solution of changing a few spans “here and there” very clean since the failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument. If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject `let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc. used by some built-in derive-macros. I haven't tried that approach yet though and cannot promise that it would actually work out or be “cleaner” for that matter. ````@rustbot```` label A-libtest A-diagnostics r? ````@estebank````
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-0/+106
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-26Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkovDylan DPC-1/+8
Workaround unstable stmt_expr_attributes for method receiver expressions Fixes https://github.com/rust-lang/rust/issues/103244 cc ``@Mark-Simulacrum`` ``@ehuss``
2022-10-24Rollup merge of #99939 - saethlin:pre-sort-tests, r=thomcc,jackh726Yuki Okushi-17/+35
Sort tests at compile time, not at startup Recently, another Miri user was trying to run `cargo miri test` on the crate `iced-x86` with `--features=code_asm,mvex`. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue. Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately. (except for doctests, because there is no compile-time harness)
2022-10-23test attr: point at return type if Termination bound unsatisfiedLeón Orell Valerian Liehr-6/+12
2022-10-23Workaround unstable stmt_expr_attributes for method receiver expressions.Camille GILLOT-1/+8
2022-10-23Migrate all diagnosticsNilstrieb-2/+2
2022-10-15Mark derived StructuralEq as automatically derived.Camille GILLOT-5/+11
2022-10-10Rename AssocItemKind::TyAlias to AssocItemKind::TypeMichael Goulet-1/+1
2022-10-06Auto merge of #99324 - reez12g:issue-99144, r=jyn514bors-1/+7
Enable doctests in compiler/ crates Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-03Rollup merge of #101040 - ↵Matthias Krüger-1/+35
danielhenrymantilla:no-bounds-for-default-annotated-derive, r=joshtriplett Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds That is, given something like: ```rs // #[default] on a generic enum does not add `Default` bounds to the type params. #[derive(Default)] enum MyOption<T> { #[default] None, Some(T), } ``` then `MyOption<T> : Default`_as currently implemented_ only holds when `T : Default`, as reported by ```@5225225``` [over Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.23.5Bderive.28Default.29.5D.20for.20enums.20with.20fields). This is contrary to [what the accepted RFC proposes](https://rust-lang.github.io/rfcs/3107-derive-default-enum.html#generated-bounds) (_i.e._, that `T` be allowed not to be itself `Default`), and indeed seems to be a rather unnecessary limitation.
2022-10-02Fix duplicate usage of `a` article.Petr Portnov-1/+1
This fixes a typo first appearing in #94624 in which test-macro diagnostic uses "a" article twice. Since I searched sources for " a a " sequences, I also fixed the same issue in a few source files where I found it. Signed-off-by: Petr Portnov <gh@progrm-jarvis.ru>
2022-10-02Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-sebors-1/+1
Change `is_some_and` to take by value Consistent with other function-accepting `Option` methods. Tracking issue: #93050 r? `@m-ou-se`
2022-10-01Change feature name to is_some_andCameron Steffen-1/+1
2022-09-30Fix format_args capture for macro expanded format stringsAlex Macleod-3/+3
2022-09-29Fix docs in compiler/rustc_builtin_macros/src/deriving/generic/mod.rsreez12g-0/+5
2022-09-29Fix docs in compiler/rustc_builtin_macros/src/assert/context.rsreez12g-1/+1
2022-09-29Add feature flag to docs in compiler/rustc_builtin_macros/src/assert/context.rsreez12g-0/+1
2022-09-27Remove confusing drop.Mara Bos-1/+0
2022-09-27Update doc comments.Mara Bos-2/+2