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

add lint for unsafe blocks #10599

Merged
merged 1 commit into from
Nov 22, 2013
Merged

add lint for unsafe blocks #10599

merged 1 commit into from
Nov 22, 2013

Conversation

thestinger
Copy link
Contributor

This is just meant to be for containing usage of unsafe, much like heap_memory.

bors added a commit that referenced this pull request Nov 22, 2013
This is just meant to be for containing usage of `unsafe`, much like `heap_memory`.
@bors bors closed this Nov 22, 2013
@bors bors merged commit a1afe9c into rust-lang:master Nov 22, 2013
fn check_unsafe_block(cx: &Context, e: &ast::Expr) {
match e.node {
// Don't warn about generated blocks, that'll just pollute the output.
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock(ast::UserProvided) => {
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that

macro_rules! foo ( () => { unsafe { *(0 as *int) } } )

fn main() { foo!() }

doesn't get picked up? Maybe we need UserProvided, UserMacroGenerated, CompileMacroGenerated, or something.

@thestinger
Copy link
Contributor Author

@huonw: I'm pretty sure it will let you use an unsafe macro but not define one. I could be wrong, and a test should be added. I agree with the solution you propose though.

@thestinger thestinger deleted the unsafe branch November 22, 2013 09:28
bors added a commit that referenced this pull request Nov 22, 2013
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2021
…ark-Simulacrum

Add a strange test for `unsafe_code` lint.

The current behavior is a little surprising to me. I'm not sure whether people would change it, but at least let me document the current behavior with a test.

I learnt about this from the [totally-speedy-transmute](https://docs.rs/totally-speedy-transmute) crate.

cc rust-lang#10599 the original implementation pr.
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