Skip to content

Ephemeral borrow on a RefCell that extracts a Copy struct member in func argument position does not drop the borrow before making the funcall #65086

@lopopolo

Description

@lopopolo

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=be4dfa9fda3dbe2c8ccb42c3785bd658

This code panics and I do not think it should.

use std::cell::RefCell;
use std::rc::Rc;

#[derive(Clone, Copy)]
struct Item(u32);

#[derive(Clone)]
struct Interp(Rc<RefCell<Item>>);

fn func(interp: &Interp, item: u32) {
    interp.0.borrow_mut();
    println!("{}", item);
}

fn main() {
    let interp = Interp(Rc::new(RefCell::new(Item(42))));
    func(&interp.clone(), interp.0.borrow().0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions