Skip to content

Usage of unsafe methods in safe code doesn't cause an error. #6641

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

Closed
brendanzab opened this issue May 20, 2013 · 1 comment
Closed

Usage of unsafe methods in safe code doesn't cause an error. #6641

brendanzab opened this issue May 20, 2013 · 1 comment

Comments

@brendanzab
Copy link
Member

This complies ok:

struct A(int);

impl A {
    unsafe fn a(&self) -> int { **self }
}

trait B {
    unsafe fn b(&self) -> int;
}

impl B for A {
    unsafe fn b(&self) -> int { **self }
}

fn main() {
    let _ = A(1).a();
    let _ = A(1).b();

    unsafe {
        let _ = A(1).a();
        let _ = A(1).b();
    }
}

With this warning:

unsafe-methods.rs:19:4: 22:5 warning: unnecessary `unsafe` block [-W unused-unsafe (default)]
unsafe-methods.rs:19     unsafe {
unsafe-methods.rs:20         let _ = A(1).a();
unsafe-methods.rs:21         let _ = A(1).b();
unsafe-methods.rs:22     }

Yikes.

@brendanzab
Copy link
Member Author

Woops, this is a duplicate of #3080

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

No branches or pull requests

1 participant