Skip to content

Remove 'unsafe' workarounds once pure goes away #4568

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
Kimundi opened this issue Jan 21, 2013 · 0 comments
Closed

Remove 'unsafe' workarounds once pure goes away #4568

Kimundi opened this issue Jan 21, 2013 · 0 comments
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@Kimundi
Copy link
Member

Kimundi commented Jan 21, 2013

Right now there are a lot of situations where you have to wrap the body of a function in an unsafe block to make it pure, because some of the functions you're using aren't declared as pure. Those have to be remove if purity goes away or its definition becomes broader.

@Kimundi Kimundi mentioned this issue Mar 15, 2013
bors added a commit that referenced this issue Apr 9, 2013
This removes some of the easier instances of mutable fields where the explicit self can just become `&mut self` along with removing some unsafe blocks which aren't necessary any more now that purity is gone.

Most of #4568 is done, except for [one case](https://github.com/alexcrichton/rust/blob/less-mut-fields/src/libcore/vec.rs#L1754) where it looks like it has to do with it being a `const` vector. Removing the unsafe block yields:

```
/Users/alex/code/rust2/src/libcore/vec.rs:1755:12: 1755:16 error: illegal borrow unless pure: creating immutable alias to const vec content
/Users/alex/code/rust2/src/libcore/vec.rs:1755         for self.each |e| {
                                                           ^~~~
/Users/alex/code/rust2/src/libcore/vec.rs:1757:8: 1757:9 note: impure due to access to impure function
/Users/alex/code/rust2/src/libcore/vec.rs:1757         }
                                                       ^
error: aborting due to previous error
```

I also didn't delve too much into removing mutable fields with `Cell` or `transmute` and friends.
bors added a commit that referenced this issue Apr 15, 2013
Closes #5487, #1913, and #4568

I tracked this by adding all used unsafe blocks/functions to a set on the `tcx` passed around, and then when the lint pass comes around if an unsafe block/function isn't listed in that set, it's unused.

I also removed everything from the compiler that was unused, and up to stage2 is now compiling without any known unused unsafe blocks.

I chose `unused_unsafe` as the name of the lint attribute, but there may be a better name...
@sanxiyn sanxiyn closed this as completed Apr 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

No branches or pull requests

2 participants