Remove casting to &mut T for JS casts

I discussed this with @fitzgen awhile back and this sort of casting seems
especially problematic when you have code along the lines of:

    let mut x: HtmlElement = ...;
    {
        let y: &mut JsValue = x.as_ref();
        *y = 3.into();
    }
    x.some_html_element_method();

as that will immediately throw! We didn't have a use case for mutable casting
other than consistency, so this commit removes it for now. We can possibly add
it back in later if motivated, but for now it seems reasonable to try to avoid
these sorts of pitfalls!
This commit is contained in:
Alex Crichton
2018-08-24 20:45:11 -07:00
parent 8ce7465bba
commit 9729efe50e
3 changed files with 1 additions and 75 deletions

View File

@ -370,11 +370,6 @@ impl JsCast for JsValue {
fn instanceof(_val: &JsValue) -> bool { true }
fn unchecked_from_js(val: JsValue) -> Self { val }
fn unchecked_from_js_ref(val: &JsValue) -> &Self { val }
fn unchecked_from_js_mut(val: &mut JsValue) -> &mut Self { val }
}
impl AsMut<JsValue> for JsValue {
fn as_mut(&mut self) -> &mut JsValue { self }
}
impl AsRef<JsValue> for JsValue {