@@ -128,29 +128,29 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
128
128
let mut cur = fn_like. id ( ) ;
129
129
loop {
130
130
// Go further upwards.
131
- let parent = tcx. hir . get_parent_node ( cur) ;
132
- if cur == parent {
133
- bug ! ( "Closures muts be inside a non-closure fn_like" ) ;
134
- }
135
- cur = parent;
136
- // Check if this is an unsafe block
137
- match tcx. hir . find ( cur) {
138
- Some ( Node :: NodeExpr ( & hir:: Expr { node : hir:: ExprBlock ( ref block) , ..} ) ) => {
139
- if block_is_unsafe ( & * block) {
140
- // Found an unsafe block, we can bail out here.
131
+ cur = tcx. hir . get_parent_node ( cur) ;
132
+ let node = tcx. hir . get ( cur) ;
133
+ // Check if this is an unsafe function
134
+ if let Some ( fn_like) = FnLikeNode :: from_node ( node) {
135
+ if !fn_is_closure ( fn_like) {
136
+ if fn_like. unsafety ( ) == hir:: Unsafety :: Unsafe {
141
137
return true ;
142
138
}
143
139
}
144
- _ => { } ,
145
140
}
146
- // Check if this is a non-closure fn_like, at which point we have to stop moving up
147
- if let Some ( fn_like) = FnLikeNode :: from_node ( tcx. hir . get ( cur) ) {
148
- if !fn_is_closure ( fn_like) {
149
- if fn_like. unsafety ( ) == hir:: Unsafety :: Unsafe {
141
+ // Check if this is an unsafe block, or an item
142
+ match node {
143
+ Node :: NodeExpr ( & hir:: Expr { node : hir:: ExprBlock ( ref block) , ..} ) => {
144
+ if block_is_unsafe ( & * block) {
145
+ // Found an unsafe block, we can bail out here.
150
146
return true ;
151
147
}
148
+ }
149
+ Node :: NodeItem ( ..) => {
150
+ // No walking up beyond items. This makes sure the loop always terminates.
152
151
break ;
153
152
}
153
+ _ => { } ,
154
154
}
155
155
}
156
156
}
0 commit comments