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

Implement check_attribute to forbid #[allow_internal_unsafe] #57467

Merged
merged 10 commits into from
Jan 15, 2019

Conversation

JohnTitor
Copy link
Member

Fixes #56768.

r? @oli-obk

@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 @oli-obk (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 Jan 9, 2019
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test if no preexisting test is touched by this change?

src/librustc_lint/builtin.rs Outdated Show resolved Hide resolved
@JohnTitor
Copy link
Member Author

JohnTitor commented Jan 9, 2019

I’m not sure where and how add a test, advise me?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 9, 2019

Tests for diagnostics are added in src/test/ui. Most likely there's already a test. You can find the preexisting test by running ./x.py test src/test/ui --stage 1 --bless and wait for a failing test. If all of them are passing, search for allow_internal_unsafe and create a new test next to the existing tests. The test's body can probably just be the example from the issue.

@JohnTitor
Copy link
Member Author

All of tests were passed. I searched for allow_internal_unsafe, found the test src/test/ui/feature-gates/feature-gate-allow-internal-unsafe-nested-macro.rs. But I added the function in librustc_lint, so I think it may good to add a test in src/test/ui/lint. Which is better, or is there a better way?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 9, 2019

Yes src/test/ui/lin is a good place

@JohnTitor
Copy link
Member Author

OK. I added the test in src/test/ui/lint, it's body is here:

#![forbid(unsafe_code)]
#![feature(allow_internal_unsafe)]

#[allow_internal_unsafe]
macro_rules! evil {
    ($e:expr) => {
        unsafe {
            $e
        }
    }
}

fn main() {
    println!("Hello, world! {}", evil!(*(0 as *const u8)));
}

But I got no stdout and stderr.

stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------

------------------------------------------

thread '[ui] ui\lint\lint-forbid-allow-internal-unsafe.rs' panicked at 'explicit panic', src\tools\compiletest\src\runtest.rs:3245:9


failures:
    [ui] ui\lint\lint-forbid-allow-internal-unsafe.rs

What did I do wrong?

@JohnTitor
Copy link
Member Author

@oli-obk I’ve done all I can. Could you review my code?

  • I don't know how to separate error comment into some lines in the test, so I made the error message short.
  • I changed the files other than builtin.rs, any problem?
    • In lint-unsafe-code.rs, two errors has occurred at the same time, is this bad?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 15, 2019

I don't know how to separate error comment into some lines in the test, so I made the error message short.

You don't need to specify the entire message, just a part of it is enough.

I changed the files other than builtin.rs, any problem?

Nope, lgtm

In lint-unsafe-code.rs, two errors has occurred at the same time, is this bad?

Should be fixed by the None change suggested above

@oli-obk
Copy link
Contributor

oli-obk commented Jan 15, 2019

Wonderful. Thanks for going all the way and making it an EarlyLintPass.

@bors r+

@bors
Copy link
Contributor

bors commented Jan 15, 2019

📌 Commit bd1551e has been approved by oli-obk

@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 Jan 15, 2019
Centril added a commit to Centril/rust that referenced this pull request Jan 15, 2019
…bute-1, r=oli-obk

Implement `check_attribute` to forbid `#[allow_internal_unsafe]`

Fixes rust-lang#56768.

r? @oli-obk
bors added a commit that referenced this pull request Jan 15, 2019
Rollup of 8 pull requests

Successful merges:

 - #56044 (Drop partially bound function parameters in the expected order)
 - #57352 (forbid manually impl'ing one of an object type's marker traits)
 - #57456 (RawVec doesn't always abort on allocation errors)
 - #57467 (Implement `check_attribute` to forbid `#[allow_internal_unsafe]`)
 - #57579 (Add core::iter::once_with())
 - #57587 (Add 'rustc-env:RUST_BACKTRACE=0' to const-pat-ice test)
 - #57608 (Simplify 'product' factorial example)
 - #57614 ([rustdoc] Fix crates filtering box not being filled)

Failed merges:

r? @ghost
@bors bors merged commit bd1551e into rust-lang:master Jan 15, 2019
@JohnTitor JohnTitor deleted the implement-the-check-attribute-1 branch January 15, 2019 16:38
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.

4 participants