Return shared reference from alloc method
commit85784bf044b4011ad3a367dcc4803c7a24a619ca
authorJake Bailey (Hacklang) <jakebailey@fb.com>
Thu, 4 Jun 2020 17:57:29 +0000 (4 10:57 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 4 Jun 2020 18:11:02 +0000 (4 11:11 -0700)
tree82c71c0b8d85233de0d15d131a3a0d095a75791e
parentb55a9149a888d2262114d370386fa82b144832b2
Return shared reference from alloc method

Summary:
Currently, `DirectDeclSmartConstructors::alloc` returns a `&mut T`, because `bumpalo::Bump::alloc` does. This could be useful in some applications, but it isn't in the direct decl parser--we never mutate a value after allocating it. Furthermore, we occasionally need to use `&*` to convert the mutable reference to a shared one, in situations where rustc does not have sufficient context to infer that the coercion is necessary.

Instead, just do the coercion in the `alloc` function by declaring it as returning a `&T`. If we find a use case where mutability after allocation would be helpful, we could always add an `alloc_mut` method.

Reviewed By: Wilfred

Differential Revision: D21645147

fbshipit-source-id: 35b6cc9dcfefa941ccd17422390253bef6bcb673
hphp/hack/src/decl/direct_decl_smart_constructors.rs