@@ -284,10 +284,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
284
284
unsafe_blocks : & [ ( ast:: NodeId , bool ) ] ) {
285
285
let safety = self . source_scope_local_data [ self . source_info . scope ] . safety ;
286
286
let within_unsafe = match ( safety, self . min_const_fn ) {
287
- // FIXME: erring on the safe side here and disallowing builtin unsafety in const fn
287
+ // Erring on the safe side, pun intended
288
288
( Safety :: BuiltinUnsafe , true ) |
289
- // `unsafe` blocks are required even in `const unsafe fn`
290
- ( Safety :: FnUnsafe , true ) |
289
+ // mir building encodes const fn bodies as safe, even for `const unsafe fn`
290
+ ( Safety :: FnUnsafe , true ) => bug ! ( "const unsafe fn body treated as inherently unsafe" ) ,
291
291
// `unsafe` blocks are required in safe code
292
292
( Safety :: Safe , _) => {
293
293
for violation in violations {
@@ -305,8 +305,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
305
305
}
306
306
false
307
307
}
308
+ // regular `unsafe` function bodies allow unsafe without additional unsafe blocks
308
309
( Safety :: BuiltinUnsafe , false ) | ( Safety :: FnUnsafe , false ) => true ,
309
310
( Safety :: ExplicitUnsafe ( node_id) , _) => {
311
+ // mark unsafe block as used if there are any unsafe operations inside
310
312
if !violations. is_empty ( ) {
311
313
self . used_unsafe . insert ( node_id) ;
312
314
}
@@ -316,6 +318,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
316
318
match violation. kind {
317
319
// these are allowed
318
320
UnsafetyViolationKind :: MinConstFn
321
+ // if `#![feature(min_const_unsafe_fn)]` is active
319
322
if self . tcx . sess . features_untracked ( ) . min_const_unsafe_fn => { } ,
320
323
_ => {
321
324
let mut violation = violation. clone ( ) ;
0 commit comments