File tree Expand file tree Collapse file tree 6 files changed +19
-11
lines changed
Expand file tree Collapse file tree 6 files changed +19
-11
lines changed Original file line number Diff line number Diff line change 3737 run : |
3838 cargo clippy
3939 cargo fmt --check
40- cd violations_coverage/format_files
40+ cd violations_coverage/in_crate
4141 cargo fmt --check
4242
4343 - name : Doc (stable, nightly)
Original file line number Diff line number Diff line change @@ -167,12 +167,21 @@ macro_rules! unsafe_method {
167167 // without upsetting operator precedence.
168168 {
169169 if false {
170- // We **cannot** take $self by value, in case it's a non-Copy static variable.
171- let rref = & ( $self ) ;
172- let mref = :: prudent:: shared_to_mut( rref) ;
173- let mut owned_receiver = :: core:: mem:: replace( mref, unsafe { :: core:: mem:: zeroed( ) } ) ;
174- let _ = owned_receiver. $fn( $( $arg ) ,* ) ;
175-
170+ if false {
171+ // This block makes an instance/owned value of the same type as $self. The
172+ // purpose is then to invoke the method inside unsafe {...}, BUT without
173+ // evaluating the given $self expression inside that unsafe {...} block, so that
174+ // we isolate/catch any unsafe code in $self.
175+ //
176+ // We **cannot** move/take/assign $self by value, in case it's a non-Copy
177+ // **static** variable.
178+ let rref = & ( $self ) ;
179+ let mref = :: prudent:: shared_to_mut( rref) ;
180+ let mut owned_receiver = :: core:: mem:: replace( mref, unsafe { :: core:: mem:: zeroed( ) } ) ;
181+ let _ = unsafe { owned_receiver. $fn( $( $arg ) ,* ) } ;
182+ } else {
183+ $( let _ = $arg; ) *
184+ }
176185 unreachable!( )
177186 } else {
178187 #[ allow( unsafe_code) ]
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ version = "0.1.0"
44edition = " 2024"
55
66[dependencies ]
7+ prudent = {path = " ../.." , version =" 0.0.3-alpha" }
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ Compilation fails - as intended.
22
33This crate exists to run
44- ` cargo fmt ` , so that symlinked-files get formatted.
5- - ` cargo expand `
5+ - ` cargo expand ` , for example: ` cargo expand --bin unsafe_fn_some_args_arg `
66
77This needs a filesystem that supports symlinks.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ use prudent::unsafe_method;
22
33fn main ( ) {
44 #[ allow( unused_unsafe) ]
5+ // str::len is actually not unsafe, but that doesn't matter for this example
56 let _ = unsafe_method ! ( core:: str :: from_utf8_unchecked( b"hi" ) , len) ;
67}
You can’t perform that action at this time.
0 commit comments