mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Add diagnostic for accessing an extern
static
This commit is contained in:
parent
0ae42bd425
commit
3d21d5e614
2 changed files with 27 additions and 1 deletions
|
@ -87,7 +87,8 @@ fn walk_unsafe(
|
|||
let g = resolver.update_to_inner_scope(db.upcast(), def, current);
|
||||
let value_or_partial = resolver.resolve_path_in_value_ns(db.upcast(), path);
|
||||
if let Some(ResolveValueResult::ValueNs(ValueNs::StaticId(id), _)) = value_or_partial {
|
||||
if db.static_data(id).mutable {
|
||||
let static_data = db.static_data(id);
|
||||
if static_data.mutable || static_data.is_extern {
|
||||
unsafe_expr_cb(UnsafeExpr { expr: current, inside_unsafe_block });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,31 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_unsafe_diagnostic_with_extern_static() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: copy
|
||||
|
||||
extern "C" {
|
||||
static EXTERN: i32;
|
||||
static mut EXTERN_MUT: i32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _x = EXTERN;
|
||||
//^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block
|
||||
let _x = EXTERN_MUT;
|
||||
//^^^^^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block
|
||||
unsafe {
|
||||
let _x = EXTERN;
|
||||
let _x = EXTERN_MUT;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_missing_unsafe_diagnostic_with_safe_intrinsic() {
|
||||
check_diagnostics(
|
||||
|
|
Loading…
Reference in a new issue