Summary
Field names written as raw identifiers (r#count, r#insert, …) bypass the
collision check that #987 added for the generated Query/Many/One/OptionOne
projection methods. The macro emits the projection method anyway, which then
clashes with the existing wrapper method and produces a duplicate-inherent-method
compile error instead of the intended skip + deprecation warning.
Root cause: both check sites compare field_ident.to_string() against
QUERY_RESERVED_METHODS / MANY_RESERVED_METHODS / ONE_RESERVED_METHODS.
syn::Ident::to_string() retains the leading r# for raw identifiers, so
r#count is compared as "r#count" and never matches "count". Rust then
treats the emitted fn r#count and the existing fn count as the same method.
Affected sites:
crates/toasty-macros/src/model/expand.rs:60 — projection_method_collides
(used by the Query projection-method expansion).
crates/toasty-macros/src/model/expand/relation.rs:336 —
reserved.contains(&field_ident.to_string().as_str()) in
expand_wrapper_projection_methods for Many / One / OptionOne.
Both should strip a leading r# before the comparison.
Reproducer
#[derive(Debug, toasty::Model)]
struct Item {
#[key]
#[auto]
id: i64,
r#count: i64,
}
Expected: macro skips the projection method, emits the #[deprecated] marker;
user gets a compile-time warning pointing at .select(Item::fields().count()).
Actual: macro emits fn r#count(self) -> …, colliding with the wrapper's
existing count method (or, with Query::count_rows since the rename, the
collision is with whichever wrapper still defines count after future
additions). Compile fails with a duplicate-inherent-method error.
Database driver
none — bug is in toasty-macros.
Toasty version
main (current worktree-floofy-plotting-pie tip, ahead of 198b7d6d).
Additional context
Follow-up from review of #987
(#987 (comment)). The PR
introduced the collision-check machinery; this bug exists in that code path
from the start.
Summary
Field names written as raw identifiers (
r#count,r#insert, …) bypass thecollision check that #987 added for the generated
Query/Many/One/OptionOneprojection methods. The macro emits the projection method anyway, which then
clashes with the existing wrapper method and produces a duplicate-inherent-method
compile error instead of the intended skip + deprecation warning.
Root cause: both check sites compare
field_ident.to_string()againstQUERY_RESERVED_METHODS/MANY_RESERVED_METHODS/ONE_RESERVED_METHODS.syn::Ident::to_string()retains the leadingr#for raw identifiers, sor#countis compared as"r#count"and never matches"count". Rust thentreats the emitted
fn r#countand the existingfn countas the same method.Affected sites:
crates/toasty-macros/src/model/expand.rs:60—projection_method_collides(used by the
Queryprojection-method expansion).crates/toasty-macros/src/model/expand/relation.rs:336—reserved.contains(&field_ident.to_string().as_str())inexpand_wrapper_projection_methodsforMany/One/OptionOne.Both should strip a leading
r#before the comparison.Reproducer
Expected: macro skips the projection method, emits the
#[deprecated]marker;user gets a compile-time warning pointing at
.select(Item::fields().count()).Actual: macro emits
fn r#count(self) -> …, colliding with the wrapper'sexisting
countmethod (or, withQuery::count_rowssince the rename, thecollision is with whichever wrapper still defines
countafter futureadditions). Compile fails with a duplicate-inherent-method error.
Database driver
none — bug is in
toasty-macros.Toasty version
main (current
worktree-floofy-plotting-pietip, ahead of198b7d6d).Additional context
Follow-up from review of #987
(#987 (comment)). The PR
introduced the collision-check machinery; this bug exists in that code path
from the start.