File tree 2 files changed +27
-1
lines changed
ide-diagnostics/src/handlers 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ fn walk_unsafe(
87
87
let g = resolver. update_to_inner_scope ( db. upcast ( ) , def, current) ;
88
88
let value_or_partial = resolver. resolve_path_in_value_ns ( db. upcast ( ) , path) ;
89
89
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 {
91
92
unsafe_expr_cb ( UnsafeExpr { expr : current, inside_unsafe_block } ) ;
92
93
}
93
94
}
Original file line number Diff line number Diff line change @@ -163,6 +163,31 @@ fn main() {
163
163
) ;
164
164
}
165
165
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
+
166
191
#[ test]
167
192
fn no_missing_unsafe_diagnostic_with_safe_intrinsic ( ) {
168
193
check_diagnostics (
You can’t perform that action at this time.
0 commit comments