mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 04:03:11 +00:00
Use Mutability::{is_mut, is_not}
This commit is contained in:
parent
fd649a3cc5
commit
4d75f61832
@ -344,7 +344,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
} else {
|
||||
err.span_help(source_info.span, "try removing `&mut` here");
|
||||
}
|
||||
} else if decl.mutability == Mutability::Not {
|
||||
} else if decl.mutability.is_not() {
|
||||
if matches!(
|
||||
decl.local_info,
|
||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
|
||||
|
@ -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!(
|
||||
self,
|
||||
rvalue,
|
||||
|
@ -304,7 +304,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
.into());
|
||||
};
|
||||
|
||||
if alloc.mutability == Mutability::Not {
|
||||
if alloc.mutability.is_not() {
|
||||
throw_ub_format!("deallocating immutable allocation {alloc_id:?}");
|
||||
}
|
||||
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();
|
||||
if alloc.mutability == Mutability::Not {
|
||||
if alloc.mutability.is_not() {
|
||||
throw_ub!(WriteToReadOnly(id))
|
||||
}
|
||||
Ok((alloc, &mut self.machine))
|
||||
|
@ -9,9 +9,7 @@ use rustc_ast_pretty::pp::{self, Breaks};
|
||||
use rustc_ast_pretty::pprust::{Comments, PrintState};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::LifetimeParamKind;
|
||||
use rustc_hir::{
|
||||
BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Mutability, Node, Term,
|
||||
};
|
||||
use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term};
|
||||
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
|
||||
@ -1746,7 +1744,7 @@ impl<'a> State<'a> {
|
||||
if by_ref == ByRef::Yes {
|
||||
self.word_nbsp("ref");
|
||||
}
|
||||
if mutbl == Mutability::Mut {
|
||||
if mutbl.is_mut() {
|
||||
self.word_nbsp("mut");
|
||||
}
|
||||
self.print_ident(ident);
|
||||
|
@ -110,7 +110,7 @@ fn write_graph_label<'tcx, W: std::fmt::Write>(
|
||||
let decl = &body.local_decls[local];
|
||||
|
||||
write!(w, "let ")?;
|
||||
if decl.mutability == Mutability::Mut {
|
||||
if decl.mutability.is_mut() {
|
||||
write!(w, "mut ")?;
|
||||
}
|
||||
|
||||
|
@ -416,11 +416,7 @@ impl<'tcx> Body<'tcx> {
|
||||
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
|
||||
let local = Local::new(index);
|
||||
let decl = &self.local_decls[local];
|
||||
if decl.is_user_variable() && decl.mutability == Mutability::Mut {
|
||||
Some(local)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if decl.is_user_variable() && decl.mutability.is_mut() { Some(local) } else { None }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ fn write_scope_tree(
|
||||
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 =
|
||||
format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);
|
||||
|
@ -44,7 +44,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let expr_ty = expr.ty;
|
||||
let temp = {
|
||||
let mut local_decl = LocalDecl::new(expr_ty, expr_span);
|
||||
if mutability == Mutability::Not {
|
||||
if mutability.is_not() {
|
||||
local_decl = local_decl.immutable();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ use std::cell::Cell;
|
||||
|
||||
use either::Right;
|
||||
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_const_eval::const_eval::CheckAlignment;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
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
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
||||
fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||
let span = self.span;
|
||||
let mut local = LocalDecl::new(ty, span);
|
||||
if mutability == Mutability::Not {
|
||||
if mutability.is_not() {
|
||||
local = local.immutable();
|
||||
}
|
||||
Place::from(self.local_decls.push(local))
|
||||
|
@ -29,7 +29,6 @@ use crate::{id_from_def_id, SaveContext};
|
||||
|
||||
use rls_data::{SigElement, Signature};
|
||||
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir_pretty::id_to_string;
|
||||
@ -769,7 +768,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
|
||||
}
|
||||
hir::ForeignItemKind::Static(ref ty, m) => {
|
||||
let mut text = "static ".to_owned();
|
||||
if m == Mutability::Mut {
|
||||
if m.is_mut() {
|
||||
text.push_str("mut ");
|
||||
}
|
||||
let name = self.ident.to_string();
|
||||
|
Loading…
Reference in New Issue
Block a user