about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/derive.rs
AgeCommit message (Collapse)AuthorLines
2025-08-11Allow attr entries to declare list of alternatives for `List` and ↵Esteban Küber-2/+4
`NamedValueStr` Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles. Suggestions now provide more correct suggested code: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler)] | LL - #[used(compiler, linker)] LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler|linker)] | LL - #[used(compiler, linker)] LL + #[used] | ```
2025-03-25Use `Ident::dummy()` in `dummy_annotatable`.Nicholas Nethercote-1/+1
This is exactly the kind of case `Ident::dummy()` is for.
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-10-07Rename nested_meta to meta_item_innercodemountains-1/+1
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-3/+3
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-08-07Stabilize `unsafe_attributes`carbotaniuman-1/+0
2024-07-30Add toggle for `parse_meta_item` unsafe parsingcarbotaniuman-12/+1
This makes it possible for the `unsafe(...)` syntax to only be valid at the top level, and the `NestedMetaItem`s will automatically reject `unsafe(...)`.
2024-07-29Deny unsafe on more builtin attributescarbotaniuman-0/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-06Handle safe casecarbotaniuman-0/+1
2024-06-06Fix formattingcarbotaniuman-1/+1
2024-06-06Fix buildcarbotaniuman-3/+3
2024-06-06Disallow unsafe in derivecarbotaniuman-1/+11
2024-04-26Introduce `DeriveResolution`.Nicholas Nethercote-6/+13
Making this a proper struct, and giving its fields names, makes things easier to understand.
2024-04-25Name the field in `Expander`.Nicholas Nethercote-2/+4
For code clarity.
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-1/+1
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-4/+4
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-3/+3
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-06-19use `ErrorGuaranteed` instead of booleansLukas Markeffsky-5/+9
2023-04-10Migrate most of `rustc_builtin_macros` to diagnostic implsclubby789-28/+12
Co-authored-by: Joe ST <joe@fbstj.net> Co-authored-by: Michael Goulet <michael@errs.io>
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-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-4/+5
`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-09-20Add the `#[derive_const]` attributeDeadbeef-4/+5
2022-09-14make `mk_attr_id` part of `ParseSess`SparrowLii-1/+2
2022-08-16Rename some things related to literals.Nicholas Nethercote-3/+3
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`.
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-1/+1
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-1/+1
2022-04-30Save colon span to suggest bounds.Camille GILLOT-0/+1
2022-03-01Improve allowness of the unexpected_cfgs lintLoïc BRANSTETT-1/+6
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-1/+1
2021-10-17rustc_span: `Ident::invalid` -> `Ident::empty`Vadim Petrochenkov-1/+1
The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s.
2021-09-24derive: Do not configure or clone items unless necessaryVadim Petrochenkov-7/+33
2021-09-24builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for `A, B, ↵Vadim Petrochenkov-2/+2
...`
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-1/+4
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-06-20expand: Move some more derive logic to `rustc_builtin_macros`Vadim Petrochenkov-2/+4
2021-04-04resolve/expand: Cache intermediate results of `#[derive]` expansionVadim Petrochenkov-25/+32
2021-03-07rustc_builtin_macros: Share some more logic between `derive` and `cfg_eval`Vadim Petrochenkov-18/+3
2021-03-07Move full configuration logic from `rustc_expand` to `rustc_builtin_macros`Vadim Petrochenkov-3/+6
This logic is applicable to two specific macros and not to the expansion infrastructure in general.
2021-03-06rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut`Vadim Petrochenkov-9/+3
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-0/+132