Repository navigation
Fix Option<&mut str> implicit arguments - #292
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
[deepseek-v4.1-flash] A mutable
Option<&mut str>#[implicit]argument compiles again. The&strborrowing change made everyOption<&str>read go throughOptionAsRef, which borrows the field shared, but it applied the same field type to the mutable form too, so the generated bound becameHasFieldMut<_, Value = str>and the read calledas_deref_muton a&mut str.Motivation
A
#[cgp_fn]or#[cgp_impl]with#[implicit] nickname: Option<&mut str>failed withE0308,expected &mut Option<_>, found &mut str. The form worked before that change, and the reference documentation describes it as reading anOption<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 selfgetter already uses; the sharedOption<&str>keeps the allocator-freeOptionAsRefread, and a&mut strimplicit is unchanged. The new test pins the expansion and runs the provider against aSomeand aNonefield.Areas needing attention
The fix keeps the mutable option form on an
Option<String>field rather than generalizing it to anyOption<U>whoseUderefs tostr. A general form needs a mutable counterpart toOptionAsRef, and the getter macros use the sameOption<String>read, so the two families agree.