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 4 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 now only rejects immutable arguments when the parameter is Declaration pretty-printing includes the new mutability variant. E2E tests cover pass/fail cases. Reviewed by Cursor Bugbot for commit 7f350f4. Bugbot is set up for automated code reviews on this repo. Configure here. |
Description
Fixes #7623.
refwithoutmuton a parameter was checked inconsistently. On a free function it raised a misleading call-site error ("Cannot pass immutable argument to mutable parameter"), and on methods and associated functions it slipped through with no check at all. The cause isVariableMutability::new_from_ref_mut(is_reference=true, is_mutable=false)returningRefMutable, so an immutable reference got treated as mutable and tripped the call-site mutability check.The fix adds a
RefImmutablevariant sorefandref mutare no longer conflated, and narrows the call-site check to fire only forref mutparams. Arefparameter now accepts immutable arguments everywhere while staying immutable inside the function body.ref mutbehavior is unchanged.refparam, immutable arg (free fn)refparam, immutable arg (method / associated fn)refparam in the bodyref mutparam, immutable argChecklist
core/trybuild-testsif needed.Breaking*orNew Featurelabels where relevant.