Skip to content

Commit

Permalink
Fix mutable references to owned parameters
Browse files Browse the repository at this point in the history
The method TypeRef::as_mut() wasn't updated to account for owned types
now always truly meaning owned types (and thus allowing mutable
references).

Changelog: fixed
  • Loading branch information
yorickpeterse committed Dec 14, 2023
1 parent 0ec0b53 commit ff8c0f2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions types/src/lib.rs
Expand Up @@ -3724,11 +3724,7 @@ impl TypeRef {

pub fn as_mut(self, db: &Database) -> Self {
match self {
TypeRef::Owned(
id @ TypeId::RigidTypeParameter(pid)
| id @ TypeId::TypeParameter(pid),
)
| TypeRef::Any(
TypeRef::Any(
id @ TypeId::RigidTypeParameter(pid)
| id @ TypeId::TypeParameter(pid),
) => {
Expand Down Expand Up @@ -5258,7 +5254,14 @@ mod tests {
uni(instance(int)).as_mut(&db),
TypeRef::UniMut(instance(int))
);
assert_eq!(owned(rigid(param1)).as_mut(&db), immutable(rigid(param1)));

assert_eq!(any(rigid(param1)).as_mut(&db), immutable(rigid(param1)));
assert_eq!(
owned(parameter(param1)).as_mut(&db),
mutable(parameter(param1))
);

assert_eq!(owned(rigid(param1)).as_mut(&db), mutable(rigid(param1)));
assert_eq!(owned(rigid(param2)).as_mut(&db), mutable(rigid(param2)));
assert_eq!(
owned(parameter(param2)).as_mut(&db),
Expand Down

0 comments on commit ff8c0f2

Please sign in to comment.