Skip to content

Fix Option<&mut str> implicit arguments - #292

Merged
soareschen merged 1 commit into
mainfrom
fix-mut-option-str-implicit
Nov 8, 2026
Merged

soareschen merged 1 commit into
mainfrom
fix-mut-option-str-implicit

Conversation

@soareschen

Copy link
Copy Markdown
Collaborator

Overview

[deepseek-v4.1-flash] A mutable Option<&mut str> #[implicit] argument compiles again. The &str borrowing change made every Option<&str> read go through OptionAsRef, which borrows the field shared, but it applied the same field type to the mutable form too, so the generated bound became HasFieldMut<_, Value = str> and the read called as_deref_mut on a &mut str.

Motivation

A #[cgp_fn] or #[cgp_impl] with #[implicit] nickname: Option<&mut str> failed with E0308, expected &mut Option<_>, found &mut str. The form worked before that change, and the reference documentation describes it as reading an Option<String> field with .as_deref_mut().

Impact

A mutable read keeps the Option<String> field and reads it with .as_deref_mut(), which is the read a &mut self getter already uses; the shared Option<&str> keeps the allocator-free OptionAsRef read, and a &mut str implicit is unchanged. The new test pins the expansion and runs the provider against a Some and a None field.

Areas needing attention

The fix keeps the mutable option form on an Option<String> field rather than generalizing it to any Option<U> whose U derefs to str. A general form needs a mutable counterpart to OptionAsRef, and the getter macros use the same Option<String> read, so the two families agree.

A mutable `Option<&mut str>` implicit argument failed to compile after
the `&str` borrowing change. That change made every `Option<&str>` read
go through `OptionAsRef`, which borrows the field shared, but it also
applied to the mutable form, so the generated bound became
`HasFieldMut<_, Value = str>` and the read called `as_deref_mut` on a
`&mut str`.

A mutable read now keeps the `Option<String>` field and reads it with
`as_deref_mut`, which is the read a `&mut self` getter already used.
The shared `Option<&str>` keeps the allocator-free `OptionAsRef` read.

The new test pins the expansion and runs the provider against a
`Some` and a `None` field.
@soareschen
soareschen marked this pull request as ready for review November 8, 2026 11:03
@soareschen
soareschen merged commit 3a23519 into main Nov 8, 2026
6 checks passed
@soareschen
soareschen deleted the fix-mut-option-str-implicit branch November 8, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant