Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4d75f61

Browse files
committed
Use Mutability::{is_mut, is_not}
1 parent fd649a3 commit 4d75f61

File tree

11 files changed

+13
-21
lines changed

11 files changed

+13
-21
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
344344
} else {
345345
err.span_help(source_info.span, "try removing `&mut` here");
346346
}
347-
} else if decl.mutability == Mutability::Not {
347+
} else if decl.mutability.is_not() {
348348
if matches!(
349349
decl.local_info,
350350
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20282028
}
20292029
};
20302030

2031-
if ty_to_mut == Mutability::Mut && ty_mut == Mutability::Not {
2031+
if ty_to_mut.is_mut() && ty_mut.is_not() {
20322032
span_mirbug!(
20332033
self,
20342034
rvalue,

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
304304
.into());
305305
};
306306

307-
if alloc.mutability == Mutability::Not {
307+
if alloc.mutability.is_not() {
308308
throw_ub_format!("deallocating immutable allocation {alloc_id:?}");
309309
}
310310
if alloc_kind != kind {
@@ -631,7 +631,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
631631
}
632632

633633
let (_kind, alloc) = self.memory.alloc_map.get_mut(id).unwrap();
634-
if alloc.mutability == Mutability::Not {
634+
if alloc.mutability.is_not() {
635635
throw_ub!(WriteToReadOnly(id))
636636
}
637637
Ok((alloc, &mut self.machine))

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use rustc_ast_pretty::pp::{self, Breaks};
99
use rustc_ast_pretty::pprust::{Comments, PrintState};
1010
use rustc_hir as hir;
1111
use rustc_hir::LifetimeParamKind;
12-
use rustc_hir::{
13-
BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Mutability, Node, Term,
14-
};
12+
use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term};
1513
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
1614
use rustc_span::source_map::SourceMap;
1715
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
@@ -1746,7 +1744,7 @@ impl<'a> State<'a> {
17461744
if by_ref == ByRef::Yes {
17471745
self.word_nbsp("ref");
17481746
}
1749-
if mutbl == Mutability::Mut {
1747+
if mutbl.is_mut() {
17501748
self.word_nbsp("mut");
17511749
}
17521750
self.print_ident(ident);

compiler/rustc_middle/src/mir/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn write_graph_label<'tcx, W: std::fmt::Write>(
110110
let decl = &body.local_decls[local];
111111

112112
write!(w, "let ")?;
113-
if decl.mutability == Mutability::Mut {
113+
if decl.mutability.is_mut() {
114114
write!(w, "mut ")?;
115115
}
116116

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,7 @@ impl<'tcx> Body<'tcx> {
416416
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
417417
let local = Local::new(index);
418418
let decl = &self.local_decls[local];
419-
if decl.is_user_variable() && decl.mutability == Mutability::Mut {
420-
Some(local)
421-
} else {
422-
None
423-
}
419+
if decl.is_user_variable() && decl.mutability.is_mut() { Some(local) } else { None }
424420
})
425421
}
426422

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ fn write_scope_tree(
580580
continue;
581581
}
582582

583-
let mut_str = if local_decl.mutability == Mutability::Mut { "mut " } else { "" };
583+
let mut_str = if local_decl.mutability.is_mut() { "mut " } else { "" };
584584

585585
let mut indented_decl =
586586
format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);

compiler/rustc_mir_build/src/build/expr/as_temp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4444
let expr_ty = expr.ty;
4545
let temp = {
4646
let mut local_decl = LocalDecl::new(expr_ty, expr_span);
47-
if mutability == Mutability::Not {
47+
if mutability.is_not() {
4848
local_decl = local_decl.immutable();
4949
}
5050

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::cell::Cell;
55

66
use either::Right;
77

8-
use rustc_ast::Mutability;
98
use rustc_const_eval::const_eval::CheckAlignment;
109
use rustc_data_structures::fx::FxHashSet;
1110
use rustc_hir::def::DefKind;
@@ -289,7 +288,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
289288
}
290289
// If the static allocation is mutable, then we can't const prop it as its content
291290
// might be different at runtime.
292-
if alloc.inner().mutability == Mutability::Mut {
291+
if alloc.inner().mutability.is_mut() {
293292
throw_machine_stop_str!("can't access mutable globals in ConstProp");
294293
}
295294

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
427427
fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> {
428428
let span = self.span;
429429
let mut local = LocalDecl::new(ty, span);
430-
if mutability == Mutability::Not {
430+
if mutability.is_not() {
431431
local = local.immutable();
432432
}
433433
Place::from(self.local_decls.push(local))

compiler/rustc_save_analysis/src/sig.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::{id_from_def_id, SaveContext};
2929

3030
use rls_data::{SigElement, Signature};
3131

32-
use rustc_ast::Mutability;
3332
use rustc_hir as hir;
3433
use rustc_hir::def::{DefKind, Res};
3534
use rustc_hir_pretty::id_to_string;
@@ -769,7 +768,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
769768
}
770769
hir::ForeignItemKind::Static(ref ty, m) => {
771770
let mut text = "static ".to_owned();
772-
if m == Mutability::Mut {
771+
if m.is_mut() {
773772
text.push_str("mut ");
774773
}
775774
let name = self.ident.to_string();

0 commit comments

Comments
 (0)