File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ fn walk_unsafe(
8787 let g = resolver. update_to_inner_scope ( db. upcast ( ) , def, current) ;
8888 let value_or_partial = resolver. resolve_path_in_value_ns ( db. upcast ( ) , path) ;
8989 if let Some ( ResolveValueResult :: ValueNs ( ValueNs :: StaticId ( id) , _) ) = value_or_partial {
90- if db. static_data ( id) . mutable {
90+ let static_data = db. static_data ( id) ;
91+ if static_data. mutable || static_data. is_extern {
9192 unsafe_expr_cb ( UnsafeExpr { expr : current, inside_unsafe_block } ) ;
9293 }
9394 }
Original file line number Diff line number Diff line change @@ -163,6 +163,31 @@ fn main() {
163163 ) ;
164164 }
165165
166+ #[ test]
167+ fn missing_unsafe_diagnostic_with_extern_static ( ) {
168+ check_diagnostics (
169+ r#"
170+ //- minicore: copy
171+
172+ extern "C" {
173+ static EXTERN: i32;
174+ static mut EXTERN_MUT: i32;
175+ }
176+
177+ fn main() {
178+ let _x = EXTERN;
179+ //^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block
180+ let _x = EXTERN_MUT;
181+ //^^^^^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block
182+ unsafe {
183+ let _x = EXTERN;
184+ let _x = EXTERN_MUT;
185+ }
186+ }
187+ "# ,
188+ ) ;
189+ }
190+
166191 #[ test]
167192 fn no_missing_unsafe_diagnostic_with_safe_intrinsic ( ) {
168193 check_diagnostics (
You can’t perform that action at this time.
0 commit comments