about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/deriving
AgeCommit message (Collapse)AuthorLines
2025-09-29Use `Iterator::eq` and (dogfood) `eq_by` in compiler and libraryYotam Ofek-11/+4
2025-09-15Remove UnsizedConstParamTy trait and make it into an unstable impltiif-39/+0
2025-08-19Avoid using `()` in `derive(From)` output.Nicholas Nethercote-35/+36
Using an error type instead of `()` avoids the duplicated errors on `struct SUnsizedField` in `deriving-from-wrong-target.rs`. It also improves the expanded output from this: ``` struct S2(u32, u32); impl ::core::convert::From<()> for S2 { #[inline] fn from(value: ()) -> S2 { (/*ERROR*/) } } ``` to this: ``` struct S2(u32, u32); impl ::core::convert::From<(/*ERROR*/)> for S2 { #[inline] fn from(value: (/*ERROR*/)) -> S2 { (/*ERROR*/) } } ``` The new code also only matchs on `item.kind` once.
2025-08-15Implement `#[derive(From)]`Jakub Beránek-5/+131
2025-08-15Create unstable `From` builtin macro and register itJakub Beránek-0/+14
2025-08-11Extract ast TraitImplHeaderCameron Steffen-23/+31
2025-08-09remove `P`Deadbeef-57/+54
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-1/+1
2025-07-17Make `derive_const` usable within libcore againOli Scherer-3/+57
Also make it *only* usable on nightly
2025-07-15Allow `Early` stage to emit errorsJonathan Brouwer-1/+1
2025-07-07Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmeaseJacob Pratt-3/+3
compiler: rename BareFn to FnPtr At some point "BareFn" was the chosen name for a "bare" function, without the niceties of `~fn`, `&fn`, or a few other ways of writing a function type. However, at some point the syntax for a "bare function" and any other function diverged even more. We started calling them what they are: function pointers, denoted by their own syntax. However, we never changed the *internal* name for these, as this divergence was very gradual. Personally, I have repeatedly searched for "FnPtr" and gotten confused until I find the name is BareFn, only to forget this until the next time, since I don't routinely interact with the higher-level AST and HIR. But even tools that interact with these internal types only touch on them in a few places, making a migration easy enough. Let's use a more intuitive and obvious name, as this 12+ year old name has little to do with current Rust.
2025-07-06compiler: rename {ast,hir}::BareFn* to FnPtr*Jubilee Young-3/+3
Fix some comments and related types and locals where it is obvious, e.g. - bare_fn -> fn_ptr - LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-06Rewrite empty attribute lintJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-03Replace kw_span by full span.Camille GILLOT-3/+3
2025-06-17Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkovJacob Pratt-3/+2
avoid `&mut P<T>` in `visit_expr` etc methods trying a different way than rust-lang/rust#141636 r? ghost
2025-06-12avoid `&mut P<T>` in `visit_expr` etc methodsDeadbeef-3/+2
2025-06-12introduce new lint infraJana Dönszelmann-1/+1
lint on duplicates during attribute parsing To do this we stuff them in the diagnostic context to be emitted after hir is constructed
2025-06-06Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-deadGuillaume Gomez-1/+1
Reduce `ast::ptr::P` to a typedef of `Box` As per the MCP at https://github.com/rust-lang/compiler-team/issues/878. r? `@fee1-dead`
2025-06-03Rollup merge of #141724 - Sol-Ell:issue-141141-fix, r=nnethercoteMatthias Krüger-58/+162
fix(#141141): When expanding `PartialEq`, check equality of scalar types first. Fixes rust-lang/rust#141141. Now, `cs_eq` function of `partial_eq.rs` compares [scalar types](https://doc.rust-lang.org/rust-by-example/primitives.html#scalar-types) first. - Add `is_scalar` field to `FieldInfo`. - Add `is_scalar` method to `TyKind`. - Pass `FieldInfo` via `CsFold::Combine` and refactor code relying on it. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for FloatTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for IntTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for UintTy.
2025-06-02Separately check equality of the scalar types and compound types in the ↵Ell-58/+162
order of declaration.
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-7/+7
So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ```
2025-05-27Reduce `P<T>` to a typedef of `Box<T>`.Nicholas Nethercote-1/+1
Keep the `P` constructor function for now, to minimize immediate churn. All the `into_inner` calls are removed, which is nice.
2025-05-18Remove rustc_attr_data_structures re-export from rustc_attr_parsingmejrs-1/+2
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-3/+2
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-16/+13
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-03-24Remove fields that are dead since the removal of type ascription syntaxLeón Orell Valerian Liehr-1/+0
Since `{ ident: ident }` is a parse error, these fields are dead.
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-0/+1
2025-03-01Implment `#[cfg]` and `#[cfg_attr]` in `where` clausesFrank King-10/+20
2025-02-24Introduce new-style attribute parsers for several attributesJana Dönszelmann-9/+6
note: compiler compiles but librustdoc and clippy don't
2025-02-11Rollup merge of #136107 - dingxiangfei2009:coerce-pointee-wellformed, ↵Matthias Krüger-19/+55
r=compiler-errors Introduce CoercePointeeWellformed for coherence checks at typeck stage Fix #135206 This is the first PR to introduce the "wellformedness" check for `derive(CoercePointee)`. This patch introduces a new error code to cover all the prerequisites of the said macro. The checks that is enforced with this patch is whether the data is indeed `struct` and whether the layout is set to `repr(transparent)`. A following series of patch will arrive later to address the following concern. 1. #135217 so that we would only admit one single coercion on one type parameter, and leave the rest for future consideration in tandem of development of other coercion rules. 1. Enforcement of data field requirements. **An open question** is whether there is a good schema to encode the `#[pointee]` as well, so that we could also check if the `#[pointee]` type parameter is indeed `?Sized`. ``@rustbot`` label F-derive_coerce_pointee
2025-02-09move repr(transparent) checks to coherenceDing Xiang Fei-10/+0
2025-02-09rename the trait to validity and place a feature gate afrontDing Xiang Fei-2/+2
2025-02-09introduce CoercePointeeWellformed for coherence checks at typeck stageDing Xiang Fei-9/+55
2025-02-08Rustfmtbjorn3-32/+51
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-0/+1
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-02-02Rollup merge of #134272 - RalfJung:destabilize-rustc_encodable_decodable, ↵Matthias Krüger-523/+10
r=oli-obk Remove rustc_encodable_decodable feature This has been shown in future-compat reports since Rust 1.79 (https://github.com/rust-lang/rust/pull/116016), released June 2024. Let's see if crater still finds any issues. Part of https://github.com/rust-lang/rust/issues/134301. Cc ``@rust-lang/libs-api``
2025-01-27Remove redundant to_ident_string callsMichael Goulet-2/+2
2025-01-14remove Rustc{En,De}codable from library and compilerRalf Jung-523/+10
2024-12-21Use E0665 for missing `#[default]` errorEsteban Küber-4/+9
Use orphaned error code for the same error it belonged to before. ``` error[E0665]: `#[derive(Default)]` on enum with no `#[default]` --> $DIR/macros-nonfatal-errors.rs:42:10 | LL | #[derive(Default)] | ^^^^^^^ LL | / enum NoDeclaredDefault { LL | | Foo, LL | | Bar, LL | | } | |_- this enum needs a unit variant marked with `#[default]` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) help: make this unit variant default by placing `#[default]` on it | LL | #[default] Foo, | ~~~~~~~~~~~~~~ help: make this unit variant default by placing `#[default]` on it | LL | #[default] Bar, | ~~~~~~~~~~~~~~ ```
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-28/+14
`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-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+2
2024-12-09Disallow `#[default] Variant {}` regardless of feature flagEsteban Küber-2/+14
2024-12-09Introduce `default_field_values` featureEsteban Küber-16/+61
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-04make CoercePointee errors translatableDing Xiang Fei-41/+56
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-34/+19
2024-11-11remove attributes from generics in built-in derive macrosPonasKovas-0/+6
add a test add github issue link to description of the test replace new ThinVec with clear() Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-10-27Auto merge of #131284 - ↵bors-11/+11
dingxiangfei2009:rename-smart-ptr-to-coerce-referent, r=compiler-errors Rename macro `SmartPointer` to `CoercePointee` As per resolution #129104 we will rename the macro to better reflect the technical specification of the feature and clarify the communication. - `SmartPointer` is renamed to `CoerceReferent` - `#[pointee]` attribute is renamed to `#[referent]` - `#![feature(derive_smart_pointer)]` gate is renamed to `#![feature(derive_coerce_referent)]`. - Any mention of `SmartPointer` in the file names are renamed accordingly. r? `@compiler-errors` cc `@nikomatsakis` `@Darksonn`
2024-10-24Pass Ident by reference in ast Visitormaxcabrajac-1/+1
2024-10-24s/SmartPointer/CoerceReferent/gDing Xiang Fei-11/+11
move derive_smart_pointer into removed set
2024-10-14Move trait bound modifiers into ast::PolyTraitRefMichael Goulet-5/+5