Skip to content

Commit

Permalink
Return references as ref T if T isn't mutable
Browse files Browse the repository at this point in the history
When exposing owned types as mutable (i.e. through an `fn mut` method),
these values are instead exposed as immutable if they are a type
parameter that doesn't allow mutations, instead of returning the raw
type as-is.

This fixes #642.

Changelog: fixed
  • Loading branch information
yorickpeterse committed Nov 14, 2023
1 parent 5dfdd4e commit 3cc6683
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions types/src/lib.rs
Expand Up @@ -3622,7 +3622,7 @@ impl TypeRef {
if pid.is_mutable(db) {
TypeRef::Mut(id)
} else {
self
TypeRef::Ref(id)
}
}
TypeRef::Owned(id) => TypeRef::Mut(id),
Expand Down Expand Up @@ -4981,7 +4981,7 @@ mod tests {
uni(instance(int)).as_mut(&db),
TypeRef::UniMut(instance(int))
);
assert_eq!(owned(rigid(param1)).as_mut(&db), owned(rigid(param1)));
assert_eq!(owned(rigid(param1)).as_mut(&db), immutable(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 3cc6683

Please sign in to comment.