mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Rollup merge of #89821 - crlf0710:unsafe_code_lint_test, r=Mark-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 #10599 the original implementation pr.
This commit is contained in:
commit
b74ae0487b
16
src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs
Normal file
16
src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// force-host
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
||||
|
||||
#[proc_macro]
|
||||
pub fn forge_unsafe_block(input: TokenStream) -> TokenStream {
|
||||
let mut output = TokenStream::new();
|
||||
output.extend(Some(TokenTree::from(Ident::new("unsafe", Span::call_site()))));
|
||||
output.extend(Some(TokenTree::from(Group::new(Delimiter::Brace, input))));
|
||||
output
|
||||
}
|
16
src/test/ui/lint/unsafe_code/forge_unsafe_block.rs
Normal file
16
src/test/ui/lint/unsafe_code/forge_unsafe_block.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// check-pass
|
||||
// aux-build:forge_unsafe_block.rs
|
||||
|
||||
#[macro_use]
|
||||
extern crate forge_unsafe_block;
|
||||
|
||||
unsafe fn foo() {}
|
||||
|
||||
#[forbid(unsafe_code)]
|
||||
fn main() {
|
||||
// `forbid` doesn't work for non-user-provided unsafe blocks.
|
||||
// see `UnsafeCode::check_expr`.
|
||||
forge_unsafe_block! {
|
||||
foo();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user