1
Fork 0

Use Mutability::{is_mut, is_not}

This commit is contained in:
Maybe Waffle 2023-01-30 12:00:11 +00:00
parent fd649a3cc5
commit 4d75f61832
11 changed files with 13 additions and 21 deletions

View file

@ -344,7 +344,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} else { } else {
err.span_help(source_info.span, "try removing `&mut` here"); err.span_help(source_info.span, "try removing `&mut` here");
} }
} else if decl.mutability == Mutability::Not { } else if decl.mutability.is_not() {
if matches!( if matches!(
decl.local_info, decl.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf( Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(

View file

@ -2028,7 +2028,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
}; };
if ty_to_mut == Mutability::Mut && ty_mut == Mutability::Not { if ty_to_mut.is_mut() && ty_mut.is_not() {
span_mirbug!( span_mirbug!(
self, self,
rvalue, rvalue,

View file

@ -304,7 +304,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
.into()); .into());
}; };
if alloc.mutability == Mutability::Not { if alloc.mutability.is_not() {
throw_ub_format!("deallocating immutable allocation {alloc_id:?}"); throw_ub_format!("deallocating immutable allocation {alloc_id:?}");
} }
if alloc_kind != kind { if alloc_kind != kind {
@ -631,7 +631,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} }
let (_kind, alloc) = self.memory.alloc_map.get_mut(id).unwrap(); let (_kind, alloc) = self.memory.alloc_map.get_mut(id).unwrap();
if alloc.mutability == Mutability::Not { if alloc.mutability.is_not() {
throw_ub!(WriteToReadOnly(id)) throw_ub!(WriteToReadOnly(id))
} }
Ok((alloc, &mut self.machine)) Ok((alloc, &mut self.machine))

View file

@ -9,9 +9,7 @@ use rustc_ast_pretty::pp::{self, Breaks};
use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_ast_pretty::pprust::{Comments, PrintState};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::LifetimeParamKind; use rustc_hir::LifetimeParamKind;
use rustc_hir::{ use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term};
BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Mutability, Node, Term,
};
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier}; use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol}; use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
@ -1746,7 +1744,7 @@ impl<'a> State<'a> {
if by_ref == ByRef::Yes { if by_ref == ByRef::Yes {
self.word_nbsp("ref"); self.word_nbsp("ref");
} }
if mutbl == Mutability::Mut { if mutbl.is_mut() {
self.word_nbsp("mut"); self.word_nbsp("mut");
} }
self.print_ident(ident); self.print_ident(ident);

View file

@ -110,7 +110,7 @@ fn write_graph_label<'tcx, W: std::fmt::Write>(
let decl = &body.local_decls[local]; let decl = &body.local_decls[local];
write!(w, "let ")?; write!(w, "let ")?;
if decl.mutability == Mutability::Mut { if decl.mutability.is_mut() {
write!(w, "mut ")?; write!(w, "mut ")?;
} }

View file

@ -416,11 +416,7 @@ impl<'tcx> Body<'tcx> {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| { (self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index); let local = Local::new(index);
let decl = &self.local_decls[local]; let decl = &self.local_decls[local];
if decl.is_user_variable() && decl.mutability == Mutability::Mut { if decl.is_user_variable() && decl.mutability.is_mut() { Some(local) } else { None }
Some(local)
} else {
None
}
}) })
} }

View file

@ -580,7 +580,7 @@ fn write_scope_tree(
continue; continue;
} }
let mut_str = if local_decl.mutability == Mutability::Mut { "mut " } else { "" }; let mut_str = if local_decl.mutability.is_mut() { "mut " } else { "" };
let mut indented_decl = let mut indented_decl =
format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty); format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);

View file

@ -44,7 +44,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr_ty = expr.ty; let expr_ty = expr.ty;
let temp = { let temp = {
let mut local_decl = LocalDecl::new(expr_ty, expr_span); let mut local_decl = LocalDecl::new(expr_ty, expr_span);
if mutability == Mutability::Not { if mutability.is_not() {
local_decl = local_decl.immutable(); local_decl = local_decl.immutable();
} }

View file

@ -5,7 +5,6 @@ use std::cell::Cell;
use either::Right; use either::Right;
use rustc_ast::Mutability;
use rustc_const_eval::const_eval::CheckAlignment; use rustc_const_eval::const_eval::CheckAlignment;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
@ -289,7 +288,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
} }
// If the static allocation is mutable, then we can't const prop it as its content // If the static allocation is mutable, then we can't const prop it as its content
// might be different at runtime. // might be different at runtime.
if alloc.inner().mutability == Mutability::Mut { if alloc.inner().mutability.is_mut() {
throw_machine_stop_str!("can't access mutable globals in ConstProp"); throw_machine_stop_str!("can't access mutable globals in ConstProp");
} }

View file

@ -427,7 +427,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> { fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> {
let span = self.span; let span = self.span;
let mut local = LocalDecl::new(ty, span); let mut local = LocalDecl::new(ty, span);
if mutability == Mutability::Not { if mutability.is_not() {
local = local.immutable(); local = local.immutable();
} }
Place::from(self.local_decls.push(local)) Place::from(self.local_decls.push(local))

View file

@ -29,7 +29,6 @@ use crate::{id_from_def_id, SaveContext};
use rls_data::{SigElement, Signature}; use rls_data::{SigElement, Signature};
use rustc_ast::Mutability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir_pretty::id_to_string; use rustc_hir_pretty::id_to_string;
@ -769,7 +768,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
} }
hir::ForeignItemKind::Static(ref ty, m) => { hir::ForeignItemKind::Static(ref ty, m) => {
let mut text = "static ".to_owned(); let mut text = "static ".to_owned();
if m == Mutability::Mut { if m.is_mut() {
text.push_str("mut "); text.push_str("mut ");
} }
let name = self.ident.to_string(); let name = self.ident.to_string();