Skip to content

Commit ebc24db

Browse files
soareschenclaude
andauthored
AI Updates #7: span the data-derive impls, and catalog the equality-pinned abstract-type error (#260)
* docs(errors): orphan-rule class is now reshaped by cargo-cgp cargo-cgp reshapes the orphan-rule namespace-registration class into a [CGP-E011] message naming the foreign namespace and key. Update the class doc's "How cargo-cgp presents it", "Notes for tooling", raw-diagnostic framing, and backing-fixture paths (usability/ -> acceptable/wiring/orphan/) to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(errors): verbose cascade is now coalesced by cargo-cgp cargo-cgp collapses a check-trait-failure cascade to a single block: it drops the intermediate provider-trait noise and coalesces the checked components that share one root cause into one headline listing every affected consumer trait over a single root-cause tree. Update the class doc's "How cargo-cgp presents it", "Notes for tooling", and backing-fixture entries (usability/ -> acceptable/duplication/) to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(macro): span derive(HasField) impls onto their fields The HasField/HasFieldMut impls generated by `#[derive(HasField)]` carried the macro's `call_site` span on their `impl`/`{ … }` boundary, so any error about one field's impl — a coherence conflict (E0119), or the "but trait `HasField<…>` is implemented for it" near-miss hint in a missing-field check error — underlined the whole `#[derive(HasField)]` instead of the field. Re-span each generated impl onto its field via `override_item_span` (the field identifier for a named field, the whole `syn::Field` for a tuple field), matching the delegate_components!/default_impl technique. Only the boundary tokens move, so interior references stay at call_site and go-to-definition on the field is unaffected. The raw-diagnostic caret is pinned by the cargo-cgp UI fixtures (22 `.rust.stderr` baselines re-blessed there); documents the mechanism in the HasField implementation doc's new Error spans section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(macro): span all data-derive impls onto their source tokens Extend the HasField span fix to every other extensible-data derive: HasFields, FromVariant, ExtractField, BuildField, and the CgpData/ CgpRecord/CgpVariant umbrellas that compose them. Each generated impl carried the derive's `call_site` span on its `impl`/`{ … }` boundary, so any error about it underlined the whole `#[derive(...)]` rather than the field, variant, or type it derives from. Re-span each impl via `override_item_span`, keyed by kind: per-field impls (`UpdateField`, builder `HasField`) onto their field, per-variant impls (`FromVariant`, `ExtractField`) onto their variant, and whole-type impls (`HasFields`/`FromFields`/`ToFields`/…, `HasBuilder`, the `HasExtractor` family, `FinalizeBuild`/`FinalizeExtract`, `PartialData`) onto the struct/enum name. Re-spanning lives in the shared codegen helpers, so every composing entry point inherits it. The `__Partial…` companion types are cloned from user input and keep their own spans. Only the boundary tokens move, so interior references stay at call_site and go-to-definition is unaffected. Documents the mechanism in each affected implementation doc's new Error spans section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(errors): document the equality-pinned abstract-type failure A provider that pins an abstract type with `#[use_type(Trait.{Assoc = Concrete})]` while the context binds it elsewhere fails as an `E0271` projection mismatch rather than the `E0277` the rest of this class produces: the trait half of the bound holds, so only the associated type disagrees. Record it as a sub-case with its own tells — the caret landing on the `#[cgp_type]` attribute that defined the type, the supplied type absent from the message, and the cascade one shared abstract type produces — and note that cargo-cgp now reshapes it into [CGP-E017], naming both types and the wiring entry to change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 34d9ea5 commit ebc24db

25 files changed

Lines changed: 154 additions & 37 deletions

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/finalize_build_impl.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use syn::token::Comma;
44
use syn::{FieldValue, Ident, ItemImpl, ItemStruct, Type};
55

66
use crate::exports::{FinalizeBuild, IsPresent};
7+
use crate::functions::override_item_span;
78
use crate::parse_internal;
89
use crate::types::cgp_data::{field_to_member, field_value_expr, to_generic_args};
910

@@ -49,5 +50,7 @@ pub fn derive_finalize_build_impl(
4950
}
5051
};
5152

52-
Ok(item_impl)
53+
// Key the error span on the struct name the user wrote, not the whole
54+
// derive. See docs/implementation/README.md#spans.
55+
override_item_span(context_ident.span(), &item_impl)
5356
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/has_builder_impl.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use syn::token::Comma;
44
use syn::{FieldValue, Ident, ItemImpl, ItemStruct};
55

66
use crate::exports::{HasBuilder, IsNothing};
7+
use crate::functions::override_item_span;
78
use crate::parse_internal;
89
use crate::types::cgp_data::{field_to_member, field_value_expr, to_generic_args};
910

@@ -44,5 +45,7 @@ pub fn derive_has_builder_impl(
4445
}
4546
};
4647

47-
Ok(item_impl)
48+
// Key the error span on the struct name the user wrote, not the whole
49+
// derive. See docs/implementation/README.md#spans.
50+
override_item_span(context_ident.span(), &item_impl)
4851
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/has_field_impls.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use syn::spanned::Spanned;
12
use syn::{Ident, ItemImpl, ItemStruct};
23

34
use crate::exports::{HasField, IsPresent, MapType};
5+
use crate::functions::override_item_span;
46
use crate::parse_internal;
57
use crate::types::cgp_data::{
68
field_to_member, field_to_tag, index_to_generic_ident, to_generic_args,
@@ -55,7 +57,13 @@ pub fn derive_has_field_impls(
5557
}
5658
};
5759

58-
item_impls.push(item_impl);
60+
// Point an error on this per-field impl at the field the user wrote
61+
// rather than at the whole derive. See docs/implementation/README.md#spans.
62+
let field_span = current_field
63+
.ident
64+
.as_ref()
65+
.map_or_else(|| current_field.span(), |ident| ident.span());
66+
item_impls.push(override_item_span(field_span, &item_impl)?);
5967
}
6068

6169
Ok(item_impls)

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/into_builder_impl.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use syn::token::Comma;
44
use syn::{FieldValue, Ident, ItemImpl, ItemStruct};
55

66
use crate::exports::{IntoBuilder, IsPresent};
7+
use crate::functions::override_item_span;
78
use crate::parse_internal;
89
use crate::types::cgp_data::{field_to_member, field_value_expr, to_generic_args};
910

@@ -47,5 +48,7 @@ pub fn derive_into_builder_impl(
4748
}
4849
};
4950

50-
Ok(item_impl)
51+
// Key the error span on the struct name the user wrote, not the whole
52+
// derive. See docs/implementation/README.md#spans.
53+
override_item_span(context_ident.span(), &item_impl)
5154
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/partial_data.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syn::{Ident, ItemImpl, ItemStruct};
22

33
use crate::exports::{MapType, PartialData};
4+
use crate::functions::override_item_span;
45
use crate::parse_internal;
56
use crate::types::cgp_data::index_to_generic_ident;
67

@@ -32,5 +33,7 @@ pub fn derive_partial_data_impl_from_struct(
3233
}
3334
};
3435

35-
Ok(item_impl)
36+
// Key the error span on the struct name the user wrote, not the whole
37+
// derive. See docs/implementation/README.md#spans.
38+
override_item_span(context_ident.span(), &item_impl)
3639
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_builder/update_field_impls.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use quote::quote;
22
use syn::punctuated::Punctuated;
3+
use syn::spanned::Spanned;
34
use syn::token::Comma;
45
use syn::{FieldValue, GenericArgument, Ident, ItemImpl, ItemStruct, Type};
56

67
use crate::exports::{MapType, UpdateField};
8+
use crate::functions::override_item_span;
79
use crate::parse_internal;
810
use crate::types::cgp_data::{
911
field_to_member, field_to_tag, field_value_expr, index_to_generic_ident, to_generic_args,
@@ -99,7 +101,13 @@ pub fn derive_update_field_impls(
99101
}
100102
};
101103

102-
item_impls.push(item_impl);
104+
// Point an error on this per-field impl at the field the user wrote
105+
// rather than at the whole derive. See docs/implementation/README.md#spans.
106+
let field_span = current_field
107+
.ident
108+
.as_ref()
109+
.map_or_else(|| current_field.span(), |ident| ident.span());
110+
item_impls.push(override_item_span(field_span, &item_impl)?);
103111
}
104112

105113
Ok(item_impls)

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_extractor/extract_field_impls.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syn::{Arm, GenericArgument, Ident, ItemEnum, ItemImpl, Type};
22

33
use crate::exports::{ExtractField, IsPresent, IsVoid, MapType, MapTypeRef};
4+
use crate::functions::override_item_span;
45
use crate::parse_internal;
56
use crate::types::cgp_data::{get_variant_type, index_to_generic_ident, to_generic_args};
67
use crate::types::field::Symbol;
@@ -116,7 +117,12 @@ pub fn derive_extract_field_impls(
116117
}
117118
};
118119

119-
item_impls.push(item_impl);
120+
// Point an error on this per-variant impl at the variant the user wrote
121+
// rather than at the whole derive. See docs/implementation/README.md#spans.
122+
item_impls.push(override_item_span(
123+
current_variant.ident.span(),
124+
&item_impl,
125+
)?);
120126
}
121127

122128
Ok(item_impls)

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_extractor/finalize_extract_impl.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syn::{Ident, ItemEnum, ItemImpl, Type};
22

33
use crate::exports::{FinalizeExtract, IsVoid, MapTypeRef};
4+
use crate::functions::override_item_span;
45
use crate::parse_internal;
56
use crate::types::cgp_data::to_generic_args;
67

@@ -61,5 +62,7 @@ pub fn derive_finalize_extract_impl(
6162
}
6263
};
6364

64-
Ok(item_impl)
65+
// Key the error span on the enum name the user wrote, not the whole derive.
66+
// See docs/implementation/README.md#spans.
67+
override_item_span(context_enum.ident.span(), &item_impl)
6568
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_extractor/has_extractor_impl.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use quote::quote;
22
use syn::{Arm, Ident, ItemEnum, ItemImpl};
33

44
use crate::exports::{HasExtractor, HasExtractorMut, HasExtractorRef, IsMut, IsPresent, IsRef};
5+
use crate::functions::override_item_span;
56
use crate::parse_internal;
67
use crate::types::cgp_data::to_generic_args;
78

@@ -62,7 +63,9 @@ pub fn derive_has_extractor_impl(
6263
}
6364
};
6465

65-
Ok(item_impl)
66+
// Key the error span on the enum name the user wrote, not the whole derive.
67+
// See docs/implementation/README.md#spans.
68+
override_item_span(context_ident.span(), &item_impl)
6669
}
6770

6871
/// Emit the `HasExtractorRef` impl over the borrowed partial enum (`IsRef`). Its
@@ -137,7 +140,9 @@ pub fn derive_has_extractor_ref_impl(
137140
}
138141
};
139142

140-
Ok(item_impl)
143+
// Key the error span on the enum name the user wrote, not the whole derive.
144+
// See docs/implementation/README.md#spans.
145+
override_item_span(context_ident.span(), &item_impl)
141146
}
142147

143148
/// Emit the `HasExtractorMut` impl: the `IsMut` mirror of
@@ -209,5 +214,7 @@ pub fn derive_has_extractor_mut_impl(
209214
}
210215
};
211216

212-
Ok(item_impl)
217+
// Key the error span on the enum name the user wrote, not the whole derive.
218+
// See docs/implementation/README.md#spans.
219+
override_item_span(context_ident.span(), &item_impl)
213220
}

‎crates/macros/cgp-macro-core/src/types/cgp_data/derive_extractor/partial_data.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syn::{Ident, ItemEnum, ItemImpl};
22

33
use crate::exports::{MapType, MapTypeRef, PartialData};
4+
use crate::functions::override_item_span;
45
use crate::parse_internal;
56
use crate::types::cgp_data::index_to_generic_ident;
67

@@ -56,5 +57,7 @@ pub fn derive_partial_data_impl_from_enum(
5657
}
5758
};
5859

59-
Ok(item_impl)
60+
// Key the error span on the enum name the user wrote, not the whole derive.
61+
// See docs/implementation/README.md#spans.
62+
override_item_span(context_ident.span(), &item_impl)
6063
}

0 commit comments

Comments
 (0)