Skip to content

Lint against RefCell::borrow/borrow_mut on &mut RefCell #9044

Open
@RalfJung

Description

@RalfJung

What it does

On this code:

use std::cell::RefCell;

pub fn foo(x: &mut RefCell<i32>) {
    *x.borrow_mut() += 1;
}

the lint would suggest to use get_mut() rather than borrow_mut(). (Same for borrow(), of course.)

Lint Name

unnecessary_runtime_borrow

Category

perf

Advantage

  • Removes unnecessary run-time borrow tracking of RefCell

Drawbacks

None that I know if

Example

See above.

Mutex and RwLock also have get_mut functions, so the same kind of lint could be added for them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions