File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
compiler/rustc_hir_analysis/src/check Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,25 @@ pub fn maybe_expr_static_mut(tcx: TyCtxt<'_>, expr: hir::Expr<'_>) {
2626 }
2727}
2828
29+ /// Check for shared or mutable references of `static mut` inside statement
30+ pub fn maybe_stmt_static_mut ( tcx : TyCtxt < ' _ > , stmt : hir:: Stmt < ' _ > ) {
31+ if let hir:: StmtKind :: Local ( loc) = stmt. kind
32+ && let hir:: PatKind :: Binding ( ba, _, _, _) = loc. pat . kind
33+ && matches ! ( ba. 0 , rustc_ast:: ByRef :: Yes )
34+ && let Some ( init) = loc. init
35+ && let Some ( var) = is_path_static_mut ( * init)
36+ {
37+ handle_static_mut_ref (
38+ tcx,
39+ init. span ,
40+ var,
41+ loc. span . edition ( ) . at_least_rust_2024 ( ) ,
42+ matches ! ( ba. 1 , Mutability :: Mut ) ,
43+ stmt. hir_id ,
44+ ) ;
45+ }
46+ }
47+
2948fn is_path_static_mut ( expr : hir:: Expr < ' _ > ) -> Option < String > {
3049 if let hir:: ExprKind :: Path ( qpath) = expr. kind
3150 && let hir:: QPath :: Resolved ( _, path) = qpath
You can’t perform that action at this time.
0 commit comments