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

Removing some mutable fields and unsafe blocks #5787

Merged
merged 2 commits into from
Apr 9, 2013

Conversation

alexcrichton
Copy link
Member

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 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 pull request 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 bors closed this Apr 9, 2013
@bors bors merged commit 255193c into rust-lang:incoming Apr 9, 2013
@alexcrichton alexcrichton deleted the less-mut-fields branch April 9, 2013 05:38
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 10, 2023
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 10, 2023
…n, r=flip1995

Add machine applicable suggestion for `needless_lifetimes`

changelog: [`needless_lifetimes`]: Add machine applicable suggestion

Fixes rust-lang#9360

It doesn't make suggestions for async functions as the input lifetime spans are funky there

The examples in rust-lang#5787 and rust-lang#7271 no longer seem to FP this PR aside, I added tests for them rather than disabling the lint entirely for async functions, I don't know if there are further FPs there though

Closes rust-lang#5787
Closes rust-lang#7271
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 this pull request may close these issues.

3 participants