about summary refs log tree commit diff
path: root/compiler/rustc_span
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-08-15 18:13:28 -0400
committerGitHub <noreply@github.com>2025-08-15 18:13:28 -0400
commit2b1a288dfc5a2cce12b8c1a2eef22f89d894c094 (patch)
tree3209bcfa71772aeb8fc4294944742f4a91c3ed10 /compiler/rustc_span
parentd077146a15fd1f31c30fbb37cec70e2325a05adf (diff)
parent1f3a7471bfb05a5fd76309545de0412d265e28be (diff)
downloadrust-2b1a288dfc5a2cce12b8c1a2eef22f89d894c094.tar.gz
rust-2b1a288dfc5a2cce12b8c1a2eef22f89d894c094.zip
Rollup merge of #144922 - Kobzol:derive-from, r=nnethercote
Implement `#[derive(From)]`

Implements the `#[derive(From)]` feature ([tracking issue](https://github.com/rust-lang/rust/issues/144889), [RFC](https://github.com/rust-lang/rfcs/pull/3809)).

It allows deriving the `From` impl on structs and tuple structs with exactly one field. Some implementation notes:
- I wasn't exactly sure which spans to use in the derive generating code, so I just used `span` everywhere. I don't know if it's the Right Thing To Do. In particular the errors when `#[derive(From)]` is used on a struct with an unsized field are weirdly duplicated.
- I had to solve an import stability problem, where if I just added the unstable `macro From` to `core::convert`, previously working code like `use std::convert::From` would suddenly require an unstable feature gate, because rustc would think that you're trying to import the unstable macro. `@petrochenkov` suggested that I add the macro the the core prelude instead. This has worked well, although it only works in edition 2021+. Not sure if I botched the prelude somehow and it should live elsewhere (?).
- I had to add `Ty::AstTy`, because the `from` function receives an argument with the type of the single field, and the existing variants of the `Ty` enum couldn't represent an arbitrary type.
Diffstat (limited to 'compiler/rustc_span')
-rw-r--r--compiler/rustc_span/src/symbol.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index f7a8258a9d8..8e26aa9e77f 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -392,6 +392,7 @@ symbols! {
         __D,
         __H,
         __S,
+        __T,
         __awaitee,
         __try_var,
         _t,
@@ -746,6 +747,7 @@ symbols! {
         contracts_ensures,
         contracts_internals,
         contracts_requires,
+        convert,
         convert_identity,
         copy,
         copy_closures,
@@ -847,6 +849,7 @@ symbols! {
         derive_const,
         derive_const_issue: "118304",
         derive_default_enum,
+        derive_from,
         derive_smart_pointer,
         destruct,
         destructuring_assignment,
@@ -2331,6 +2334,7 @@ symbols! {
         va_start,
         val,
         validity,
+        value,
         values,
         var,
         variant_count,