Skip to content

[runtime]: AsRef<C> for Cell<C> violates AsRef contract #1869

@SuperFluffy

Description

@SuperFluffy

The AsRef<C> for Cell<C> and AsMut<C> for Cell<C> impls violate the AsRef contract that these must not fail, see: https://doc.rust-lang.org/std/convert/trait.AsRef.html#relation-to-borrow

In the impls they panic if the cell has the wrong variant:

impl<C> AsRef<C> for Cell<C> {
fn as_ref(&self) -> &C {
match self {
Self::Present(context) => context,
Self::Missing => panic!("{}", MISSING_CONTEXT),
}
}
}
impl<C> AsMut<C> for Cell<C> {
fn as_mut(&mut self) -> &mut C {
match self {
Self::Present(context) => context,
Self::Missing => panic!("{}", MISSING_CONTEXT),
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions