Skip to content

Calling .pop() on an Attribute node causes BorrowMutError panic #100

@mickdekkers

Description

@mickdekkers

Hey, I noticed that the .pop() method appears to be broken for Attribute nodes. It causes a BorrowMutError panic when called.

Example code:

use std::rc::Rc;

use xrust::item::Node;
use xrust::parser::xml::parse as xmlparse;
use xrust::trees::smite::Node as SmiteNode;

fn main() {
    let input = r"<doc foo='bar'/>";

    let root = xmlparse(Rc::new(SmiteNode::new()), input, None).unwrap();
    let elem = root.first_child().unwrap();
    let mut foo_attr = elem.attribute_iter().next().unwrap();
    // Panics with BorrowMutError
    foo_attr.pop().unwrap();
}

Panics when run with cargo run:

thread 'main' panicked at /home/mick/.cargo/git/checkouts/xrust-bdc2299a4e8ad91c/127ee22/src/trees/smite.rs:849:59:
already borrowed: BorrowMutError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Can run with core/debug_refcell feature (adjust target triple to match your host):

cargo +nightly run --target x86_64-unknown-linux-gnu -Zbuild-std -Zbuild-std-features=core/debug_refcell

To display additional info about the panic:

thread 'main' panicked at /home/mick/.cargo/git/checkouts/xrust-bdc2299a4e8ad91c/127ee22/src/trees/smite.rs:849:59:
already borrowed: BorrowMutError { location: Location { file: "/home/mick/.cargo/git/checkouts/xrust-bdc2299a4e8ad91c/127ee22/src/trees/smite.rs", line: 426, col: 45 } }

The line numbers are a bit shifted for me, but it refers to these two lines:

match Weak::upgrade(&parent.borrow()) {

| NodeInner::ProcessingInstruction(p, _, _) => *p.borrow_mut() = Rc::downgrade(&b),

Tested with latest dev branch commit (2449e4d)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions