rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]`
Status from this message: Applied to pin-init-next, with typo pointed out by Sashiko fixed.
Get series with b4
b4 am [email protected] change-id 20260923-dev-pin-data-diag-65209ab751fcVersions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | rust: pin-init: internal: make `__init_data` and `__pin_data` saferust/ rust/ rust/ | +7 | 0 replies | |
| 2/5 | rust: pin-init: internal: remove associated type of `HasInitData`rust/ | +14 | 0 replies | |
| 3/5 | rust: pin-init: internal: use `HasInitData` to provide inference help onlyrust/ rust/ rust/ +1 more | +16 | 0 replies | |
| 4/5 | rust: pin-init: internal: add custom diagnostic when `#[pin_data]` is not implementedrust/ | +4 | 0 replies | |
| 5/5 | rust: pin-init: add diagnostic attribute for `PinInit` and `Init`rust/ | +8 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/5] rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]`
Improve the diagnostics of missing #[pin_data] and #[pin], by adding diagnostics attributes. For #[pin_data], we have to change the expansion to retrieve PinData in a two-step process, so we change the error message from "method exists but trait bound not satisfied" to "trait not implemented".
This is the new error message for missing #[pin_data]:
error[E0277]: `Foo` cannot be used with `pin_init!` macro
--> tests/ui/compile-fail/init/missing_pin_data.rs:9:19
|
9 | pin_init!(Self { a: 42 })
| ^^^^ unsatisfied trait bound
|
help: the trait `pin_init::__internal::HasPinData` is not implemented for `Foo`where it was previously
error[E0599]: no associated function or constant named `__pin_data` found for struct `Foo` in the current scope
--> tests/ui/compile-fail/init/missing_pin_data.rs:9:9
|
3 | struct Foo {
| ---------- associated function or constant `__pin_data` not found for this struct
...
9 | pin_init!(Self { a: 42 })
| ^^^^^^^^^^^^^^^^^^^^^^^^^ associated function or constant not found in `Foo`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `__pin_data`, perhaps you need to implement it:
candidate #1: `pin_init::__internal::HasPinData`and this is the new error message for missing #[pin]:
error[E0277]: impl PinInit<usize> cannot be used to movably initialize usize with error _
--> tests/ui/compile-fail/pin_data/missing_pin.rs:12:18
|
12 | a <- a,
| -----^
| | |
| | the trait Init<usize, _> is not implemented for impl PinInit<usize>
| required by a bound introduced by this call
|
= note: if your type implements PinInit but not Init, you might be forgetting a #[pin] annotation on fields
where it was previously
error[E0277]: the trait bound impl pin_init::PinInit<Bar>: Init<Bar, _> is not satisfied
--> tests/ui/compile-fail/init/invalid_init.rs:19:16
|
19 | bar <- Bar::new(),
| -------^^^^^^^^^^
| | |
| | the trait Init<Bar, _> is not implemented for impl pin_init::PinInit<Bar>
| required by a bound introduced by this call
---
Gary Guo (5):
rust: pin-init: internal: make __init_data and __pin_data safe
rust: pin-init: internal: remove associated type of HasInitData
rust: pin-init: internal: use HasInitData to provide inference help only
rust: pin-init: internal: add custom diagnostic when #[pin_data] is not implemented
rust: pin-init: add diagnostic attribute for PinInit and Init
rust/pin-init/internal/src/init.rs | 25 +++++++++--------- rust/pin-init/internal/src/pin_data.rs | 2 +- rust/pin-init/src/__internal.rs | 48 +++++++++++++++------------------- rust/pin-init/src/lib.rs | 11 +++++++- 4 files changed, 45 insertions(+), 41 deletions(-)
---
base-commit: dfb6a037fd586f1ffcba3b143dab58f5c88294d1
change-id: 20260923-dev-pin-data-diag-65209ab751fc
Best regards,
Signature · 1 line
Gary Guo <[email protected]>