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

unused_unsafe: don't label irrelevant fns #48317

Merged
merged 1 commit into from
Feb 24, 2018

Conversation

ExpHP
Copy link
Contributor

@ExpHP ExpHP commented Feb 18, 2018

Fixes #48131

Diagnostic bugfix to remove an errant note. Stops the search for an enclosing unsafe scope at the first safe fn encountered.

pub unsafe fn outer() {
    fn inner() {
        unsafe { /* unnecessary */ }
    }
    
    inner()
}

Before:

warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
1 | pub unsafe fn outer() {
  | --------------------- because it's nested under this `unsafe` fn
2 |     fn inner() {
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default

After:

warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2018
@ExpHP
Copy link
Contributor Author

ExpHP commented Feb 18, 2018

(hm, I wonder if I should have added the test cases to the ui test, rather than this silly thing I have done to check for the absence of a NOTE in compile-fail...)

@michaelwoerister
Copy link
Member

r? @estebank

@estebank
Copy link
Contributor

estebank commented Feb 20, 2018

Can you move the test to ui? I think it'll be easier to maintain going forward. r=me after doing that.

It's fine, @bors r+ rollup.

@bors
Copy link
Contributor

bors commented Feb 20, 2018

📌 Commit 42df8c5 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 20, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018
…ebank

unused_unsafe: don't label irrelevant fns

Fixes rust-lang#48131

Diagnostic bugfix to remove an errant note.  Stops the search for an enclosing unsafe scope at the first safe fn encountered.

```rust
pub unsafe fn outer() {
    fn inner() {
        unsafe { /* unnecessary */ }
    }

    inner()
}
```

**Before:**

```
warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
1 | pub unsafe fn outer() {
  | --------------------- because it's nested under this `unsafe` fn
2 |     fn inner() {
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default
```

**After:**

```
warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default
```
bors added a commit that referenced this pull request Feb 24, 2018
Rollup of 15 pull requests

- Successful merges: #47987, #48056, #48061, #48084, #48143, #48185, #48206, #48208, #48232, #48246, #48258, #48317, #48353, #48356, #48402
- Failed merges:
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018
…ebank

unused_unsafe: don't label irrelevant fns

Fixes rust-lang#48131

Diagnostic bugfix to remove an errant note.  Stops the search for an enclosing unsafe scope at the first safe fn encountered.

```rust
pub unsafe fn outer() {
    fn inner() {
        unsafe { /* unnecessary */ }
    }

    inner()
}
```

**Before:**

```
warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
1 | pub unsafe fn outer() {
  | --------------------- because it's nested under this `unsafe` fn
2 |     fn inner() {
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default
```

**After:**

```
warning: unnecessary `unsafe` block
 --> src/main.rs:3:9
  |
3 |         unsafe { /* unnecessary */ }
  |         ^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default
```
bors added a commit that referenced this pull request Feb 24, 2018
Rollup of 15 pull requests

- Successful merges: #47987, #48056, #48061, #48084, #48143, #48185, #48206, #48208, #48232, #48246, #48258, #48317, #48353, #48356, #48402
- Failed merges:
@bors bors merged commit 42df8c5 into rust-lang:master Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unused_unsafe gives wrong reason
5 participants