Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bill-myers opened this issue Jun 8, 2013 · 1 comment
Closed

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

bill-myers opened this issue Jun 8, 2013 · 1 comment

Comments

@bill-myers
Copy link
Contributor

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());})
}
bill-myers added a commit to bill-myers/rust that referenced this issue Jun 8, 2013
Owned traits and closures can contain any type, including those that
do not satisfy Const, and thus must not satisfy Const themselves.
bill-myers added a commit to bill-myers/rust that referenced this issue Jun 8, 2013
@emberian
Copy link
Member

triage bump; soon to be closed.

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 8, 2021
clippy_utils: fix needless parenthesis output from sugg::Sugg::maybe_par

changelog: clippy_utils: fix needless parenthesis output from `sugg::Sugg::maybe_par`

fixes: rust-lang#6767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants