summaryrefslogtreecommitdiff
path: root/compiler/rustc_builtin_macros/src
Commit message (Collapse)AuthorAgeFilesLines
...
* | Rollup merge of #105978 - jyn514:unused_proc_macro_decl, r=tmiaskoMatthias Krüger2022-12-231-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`
| * Mark `proc_macro_decls_static` as always usedJoshua Nelson2022-12-221-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.
* | Rollup merge of #105870 - matthiaskrgr:useless_conv, r=oli-obkMatthias Krüger2022-12-181-2/+1
|\ \ | | | | | | | | | avoid .into() conversion to identical types
| * | avoid .into() conversion to identical typesMatthias Krüger2022-12-181-2/+1
| |/
* | remove redundant cloneMatthias Krüger2022-12-181-1/+1
|/
* Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, ↵Matthias Krüger2022-12-132-2/+2
|\ | | | | | | | | | | r=compiler-errors Remove unnecessary uses of `clone`
| * remove unnecessary uses of `clone`Takayuki Maeda2022-12-132-2/+2
| |
* | Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkovbors2022-12-122-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`
| * Remove `token::Lit` from `ast::MetaItemLit`.Nicholas Nethercote2022-12-021-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.
| * Add `StrStyle` to `ast::LitKind::ByteStr`.Nicholas Nethercote2022-12-021-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.
* | Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-deadMatthias Krüger2022-12-111-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 :/
| * | compiler: remove unnecessary imports and qualified pathsKaDiWa2022-12-101-2/+0
| | |
* | | Migrate parts of `rustc_expand` to session diagnosticsnils2022-12-103-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.
* | Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercotebors2022-12-091-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`
| * | Box `rustc_parse_format::Piece::NextArgument`Maybe Waffle2022-12-061-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.
* | | `rustc_builtin_macros`: remove `ref` patternsMaybe Waffle2022-12-0616-196/+176
|/ / | | | | | | ... and other pattern matching improvements
* | Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8KiMatthias Krüger2022-12-022-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
| * | Add unstable `type_ascribe` macroNilstrieb2022-11-192-0/+37
| | | | | | | | | | | | | | | This macro serves as a placeholder for future type ascription syntax to make sure that the semantic implementation keeps working.
* | | Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillotbors2022-12-021-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.
| * | rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov2022-12-011-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.
* | | Rollup merge of #105106 - jhpratt:issue-105101, r=TaKO8KiMatthias Krüger2022-12-011-1/+1
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | Fix ICE from #105101 Fixes #105101 Rather than comparing idents, compare spans, which should be unique to each variant.
| * | Fix ICE from #105101Jacob Pratt2022-11-301-1/+1
| | |
* | | Auto merge of #104861 - nnethercote:attr-cleanups, r=petrochenkovbors2022-12-0118-95/+67
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | Attribute cleanups Best reviewed one commit at a time. r? `@petrochenkov`
| * | Avoid more `MetaItem`-to-`Attribute` conversions.Nicholas Nethercote2022-11-2915-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.
| * | Avoid more unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote2022-11-291-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.
| * | Avoid unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote2022-11-293-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.
* | | Fix an ICE parsing a malformed literal in `concat_bytes!`.Nicholas Nethercote2022-11-301-1/+5
|/ / | | | | | | Fixes #104769.
* | Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote2022-11-281-1/+1
| | | | | | | | | | We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
* | Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote2022-11-281-2/+2
| |
* | Prefer doc comments over `//`-comments in compilerMaybe Waffle2022-11-275-29/+29
| |
* | Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errorsMatthias Krüger2022-11-241-1/+1
|\ \ | | | | | | | | | Suggest `.clone()` or `ref binding` on E0382
| * | Suggest `.clone()` or `ref binding` on E0382Esteban Küber2022-11-231-1/+1
| | |
* | | Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors2022-11-243-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")
| * | Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle2022-11-163-3/+3
| | |
* | | Split `MacArgs` in two.Nicholas Nethercote2022-11-223-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.
* | | Streamline deriving on packed structs.Nicholas Nethercote2022-11-211-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.
* | Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote2022-11-171-8/+8
| | | | | | | | patterns.
* | Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote2022-11-163-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
* Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726Matthias Krüger2022-11-1512-50/+31
|\ | | | | | | | | | | | | | | Deriving cleanups Fixing some minor problems `@RalfJung` found in #99046. r? `@RalfJung`
| * Remove TraitDef::generics.Nicholas Nethercote2022-11-1412-38/+26
| | | | | | | | Because it's always empty.
| * Remove `addr_of` argument from `create_struct_pattern_fields`.Nicholas Nethercote2022-11-141-9/+3
| | | | | | | | Because it's always false.
| * Clarify `expand_struct_method_body`.Nicholas Nethercote2022-11-141-4/+3
| | | | | | | | Spotted by @RalfJung. This causes no behavioural changes.
* | Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkovbors2022-11-124-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.
| * | Introduce `ExprKind::IncludedBytes`clubby7892022-11-114-1/+21
| |/
* | Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obkDylan DPC2022-11-1216-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`````
| * | Add the `#[derive_const]` attributeDeadbeef2022-09-2016-20/+56
| | |
* | | Rollup merge of #103445 - fmease:fix-50291, r=estebankDylan DPC2022-11-111-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````
| * | test attr: point at return type if Termination bound unsatisfiedLeón Orell Valerian Liehr2022-10-231-6/+12
| | |
* | | Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras2022-10-312-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).
* | | Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkovDylan DPC2022-10-261-1/+8
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Workaround unstable stmt_expr_attributes for method receiver expressions Fixes https://github.com/rust-lang/rust/issues/103244 cc ``@Mark-Simulacrum`` ``@ehuss``