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

Projects
None yet
4 participants
@JohnTitor
Copy link
Contributor

JohnTitor commented Jan 9, 2019

Fixes #56768.

r? @oli-obk

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 9, 2019

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.

@oli-obk
Copy link
Contributor

oli-obk left a comment

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

Show resolved Hide resolved src/librustc_lint/builtin.rs Outdated
@JohnTitor

This comment has been minimized.

Copy link
Contributor

JohnTitor commented Jan 9, 2019

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

@oli-obk

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

JohnTitor commented Jan 9, 2019

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

This comment has been minimized.

Copy link
Contributor

oli-obk commented Jan 9, 2019

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

@JohnTitor

This comment has been minimized.

Copy link
Contributor

JohnTitor commented Jan 9, 2019

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

This comment has been minimized.

Copy link
Contributor

JohnTitor commented Jan 15, 2019

@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?
Show resolved Hide resolved src/librustc_lint/builtin.rs Outdated
Show resolved Hide resolved src/librustc_lint/builtin.rs Outdated
@oli-obk

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

oli-obk commented Jan 15, 2019

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

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 15, 2019

📌 Commit bd1551e has been approved by oli-obk

Centril added a commit to Centril/rust that referenced this pull request Jan 15, 2019

Rollup merge of rust-lang#57467 - JohnTitor:implement-the-check-attri…
…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

Auto merge of #57630 - Centril:rollup, r=Centril
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 JohnTitor:implement-the-check-attribute-1 branch Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment