Fix ref without mut parameter check on methods and associated functions#7633
Fix ref without mut parameter check on methods and associated functions#7633Dnreikronos wants to merge 2 commits into
Conversation
ref without mut incorrectly mapped to RefMutable in new_from_ref_mut, causing ref-only parameters to be treated as mutable (wrong call-site error on free fns, silently accepted on methods). Add RefImmutable variant so ref-only parameters are correctly immutable both at call sites and inside function bodies. Closes FuelLabs#7623
should_pass: ref without mut on free fns, methods, and associated fns accepts immutable arguments and returns correct values. should_fail: ref without mut params are immutable inside body (cannot assign), and ref mut params still reject immutable arguments.
PR SummaryMedium Risk Overview Call-site checking in function application now requires a mutable argument only when the parameter is E2E tests cover accepting immutable args with Reviewed by Cursor Bugbot for commit 280bc77. Bugbot is set up for automated code reviews on this repo. Configure here. |
Description
Fixes #7623.
refwithoutmuton function parameters was incorrectly handled:refalone was mapped toRefMutable, whichis_mutable()treats as mutable.Root cause:
VariableMutability::new_from_ref_mut(is_reference=true, is_mutable=false)returnedRefMutable— treating an immutable reference as mutable.Changes
RefImmutablevariant toVariableMutabilityforrefwithoutmutparametersnew_from_ref_mutto correctly distinguishref mut(RefMutable) fromrefalone (RefImmutable)ref mutparametersRefImmutablevariantBehavior after fix
refparam accepts immutable arg (free fn)refparam accepts immutable arg (method/associated fn)refparam is immutable inside function bodyref mutparam still rejects immutable argChecklist
core/trybuild-testsif needed.Breaking*orNew Featurelabels where relevant.