Skip to content

Unsoundness: ~Trait is considered Const, but shouldn't be #7013

Closed
@bill-myers

Description

@bill-myers

It seems that in Rust ~Trait are Const but that seems wrong, because the implementation of Trait can contain non-Const structs, such as those annotated "mutable", like RcMut.

This seems allows to create an RcMut pointing to itself, like this.

extern mod std;
use std::rc::*;

trait Foo
{
    fn set(&mut self, v: RcMut<A>);
}

struct B
{
    v: Option<RcMut<A>>
}

impl Foo for B
{
    fn set(&mut self, v: RcMut<A>)
    {
        self.v = Some(v);
    }
}

struct A
{
    v: ~Foo,
}

fn main()
{
    let a = A {v: ~B{v: None} as ~Foo};
    let v = rc_mut_from_const(a);
    let w = v.clone();
    v.with_mut_borrow(|p| {p.v.set(w.clone());})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions