File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -3675,3 +3675,24 @@ pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -
3675
3675
_ => false ,
3676
3676
}
3677
3677
}
3678
+
3679
+ /// Returns `true` if `expr` designates a mutable static, a mutable local binding, or an expression
3680
+ /// that can be owned.
3681
+ pub fn is_mutable ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
3682
+ if let Some ( hir_id) = path_to_local ( expr)
3683
+ && let Node :: Pat ( pat) = cx. tcx . hir_node ( hir_id)
3684
+ {
3685
+ matches ! ( pat. kind, PatKind :: Binding ( BindingMode :: MUT , ..) )
3686
+ } else if let ExprKind :: Path ( p) = & expr. kind
3687
+ && let Some ( mutability) = cx
3688
+ . qpath_res ( p, expr. hir_id )
3689
+ . opt_def_id ( )
3690
+ . and_then ( |id| cx. tcx . static_mutability ( id) )
3691
+ {
3692
+ mutability == Mutability :: Mut
3693
+ } else if let ExprKind :: Field ( parent, _) = expr. kind {
3694
+ is_mutable ( cx, parent)
3695
+ } else {
3696
+ true
3697
+ }
3698
+ }
You can’t perform that action at this time.
0 commit comments