1. ast::Mutability::{Mutable -> Mut, Immutable -> Not}.

2. mir::Mutability -> ast::Mutability.
This commit is contained in:
Mazdak Farrokhzad 2019-12-16 17:28:40 +01:00
parent 01a46509a4
commit a7aec3f207
91 changed files with 292 additions and 319 deletions

View File

@ -2254,7 +2254,7 @@ impl<'a> LoweringContext<'a> {
let is_mutable_pat = match arg.pat.kind {
PatKind::Ident(BindingMode::ByValue(mt), _, _) |
PatKind::Ident(BindingMode::ByRef(mt), _, _) =>
mt == Mutability::Mutable,
mt == Mutability::Mut,
_ => false,
};
@ -2265,7 +2265,7 @@ impl<'a> LoweringContext<'a> {
// the case where we have a mutable pattern to a reference as that would
// no longer be an `ImplicitSelf`.
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() &&
mt.mutbl == ast::Mutability::Mutable =>
mt.mutbl == ast::Mutability::Mut =>
hir::ImplicitSelfKind::MutRef,
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() =>
hir::ImplicitSelfKind::ImmRef,
@ -3069,10 +3069,10 @@ impl<'a> LoweringContext<'a> {
fn lower_binding_mode(&mut self, b: &BindingMode) -> hir::BindingAnnotation {
match *b {
BindingMode::ByValue(Mutability::Immutable) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Immutable) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mutable) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mutable) => hir::BindingAnnotation::RefMut,
BindingMode::ByValue(Mutability::Not) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Not) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mut) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mut) => hir::BindingAnnotation::RefMut,
}
}

View File

@ -1341,7 +1341,7 @@ impl LoweringContext<'_> {
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
self.expr(
span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, e),
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
ThinVec::new(),
)
}

View File

@ -169,11 +169,10 @@ impl hir::Pat {
self.each_binding(|annotation, _, _, _| {
match annotation {
hir::BindingAnnotation::Ref => match result {
None | Some(hir::Mutability::Immutable) =>
result = Some(hir::Mutability::Immutable),
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
_ => {}
}
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
_ => {}
}
});

View File

@ -386,7 +386,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
@ -502,7 +502,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Static(ref ty, m, expr) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
@ -1632,11 +1632,11 @@ impl<'a> State<'a> {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Immutable, false);
self.print_mutability(hir::Mutability::Not, false);
}
hir::BindingAnnotation::RefMut => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Mutable, false);
self.print_mutability(hir::Mutability::Mut, false);
}
hir::BindingAnnotation::Unannotated => {}
hir::BindingAnnotation::Mutable => {
@ -2065,8 +2065,8 @@ impl<'a> State<'a> {
pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
match mutbl {
hir::Mutability::Mutable => self.word_nbsp("mut"),
hir::Mutability::Immutable => if print_const { self.word_nbsp("const") },
hir::Mutability::Mut => self.word_nbsp("mut"),
hir::Mutability::Not => if print_const { self.word_nbsp("const") },
}
}

View File

@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
}
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => {
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) {
if cx.tcx.impl_trait_ref(impl_did).is_some() {
return;

View File

@ -106,7 +106,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, true),
size,
align,
mutability: Mutability::Immutable,
mutability: Mutability::Not,
extra: (),
}
}
@ -123,7 +123,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, false),
size,
align,
mutability: Mutability::Mutable,
mutability: Mutability::Mut,
extra: (),
}
}

View File

@ -34,6 +34,7 @@ use std::ops::Index;
use std::slice;
use std::{iter, mem, option, u32};
use syntax::ast::Name;
pub use syntax::ast::Mutability;
use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};
@ -396,22 +397,7 @@ pub struct SourceInfo {
}
///////////////////////////////////////////////////////////////////////////
// Mutability and borrow kinds
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
pub enum Mutability {
Mut,
Not,
}
impl From<Mutability> for hir::Mutability {
fn from(m: Mutability) -> Self {
match m {
Mutability::Mut => hir::Mutability::Mutable,
Mutability::Not => hir::Mutability::Immutable,
}
}
}
// Borrow kinds
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, HashStable,
@ -2886,7 +2872,6 @@ pub enum ClosureOutlivesSubject<'tcx> {
CloneTypeFoldableAndLiftImpls! {
BlockTailInfo,
MirPhase,
Mutability,
SourceInfo,
FakeReadCause,
RetagKind,

View File

@ -279,17 +279,17 @@ impl<'tcx> BinOp {
impl BorrowKind {
pub fn to_mutbl_lossy(self) -> hir::Mutability {
match self {
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
BorrowKind::Shared => hir::Mutability::Immutable,
BorrowKind::Mut { .. } => hir::Mutability::Mut,
BorrowKind::Shared => hir::Mutability::Not,
// We have no type corresponding to a unique imm borrow, so
// use `&mut`. It gives all the capabilities of an `&uniq`
// and hence is a safe "over approximation".
BorrowKind::Unique => hir::Mutability::Mutable,
BorrowKind::Unique => hir::Mutability::Mut,
// We have no type corresponding to a shallow borrow, so use
// `&` as an approximation.
BorrowKind::Shallow => hir::Mutability::Immutable,
BorrowKind::Shallow => hir::Mutability::Not,
}
}
}

View File

@ -1548,8 +1548,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
let trait_type = match mutability {
hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
};
let new_obligation = self.mk_obligation_for_def_id(
@ -1565,7 +1565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let sp = self.tcx.sess.source_map()
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
if points_at_arg &&
mutability == hir::Mutability::Immutable &&
mutability == hir::Mutability::Not &&
refs_number > 0
{
err.span_suggestion(

View File

@ -2622,7 +2622,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Char
| ty::RawPtr(..)
| ty::Never
| ty::Ref(_, _, hir::Mutability::Immutable) => {
| ty::Ref(_, _, hir::Mutability::Not) => {
// Implementations provided in libcore
None
}
@ -2633,7 +2633,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::Foreign(..)
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
| ty::Ref(_, _, hir::Mutability::Mut) => None,
ty::Array(element_ty, _) => {
// (*) binder moved here

View File

@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
impl<'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
hir::Mutability::Not => tcx.lang_items().deref_trait(),
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait()
};
let method_def_id = tcx.associated_items(trait_def_id.unwrap())
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
@ -138,15 +138,15 @@ pub enum AllowTwoPhase {
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum AutoBorrowMutability {
Mutable { allow_two_phase_borrow: AllowTwoPhase },
Immutable,
Mut { allow_two_phase_borrow: AllowTwoPhase },
Not,
}
impl From<AutoBorrowMutability> for hir::Mutability {
fn from(m: AutoBorrowMutability) -> Self {
match m {
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
AutoBorrowMutability::Mut { .. } => hir::Mutability::Mut,
AutoBorrowMutability::Not => hir::Mutability::Not,
}
}
}

View File

@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
impl BindingMode {
pub fn convert(ba: BindingAnnotation) -> BindingMode {
match ba {
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
Mutable => BindingMode::BindByValue(Mutability::Mutable),
Ref => BindingMode::BindByReference(Mutability::Immutable),
RefMut => BindingMode::BindByReference(Mutability::Mutable),
Unannotated => BindingMode::BindByValue(Mutability::Not),
Mutable => BindingMode::BindByValue(Mutability::Mut),
Ref => BindingMode::BindByReference(Mutability::Not),
RefMut => BindingMode::BindByReference(Mutability::Mut),
}
}
}

View File

@ -2406,22 +2406,22 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
}
#[inline]
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
}
#[inline]
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
}
#[inline]
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
}
#[inline]

View File

@ -248,7 +248,7 @@ impl<'tcx> ty::TyS<'tcx> {
format!("`&{}`", tymut_string).into()
} else { // Unknown type name, it's long or has type arguments
match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference",
}.into()
}
@ -293,7 +293,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Slice(_) => "slice".into(),
ty::RawPtr(_) => "raw pointer".into(),
ty::Ref(.., mutbl) => match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference"
}.into(),
ty::FnDef(..) => "fn item".into(),

View File

@ -2221,12 +2221,12 @@ where
let tcx = cx.tcx();
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
let kind = match mt {
hir::Mutability::Immutable => if is_freeze {
hir::Mutability::Not => if is_freeze {
PointerKind::Frozen
} else {
PointerKind::Shared
},
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
// Previously we would only emit noalias annotations for LLVM >= 6 or in
// panic=abort mode. That was deemed right, as prior versions had many bugs
// in conjunction with unwinding, but later versions didnt seem to have

View File

@ -2657,8 +2657,8 @@ impl<'tcx> TyS<'tcx> {
impl BorrowKind {
pub fn from_mutbl(m: hir::Mutability) -> BorrowKind {
match m {
hir::Mutability::Mutable => MutBorrow,
hir::Mutability::Immutable => ImmBorrow,
hir::Mutability::Mut => MutBorrow,
hir::Mutability::Not => ImmBorrow,
}
}
@ -2668,13 +2668,13 @@ impl BorrowKind {
/// question.
pub fn to_mutbl_lossy(self) -> hir::Mutability {
match self {
MutBorrow => hir::Mutability::Mutable,
ImmBorrow => hir::Mutability::Immutable,
MutBorrow => hir::Mutability::Mut,
ImmBorrow => hir::Mutability::Not,
// We have no type corresponding to a unique imm borrow, so
// use `&mut`. It gives all the capabilities of an `&uniq`
// and hence is a safe "over approximation".
UniqueImmBorrow => hir::Mutability::Mutable,
UniqueImmBorrow => hir::Mutability::Mut,
}
}

View File

@ -59,8 +59,8 @@ impl DefPathBasedNames<'tcx> {
ty::RawPtr(ty::TypeAndMut { ty: inner_type, mutbl }) => {
output.push('*');
match mutbl {
hir::Mutability::Immutable => output.push_str("const "),
hir::Mutability::Mutable => output.push_str("mut "),
hir::Mutability::Not => output.push_str("const "),
hir::Mutability::Mut => output.push_str("mut "),
}
self.push_type_name(inner_type, output, debug);

View File

@ -490,8 +490,8 @@ pub trait PrettyPrinter<'tcx>:
ty::Float(t) => p!(write("{}", t.name_str())),
ty::RawPtr(ref tm) => {
p!(write("*{} ", match tm.mutbl {
hir::Mutability::Mutable => "mut",
hir::Mutability::Immutable => "const",
hir::Mutability::Mut => "mut",
hir::Mutability::Not => "const",
}));
p!(print(tm.ty))
}

View File

@ -121,8 +121,8 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
} else {
let mutbl = a.mutbl;
let variance = match mutbl {
ast::Mutability::Immutable => ty::Covariant,
ast::Mutability::Mutable => ty::Invariant,
ast::Mutability::Not => ty::Covariant,
ast::Mutability::Mut => ty::Invariant,
};
let ty = relation.relate_with_variance(variance, &a.ty, &b.ty)?;
Ok(ty::TypeAndMut { ty, mutbl })

View File

@ -1853,8 +1853,8 @@ impl<'tcx> TyS<'tcx> {
#[inline]
pub fn is_mutable_ptr(&self) -> bool {
match self.kind {
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mutable, .. }) |
Ref(_, _, hir::Mutability::Mutable) => true,
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mut, .. }) |
Ref(_, _, hir::Mutability::Mut) => true,
_ => false
}
}
@ -2044,7 +2044,7 @@ impl<'tcx> TyS<'tcx> {
Adt(def, _) if def.is_box() => {
Some(TypeAndMut {
ty: self.boxed_ty(),
mutbl: hir::Mutability::Immutable,
mutbl: hir::Mutability::Not,
})
},
Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl }),

View File

@ -183,7 +183,7 @@ impl<'tcx> ty::ParamEnv<'tcx> {
// Now libcore provides that impl.
ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Float(_) |
ty::Char | ty::RawPtr(..) | ty::Never |
ty::Ref(_, _, hir::Mutability::Immutable) => return Ok(()),
ty::Ref(_, _, hir::Mutability::Not) => return Ok(()),
ty::Adt(adt, substs) => (adt, substs),
@ -679,7 +679,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
pub fn is_mutable_static(&self, def_id: DefId) -> bool {
self.static_mutability(def_id) == Some(hir::Mutability::Mutable)
self.static_mutability(def_id) == Some(hir::Mutability::Mut)
}
/// Get the type of the pointer to the static that we use in MIR.

View File

@ -277,7 +277,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let base_addr = match alloc_kind {
Some(GlobalAlloc::Memory(alloc)) => {
let init = const_alloc_to_llvm(self, alloc);
if alloc.mutability == Mutability::Mutable {
if alloc.mutability == Mutability::Mut {
self.static_addr_of_mut(init, alloc.align, None)
} else {
self.static_addr_of(init, alloc.align, None)

View File

@ -1582,7 +1582,7 @@ fn generic_simd_intrinsic(
// The second argument must be a simd vector with an element type that's a pointer
// to the element type of the first argument
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind {
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mutable
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut
=> (ptr_count(arg_tys[1].simd_type(tcx)),
non_ptr(arg_tys[1].simd_type(tcx))),
_ => {

View File

@ -62,8 +62,8 @@ pub fn push_debuginfo_type_name<'tcx>(
output.push('*');
}
match mutbl {
hir::Mutability::Immutable => output.push_str("const "),
hir::Mutability::Mutable => output.push_str("mut "),
hir::Mutability::Not => output.push_str("const "),
hir::Mutability::Mut => output.push_str("mut "),
}
push_debuginfo_type_name(tcx, inner_type, true, output, visited);

View File

@ -373,8 +373,8 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
ty::Ref(r, ty, mutbl) => {
self.push(match mutbl {
hir::Mutability::Immutable => "R",
hir::Mutability::Mutable => "Q",
hir::Mutability::Not => "R",
hir::Mutability::Mut => "Q",
});
if *r != ty::ReErased {
self = r.print(self)?;
@ -384,8 +384,8 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
ty::RawPtr(mt) => {
self.push(match mt.mutbl {
hir::Mutability::Immutable => "P",
hir::Mutability::Mutable => "O",
hir::Mutability::Not => "P",
hir::Mutability::Mut => "O",
});
self = mt.ty.print(self)?;
}

View File

@ -887,8 +887,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
consider instead using an UnsafeCell";
match get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (&ty1.kind, &ty2.kind)) {
Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) => {
if to_mt == hir::Mutability::Mutable &&
from_mt == hir::Mutability::Immutable {
if to_mt == hir::Mutability::Mut &&
from_mt == hir::Mutability::Not {
cx.span_lint(MUTABLE_TRANSMUTES, expr.span, msg);
}
}

View File

@ -392,7 +392,7 @@ impl UnusedParens {
avoid_or: bool,
avoid_mut: bool,
) {
use ast::{PatKind, BindingMode::ByValue, Mutability::Mutable};
use ast::{PatKind, BindingMode::ByValue, Mutability::Mut};
if let PatKind::Paren(inner) = &value.kind {
match inner.kind {
@ -404,7 +404,7 @@ impl UnusedParens {
// Avoid `p0 | .. | pn` if we should.
PatKind::Or(..) if avoid_or => return,
// Avoid `mut x` and `mut x @ p` if we should:
PatKind::Ident(ByValue(Mutable), ..) if avoid_mut => return,
PatKind::Ident(ByValue(Mut), ..) if avoid_mut => return,
// Otherwise proceed with linting.
_ => {}
}
@ -560,7 +560,7 @@ impl EarlyLintPass for UnusedParens {
Ident(.., Some(p)) | Box(p) => self.check_unused_parens_pat(cx, p, true, false),
// Avoid linting on `&(mut x)` as `&mut x` has a different meaning, #55342.
// Also avoid linting on `& mut? (p0 | .. | pn)`, #64106.
Ref(p, m) => self.check_unused_parens_pat(cx, p, true, *m == Mutability::Immutable),
Ref(p, m) => self.check_unused_parens_pat(cx, p, true, *m == Mutability::Not),
}
}
@ -668,9 +668,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation {
for adj in cx.tables.expr_adjustments(e) {
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
let msg = match m {
adjustment::AutoBorrowMutability::Immutable =>
adjustment::AutoBorrowMutability::Not =>
"unnecessary allocation, use `&` instead",
adjustment::AutoBorrowMutability::Mutable { .. }=>
adjustment::AutoBorrowMutability::Mut { .. }=>
"unnecessary allocation, use `&mut` instead"
};
cx.span_lint(UNUSED_ALLOCATION, e.span, msg);

View File

@ -1401,9 +1401,9 @@ impl<'a, 'tcx> CrateMetadata {
fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> {
match self.kind(id) {
EntryKind::ImmStatic |
EntryKind::ForeignImmStatic => Some(hir::Mutability::Immutable),
EntryKind::ForeignImmStatic => Some(hir::Mutability::Not),
EntryKind::MutStatic |
EntryKind::ForeignMutStatic => Some(hir::Mutability::Mutable),
EntryKind::ForeignMutStatic => Some(hir::Mutability::Mut),
_ => None,
}
}

View File

@ -1054,8 +1054,8 @@ impl EncodeContext<'tcx> {
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
record!(self.per_def.kind[def_id] <- match item.kind {
hir::ItemKind::Static(_, hir::Mutability::Mutable, _) => EntryKind::MutStatic,
hir::ItemKind::Static(_, hir::Mutability::Immutable, _) => EntryKind::ImmStatic,
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
hir::ItemKind::Const(_, body_id) => {
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
EntryKind::Const(
@ -1544,10 +1544,8 @@ impl EncodeContext<'tcx> {
};
EntryKind::ForeignFn(self.lazy(data))
}
hir::ForeignItemKind::Static(_, hir::Mutability::Mutable) =>
EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, hir::Mutability::Immutable) =>
EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Type => EntryKind::ForeignType,
});
record!(self.per_def.visibility[def_id] <-

View File

@ -261,7 +261,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// we have an explicit self. Do the same thing in this case and check
// for a `self: &mut Self` to suggest removing the `&mut`.
if let ty::Ref(
_, _, hir::Mutability::Mutable
_, _, hir::Mutability::Mut
) = local_decl.ty.kind {
true
} else {
@ -578,7 +578,7 @@ fn suggest_ampmut<'tcx>(
}
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
assert_eq!(ty_mut.mutbl, hir::Mutability::Immutable);
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
(highlight_span,
if local_decl.ty.is_region_ptr() {
format!("&mut {}", ty_mut.ty)
@ -614,7 +614,7 @@ fn annotate_struct_field(
// we can expect a field that is an immutable reference to a type.
if let hir::Node::Field(field) = node {
if let hir::TyKind::Rptr(lifetime, hir::MutTy {
mutbl: hir::Mutability::Immutable,
mutbl: hir::Mutability::Not,
ref ty
}) = field.ty.kind {
// Get the snippets in two parts - the named lifetime (if there is one) and

View File

@ -160,7 +160,7 @@ fn do_mir_borrowck<'a, 'tcx>(
};
let bm = *tables.pat_binding_modes().get(var_hir_id)
.expect("missing binding mode");
if bm == ty::BindByValue(hir::Mutability::Mutable) {
if bm == ty::BindByValue(hir::Mutability::Mut) {
upvar.mutability = Mutability::Mut;
}
upvar
@ -2225,10 +2225,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::Ref(_, _, mutbl) => {
match mutbl {
// Shared borrowed data is never mutable
hir::Mutability::Immutable => Err(place),
hir::Mutability::Not => Err(place),
// Mutably borrowed data is mutable, but only if we have a
// unique path to the `&mut`
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
let mode = match self.is_upvar_field_projection(place) {
Some(field)
if self.upvars[field.index()].by_ref =>
@ -2248,10 +2248,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::RawPtr(tnm) => {
match tnm.mutbl {
// `*const` raw pointers are not mutable
hir::Mutability::Immutable => Err(place),
hir::Mutability::Not => Err(place),
// `*mut` raw pointers are always mutable, regardless of
// context. The users have to check by themselves.
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
Ok(RootPlace {
place_base: place.base,
place_projection: place.projection,

View File

@ -58,7 +58,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
if *elem == ProjectionElem::Deref {
let ty = Place::ty_from(&self.base, proj_base, body, tcx).ty;
match ty.kind {
ty::Ref(_, _, hir::Mutability::Immutable) if i == 0 => {
ty::Ref(_, _, hir::Mutability::Not) if i == 0 => {
// For references to thread-local statics, we do need
// to track the borrow.
if body.local_decls[local].is_ref_to_thread_local() {
@ -66,7 +66,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
}
return true;
}
ty::RawPtr(..) | ty::Ref(_, _, hir::Mutability::Immutable) => {
ty::RawPtr(..) | ty::Ref(_, _, hir::Mutability::Not) => {
// For both derefs of raw pointers and `&T`
// references, the original path is `Copy` and
// therefore not significant. In particular,

View File

@ -246,13 +246,11 @@ fn place_components_conflict<'tcx>(
debug!("borrow_conflicts_with_place: shallow access behind ptr");
return false;
}
(ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Immutable), _) => {
(ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Not), _) => {
// Shouldn't be tracked
bug!("Tracking borrow behind shared reference.");
}
(ProjectionElem::Deref,
ty::Ref(_, _, hir::Mutability::Mutable),
AccessDepth::Drop) => {
(ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Mut), AccessDepth::Drop) => {
// Values behind a mutable reference are not access either by dropping a
// value, or by StorageDead
debug!("borrow_conflicts_with_place: drop access behind ptr");

View File

@ -149,7 +149,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
ty::Ref(
_, /*rgn*/
_, /*ty*/
hir::Mutability::Immutable
hir::Mutability::Not
) => {
// don't continue traversing over derefs of raw pointers or shared
// borrows.
@ -160,7 +160,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
ty::Ref(
_, /*rgn*/
_, /*ty*/
hir::Mutability::Mutable,
hir::Mutability::Mut,
) => {
self.next = Some(PlaceRef {
base: cursor.base,

View File

@ -2162,7 +2162,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_from = match op.ty(*body, tcx).kind {
ty::RawPtr(ty::TypeAndMut {
ty: ty_from,
mutbl: hir::Mutability::Mutable,
mutbl: hir::Mutability::Mut,
}) => ty_from,
_ => {
span_mirbug!(
@ -2177,7 +2177,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_to = match ty.kind {
ty::RawPtr(ty::TypeAndMut {
ty: ty_to,
mutbl: hir::Mutability::Immutable,
mutbl: hir::Mutability::Not,
}) => ty_to,
_ => {
span_mirbug!(
@ -2211,7 +2211,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let opt_ty_elem = match ty_from.kind {
ty::RawPtr(
ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: array_ty }
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: array_ty }
) => {
match array_ty.kind {
ty::Array(ty_elem, _) => Some(ty_elem),
@ -2236,7 +2236,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_to = match ty.kind {
ty::RawPtr(
ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: ty_to }
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: ty_to }
) => {
ty_to
}
@ -2504,13 +2504,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
});
match mutbl {
hir::Mutability::Immutable => {
hir::Mutability::Not => {
// Immutable reference. We don't need the base
// to be valid for the entire lifetime of
// the borrow.
break;
}
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
// Mutable reference. We *do* need the base
// to be valid, because after the base becomes
// invalid, someone else can use our mutable deref.

View File

@ -301,11 +301,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
arg,
} => {
let address_of = match mutability {
hir::Mutability::Immutable => Rvalue::AddressOf(
hir::Mutability::Not => Rvalue::AddressOf(
Mutability::Not,
unpack!(block = this.as_read_only_place(block, arg)),
),
hir::Mutability::Mutable => Rvalue::AddressOf(
hir::Mutability::Mut => Rvalue::AddressOf(
Mutability::Mut,
unpack!(block = this.as_place(block, arg)),
),

View File

@ -821,7 +821,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
name = ident.name;
if let Some(&bm) = hir_tables.pat_binding_modes().get(pat.hir_id) {
if bm == ty::BindByValue(hir::Mutability::Mutable) {
if bm == ty::BindByValue(hir::Mutability::Mut) {
mutability = Mutability::Mut;
} else {
mutability = Mutability::Not;

View File

@ -812,13 +812,12 @@ impl ToBorrowKind for AutoBorrowMutability {
fn to_borrow_kind(&self) -> BorrowKind {
use rustc::ty::adjustment::AllowTwoPhase;
match *self {
AutoBorrowMutability::Mutable { allow_two_phase_borrow } =>
AutoBorrowMutability::Mut { allow_two_phase_borrow } =>
BorrowKind::Mut { allow_two_phase_borrow: match allow_two_phase_borrow {
AllowTwoPhase::Yes => true,
AllowTwoPhase::No => false
}},
AutoBorrowMutability::Immutable =>
BorrowKind::Shared,
AutoBorrowMutability::Not => BorrowKind::Shared,
}
}
}
@ -826,8 +825,8 @@ impl ToBorrowKind for AutoBorrowMutability {
impl ToBorrowKind for hir::Mutability {
fn to_borrow_kind(&self) -> BorrowKind {
match *self {
hir::Mutability::Mutable => BorrowKind::Mut { allow_two_phase_borrow: false },
hir::Mutability::Immutable => BorrowKind::Shared,
hir::Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false },
hir::Mutability::Not => BorrowKind::Shared,
}
}
}
@ -994,7 +993,7 @@ fn convert_var(
let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut {
ty: closure_ty,
mutbl: hir::Mutability::Immutable,
mutbl: hir::Mutability::Not,
});
Expr {
ty: closure_ty,
@ -1015,7 +1014,7 @@ fn convert_var(
let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut {
ty: closure_ty,
mutbl: hir::Mutability::Mutable,
mutbl: hir::Mutability::Mut,
});
Expr {
ty: closure_ty,

View File

@ -269,7 +269,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
pat.walk(|p| {
if let hir::PatKind::Binding(_, _, ident, None) = p.kind {
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
if bm != ty::BindByValue(hir::Mutability::Immutable) {
if bm != ty::BindByValue(hir::Mutability::Not) {
// Nothing to check.
return true;
}

View File

@ -598,14 +598,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
let bm = *self.tables.pat_binding_modes().get(pat.hir_id)
.expect("missing binding mode");
let (mutability, mode) = match bm {
ty::BindByValue(hir::Mutability::Mutable) =>
(Mutability::Mut, BindingMode::ByValue),
ty::BindByValue(hir::Mutability::Immutable) =>
(Mutability::Not, BindingMode::ByValue),
ty::BindByReference(hir::Mutability::Mutable) =>
ty::BindByValue(mutbl) => (mutbl, BindingMode::ByValue),
ty::BindByReference(hir::Mutability::Mut) =>
(Mutability::Not, BindingMode::ByRef(
BorrowKind::Mut { allow_two_phase_borrow: false })),
ty::BindByReference(hir::Mutability::Immutable) =>
ty::BindByReference(hir::Mutability::Not) =>
(Mutability::Not, BindingMode::ByRef(
BorrowKind::Shared)),
};

View File

@ -115,11 +115,11 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
// For statics, allocation mutability is the combination of the place mutability and
// the type mutability.
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.
if mutability == Mutability::Immutable && frozen {
alloc.mutability = Mutability::Immutable;
if mutability == Mutability::Not && frozen {
alloc.mutability = Mutability::Not;
} else {
// Just making sure we are not "upgrading" an immutable allocation to mutable.
assert_eq!(alloc.mutability, Mutability::Mutable);
assert_eq!(alloc.mutability, Mutability::Mut);
}
} else {
// We *could* be non-frozen at `ConstBase`, for constants like `Cell::new(0)`.
@ -127,10 +127,10 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
// initial value was computed.
// Constants are never mutable.
assert_eq!(
mutability, Mutability::Immutable,
mutability, Mutability::Not,
"Something went very wrong: mutability requested for a constant"
);
alloc.mutability = Mutability::Immutable;
alloc.mutability = Mutability::Not;
};
// link the alloc id to the actual allocation
let alloc = tcx.intern_const_alloc(alloc);
@ -179,7 +179,7 @@ for
// We are crossing over an `UnsafeCell`, we can mutate again. This means that
// References we encounter inside here are interned as pointing to mutable
// allocations.
let old = std::mem::replace(&mut self.mutability, Mutability::Mutable);
let old = std::mem::replace(&mut self.mutability, Mutability::Mut);
assert_ne!(
self.mode, InternMode::Const,
"UnsafeCells are not allowed behind references in constants. This should have \
@ -210,7 +210,7 @@ for
if let Ok(vtable) = mplace.meta.unwrap().to_ptr() {
// explitly choose `Immutable` here, since vtables are immutable, even
// if the reference of the fat pointer is mutable
self.intern_shallow(vtable.alloc_id, Mutability::Immutable, None)?;
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
}
}
// Check if we have encountered this pointer+layout combination before.
@ -223,16 +223,16 @@ for
// const qualification enforces it. We can lift it in the future.
match (self.mode, mutability) {
// immutable references are fine everywhere
(_, hir::Mutability::Immutable) => {},
(_, hir::Mutability::Not) => {},
// all is "good and well" in the unsoundness of `static mut`
// mutable references are ok in `static`. Either they are treated as immutable
// because they are behind an immutable one, or they are behind an `UnsafeCell`
// and thus ok.
(InternMode::Static, hir::Mutability::Mutable) => {},
(InternMode::Static, hir::Mutability::Mut) => {},
// we statically prevent `&mut T` via `const_qualif` and double check this here
(InternMode::ConstBase, hir::Mutability::Mutable) |
(InternMode::Const, hir::Mutability::Mutable) => {
(InternMode::ConstBase, hir::Mutability::Mut) |
(InternMode::Const, hir::Mutability::Mut) => {
match referenced_ty.kind {
ty::Array(_, n)
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
@ -243,16 +243,14 @@ for
},
}
// Compute the mutability with which we'll start visiting the allocation. This is
// what gets changed when we encounter an `UnsafeCell`
let mutability = match (self.mutability, mutability) {
// The only way a mutable reference actually works as a mutable reference is
// by being in a `static mut` directly or behind another mutable reference.
// If there's an immutable reference or we are inside a static, then our
// mutable reference is equivalent to an immutable one. As an example:
// `&&mut Foo` is semantically equivalent to `&&Foo`
(Mutability::Mutable, hir::Mutability::Mutable) => Mutability::Mutable,
_ => Mutability::Immutable,
};
// what gets changed when we encounter an `UnsafeCell`.
//
// The only way a mutable reference actually works as a mutable reference is
// by being in a `static mut` directly or behind another mutable reference.
// If there's an immutable reference or we are inside a static, then our
// mutable reference is equivalent to an immutable one. As an example:
// `&&mut Foo` is semantically equivalent to `&&Foo`
let mutability = self.mutability.and(mutability);
// Recursing behind references changes the intern mode for constants in order to
// cause assertions to trigger if we encounter any `UnsafeCell`s.
let mode = match self.mode {
@ -282,11 +280,10 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
) -> InterpResult<'tcx> {
let tcx = ecx.tcx;
let (base_mutability, base_intern_mode) = match place_mut {
Some(hir::Mutability::Immutable) => (Mutability::Immutable, InternMode::Static),
// `static mut` doesn't care about interior mutability, it's mutable anyway
Some(hir::Mutability::Mutable) => (Mutability::Mutable, InternMode::Static),
Some(mutbl) => (mutbl, InternMode::Static),
// consts, promoteds. FIXME: what about array lengths, array initializers?
None => (Mutability::Immutable, InternMode::ConstBase),
None => (Mutability::Not, InternMode::ConstBase),
};
// Type based interning.
@ -346,7 +343,7 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
// We cannot have mutable memory inside a constant.
// FIXME: ideally we would assert that they already are immutable, to double-
// check our static checks.
alloc.mutability = Mutability::Immutable;
alloc.mutability = Mutability::Not;
}
let alloc = tcx.intern_const_alloc(alloc);
tcx.alloc_map.lock().set_alloc_id_memory(alloc_id, alloc);

View File

@ -539,7 +539,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// Need to make a copy, even if `get_static_alloc` is able
// to give us a cheap reference.
let alloc = Self::get_static_alloc(memory_extra, tcx, id)?;
if alloc.mutability == Mutability::Immutable {
if alloc.mutability == Mutability::Not {
throw_unsup!(ModifiedConstantMemory)
}
match M::STATIC_KIND {
@ -553,7 +553,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
Err(e) => Err(e),
Ok(a) => {
let a = &mut a.1;
if a.mutability == Mutability::Immutable {
if a.mutability == Mutability::Not {
throw_unsup!(ModifiedConstantMemory)
}
Ok(a)
@ -643,7 +643,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
}
pub fn mark_immutable(&mut self, id: AllocId) -> InterpResult<'tcx> {
self.get_raw_mut(id)?.mutability = Mutability::Immutable;
self.get_raw_mut(id)?.mutability = Mutability::Not;
Ok(())
}

View File

@ -471,7 +471,7 @@ impl CloneShimBuilder<'tcx> {
Mutability::Not,
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
ty,
mutbl: hir::Mutability::Immutable,
mutbl: hir::Mutability::Not,
})
);
@ -757,7 +757,7 @@ fn build_call_shim<'tcx>(
Mutability::Not,
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
ty: sig.inputs()[0],
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
}),
span
));

View File

@ -87,8 +87,8 @@ impl ConstKind {
HirKind::Const => ConstKind::Const,
HirKind::Static(hir::Mutability::Immutable) => ConstKind::Static,
HirKind::Static(hir::Mutability::Mutable) => ConstKind::StaticMut,
HirKind::Static(hir::Mutability::Not) => ConstKind::Static,
HirKind::Static(hir::Mutability::Mut) => ConstKind::StaticMut,
};
Some(mode)

View File

@ -238,7 +238,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
) -> InterpResult<'tcx> {
// if the static allocation is mutable or if it has relocations (it may be legal to mutate
// the memory behind that in the future), then we can't const prop it
if allocation.mutability == Mutability::Mutable || allocation.relocations().len() > 0 {
if allocation.mutability == Mutability::Mut || allocation.relocations().len() > 0 {
throw_unsup!(ConstPropUnsupported("can't eval mutable statics in ConstProp"));
}

View File

@ -391,7 +391,7 @@ fn make_generator_state_argument_indirect<'tcx>(
let ref_gen_ty = tcx.mk_ref(region, ty::TypeAndMut {
ty: gen_ty,
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
});
// Replace the by value generator argument
@ -969,7 +969,7 @@ fn create_generator_drop_shim<'tcx>(
mutability: Mutability::Mut,
ty: tcx.mk_ptr(ty::TypeAndMut {
ty: gen_ty,
mutbl: hir::Mutability::Mutable,
mutbl: hir::Mutability::Mut,
}),
user_ty: UserTypeProjections::none(),
source_info,

View File

@ -79,7 +79,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult {
for ty in ty.walk() {
match ty.kind {
ty::Ref(_, _, hir::Mutability::Mutable) => {
ty::Ref(_, _, hir::Mutability::Mut) => {
if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) {
return Err((
span,

View File

@ -521,7 +521,7 @@ where
let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
ty,
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
});
let ref_place = self.new_temp(ref_ty);
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
@ -580,7 +580,7 @@ where
let ptr_ty = tcx.mk_ptr(ty::TypeAndMut {
ty: ety,
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
});
let ptr = &Place::from(self.new_temp(ptr_ty));
let can_go = Place::from(self.new_temp(tcx.types.bool));

View File

@ -23,7 +23,7 @@ const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify typ
pub(super) fn dummy_arg(ident: Ident) -> Param {
let pat = P(Pat {
id: ast::DUMMY_NODE_ID,
kind: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None),
kind: PatKind::Ident(BindingMode::ByValue(Mutability::Not), ident, None),
span: ident.span,
});
let ty = Ty {

View File

@ -1240,8 +1240,8 @@ impl<'a> Parser<'a> {
// Construct the error and stash it away with the hope
// that typeck will later enrich the error with a type.
let kind = match m {
Some(Mutability::Mutable) => "static mut",
Some(Mutability::Immutable) => "static",
Some(Mutability::Mut) => "static mut",
Some(Mutability::Not) => "static",
None => "const",
};
let mut err = self.struct_span_err(id.span, &format!("missing type for `{}` item", kind));
@ -1961,7 +1961,7 @@ impl<'a> Parser<'a> {
match ty {
Ok(ty) => {
let ident = Ident::new(kw::Invalid, self.prev_span);
let bm = BindingMode::ByValue(Mutability::Immutable);
let bm = BindingMode::ByValue(Mutability::Not);
let pat = self.mk_pat_ident(ty.span, bm, ident);
(pat, ty)
}
@ -2033,7 +2033,7 @@ impl<'a> Parser<'a> {
.span_label(span, msg)
.emit();
Ok((SelfKind::Value(Mutability::Immutable), expect_self_ident(this), this.prev_span))
Ok((SelfKind::Value(Mutability::Not), expect_self_ident(this), this.prev_span))
};
// Parse optional `self` parameter of a method.
@ -2045,23 +2045,23 @@ impl<'a> Parser<'a> {
let eself = if is_isolated_self(self, 1) {
// `&self`
self.bump();
SelfKind::Region(None, Mutability::Immutable)
SelfKind::Region(None, Mutability::Not)
} else if is_isolated_mut_self(self, 1) {
// `&mut self`
self.bump();
self.bump();
SelfKind::Region(None, Mutability::Mutable)
SelfKind::Region(None, Mutability::Mut)
} else if self.look_ahead(1, |t| t.is_lifetime()) && is_isolated_self(self, 2) {
// `&'lt self`
self.bump();
let lt = self.expect_lifetime();
SelfKind::Region(Some(lt), Mutability::Immutable)
SelfKind::Region(Some(lt), Mutability::Not)
} else if self.look_ahead(1, |t| t.is_lifetime()) && is_isolated_mut_self(self, 2) {
// `&'lt mut self`
self.bump();
let lt = self.expect_lifetime();
self.bump();
SelfKind::Region(Some(lt), Mutability::Mutable)
SelfKind::Region(Some(lt), Mutability::Mut)
} else {
// `&not_self`
return Ok(None);
@ -2084,12 +2084,12 @@ impl<'a> Parser<'a> {
}
// `self` and `self: TYPE`
token::Ident(..) if is_isolated_self(self, 0) => {
parse_self_possibly_typed(self, Mutability::Immutable)?
parse_self_possibly_typed(self, Mutability::Not)?
}
// `mut self` and `mut self: TYPE`
token::Ident(..) if is_isolated_mut_self(self, 0) => {
self.bump();
parse_self_possibly_typed(self, Mutability::Mutable)?
parse_self_possibly_typed(self, Mutability::Mut)?
}
_ => return Ok(None),
};

View File

@ -979,18 +979,18 @@ impl<'a> Parser<'a> {
/// Parses mutability (`mut` or nothing).
fn parse_mutability(&mut self) -> Mutability {
if self.eat_keyword(kw::Mut) {
Mutability::Mutable
Mutability::Mut
} else {
Mutability::Immutable
Mutability::Not
}
}
/// Possibly parses mutability (`const` or `mut`).
fn parse_const_or_mut(&mut self) -> Option<Mutability> {
if self.eat_keyword(kw::Mut) {
Some(Mutability::Mutable)
Some(Mutability::Mut)
} else if self.eat_keyword(kw::Const) {
Some(Mutability::Immutable)
Some(Mutability::Not)
} else {
None
}

View File

@ -326,7 +326,7 @@ impl<'a> Parser<'a> {
// Parse `ident @ pat`
// This can give false positives and parse nullary enums,
// they are dealt with later in resolve.
self.parse_pat_ident(BindingMode::ByValue(Mutability::Immutable))?
self.parse_pat_ident(BindingMode::ByValue(Mutability::Not))?
} else if self.is_start_of_pat_with_path() {
// Parse pattern starting with a path
let (qself, path) = if self.eat_lt() {
@ -540,7 +540,7 @@ impl<'a> Parser<'a> {
)
.emit();
self.parse_pat_ident(BindingMode::ByRef(Mutability::Mutable))
self.parse_pat_ident(BindingMode::ByRef(Mutability::Mut))
}
/// Turn all by-value immutable bindings in a pattern into mutable bindings.
@ -553,10 +553,10 @@ impl<'a> Parser<'a> {
}
fn visit_pat(&mut self, pat: &mut P<Pat>) {
if let PatKind::Ident(BindingMode::ByValue(ref mut m @ Mutability::Immutable), ..)
if let PatKind::Ident(BindingMode::ByValue(ref mut m @ Mutability::Not), ..)
= pat.kind
{
*m = Mutability::Mutable;
*m = Mutability::Mut;
self.0 = true;
}
noop_visit_pat(pat, self);
@ -987,10 +987,10 @@ impl<'a> Parser<'a> {
hi = self.prev_span;
let bind_type = match (is_ref, is_mut) {
(true, true) => BindingMode::ByRef(Mutability::Mutable),
(true, false) => BindingMode::ByRef(Mutability::Immutable),
(false, true) => BindingMode::ByValue(Mutability::Mutable),
(false, false) => BindingMode::ByValue(Mutability::Immutable),
(true, true) => BindingMode::ByRef(Mutability::Mut),
(true, false) => BindingMode::ByRef(Mutability::Not),
(false, true) => BindingMode::ByValue(Mutability::Mut),
(false, false) => BindingMode::ByValue(Mutability::Not),
};
let fieldpat = self.mk_pat_ident(boxed_span.to(hi), bind_type, fieldname);

View File

@ -261,7 +261,7 @@ impl<'a> Parser<'a> {
.span_label(span, msg)
.help("use `*mut T` or `*const T` as appropriate")
.emit();
Mutability::Immutable
Mutability::Not
});
let t = self.parse_ty_no_plus()?;
Ok(MutTy { ty: t, mutbl })

View File

@ -161,9 +161,9 @@ impl<'a> AstValidator<'a> {
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, bool)) {
for Param { pat, .. } in &decl.inputs {
match pat.kind {
PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), _, None) |
PatKind::Ident(BindingMode::ByValue(Mutability::Not), _, None) |
PatKind::Wild => {}
PatKind::Ident(BindingMode::ByValue(Mutability::Mutable), _, None) =>
PatKind::Ident(BindingMode::ByValue(Mutability::Mut), _, None) =>
report_err(pat.span, true),
_ => report_err(pat.span, false),
}

View File

@ -81,8 +81,8 @@ impl ConstKind {
let owner = hir_map.body_owner(body.id());
let const_kind = match hir_map.body_owner_kind(owner) {
hir::BodyOwnerKind::Const => Self::Const,
hir::BodyOwnerKind::Static(Mutability::Mutable) => Self::StaticMut,
hir::BodyOwnerKind::Static(Mutability::Immutable) => Self::Static,
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static,
hir::BodyOwnerKind::Fn if is_const_fn(owner) => Self::ConstFn,
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None,

View File

@ -1472,7 +1472,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
// An immutable (no `mut`) by-value (no `ref`) binding pattern without
// a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
// also be interpreted as a path to e.g. a constant, variant, etc.
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Immutable);
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);
match res {
Res::Def(DefKind::Ctor(_, CtorKind::Const), _) |

View File

@ -985,7 +985,7 @@ impl<'l> Visitor<'l> for PathCollector<'l> {
// Even if the ref is mut, you can't change the ref, only
// the data pointed at, so showing the initialising expression
// is still worthwhile.
ast::BindingMode::ByRef(_) => ast::Mutability::Immutable,
ast::BindingMode::ByRef(_) => ast::Mutability::Not,
ast::BindingMode::ByValue(mt) => mt,
};
self.collected_idents

View File

@ -175,8 +175,8 @@ impl Sig for ast::Ty {
}
ast::TyKind::Ptr(ref mt) => {
let prefix = match mt.mutbl {
ast::Mutability::Mutable => "*mut ",
ast::Mutability::Immutable => "*const ",
ast::Mutability::Mut => "*mut ",
ast::Mutability::Not => "*const ",
};
let nested = mt.ty.make(offset + prefix.len(), id, scx)?;
let text = format!("{}{}", prefix, nested.text);
@ -188,7 +188,7 @@ impl Sig for ast::Ty {
prefix.push_str(&l.ident.to_string());
prefix.push(' ');
}
if let ast::Mutability::Mutable = mt.mutbl {
if let ast::Mutability::Mut = mt.mutbl {
prefix.push_str("mut ");
};
@ -330,7 +330,7 @@ impl Sig for ast::Item {
match self.kind {
ast::ItemKind::Static(ref ty, m, ref expr) => {
let mut text = "static ".to_owned();
if m == ast::Mutability::Mutable {
if m == ast::Mutability::Mut {
text.push_str("mut ");
}
let name = self.ident.to_string();
@ -787,7 +787,7 @@ impl Sig for ast::ForeignItem {
}
ast::ForeignItemKind::Static(ref ty, m) => {
let mut text = "static ".to_owned();
if m == ast::Mutability::Mutable {
if m == ast::Mutability::Mut {
text.push_str("mut ");
}
let name = self.ident.to_string();

View File

@ -243,7 +243,7 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
ty::Float(..) |
ty::RawPtr(..) |
ty::Never |
ty::Ref(_, _, hir::Mutability::Immutable) => (),
ty::Ref(_, _, hir::Mutability::Not) => (),
// Non parametric primitive types.
ty::Infer(ty::IntVar(_)) |
@ -319,7 +319,7 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
ty::Generator(..) |
ty::Str |
ty::Slice(..) |
ty::Ref(_, _, hir::Mutability::Mutable) => (),
ty::Ref(_, _, hir::Mutability::Mut) => (),
ty::Bound(..) |
ty::GeneratorWitness(..) |

View File

@ -430,8 +430,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let contains_ref_bindings = arms.iter()
.filter_map(|a| a.pat.contains_explicit_ref_binding())
.max_by_key(|m| match *m {
hir::Mutability::Mutable => 1,
hir::Mutability::Immutable => 0,
hir::Mutability::Mut => 1,
hir::Mutability::Not => 0,
});
if let Some(m) = contains_ref_bindings {

View File

@ -217,8 +217,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if borrow {
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind {
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// For initial two-phase borrow
// deployment, conservatively omit
// overloaded function call ops.

View File

@ -637,8 +637,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
) -> Result<CastKind, CastError> {
// array-ptr-cast.
if m_expr.mutbl == hir::Mutability::Immutable &&
m_cast.mutbl == hir::Mutability::Immutable {
if m_expr.mutbl == hir::Mutability::Not &&
m_cast.mutbl == hir::Mutability::Not {
if let ty::Array(ety, _) = m_expr.ty.kind {
// Due to the limitations of LLVM global constants,
// region pointers end up pointing at copies of

View File

@ -101,10 +101,10 @@ fn coerce_mutbls<'tcx>(from_mutbl: hir::Mutability,
to_mutbl: hir::Mutability)
-> RelateResult<'tcx, ()> {
match (from_mutbl, to_mutbl) {
(hir::Mutability::Mutable, hir::Mutability::Mutable) |
(hir::Mutability::Immutable, hir::Mutability::Immutable) |
(hir::Mutability::Mutable, hir::Mutability::Immutable) => Ok(()),
(hir::Mutability::Immutable, hir::Mutability::Mutable) => Err(TypeError::Mutability),
(hir::Mutability::Mut, hir::Mutability::Mut) |
(hir::Mutability::Not, hir::Mutability::Not) |
(hir::Mutability::Mut, hir::Mutability::Not) => Ok(()),
(hir::Mutability::Not, hir::Mutability::Mut) => Err(TypeError::Mutability),
}
}
@ -412,7 +412,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
}
};
if ty == a && mt_a.mutbl == hir::Mutability::Immutable && autoderef.step_count() == 1 {
if ty == a && mt_a.mutbl == hir::Mutability::Not && autoderef.step_count() == 1 {
// As a special case, if we would produce `&'a *x`, that's
// a total no-op. We end up with the type `&'a T` just as
// we started with. In that case, just skip it
@ -424,7 +424,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// `self.x` both have `&mut `type would be a move of
// `self.x`, but we auto-coerce it to `foo(&mut *self.x)`,
// which is a borrow.
assert_eq!(mt_b.mutbl, hir::Mutability::Immutable); // can only coerce &T -> &U
assert_eq!(mt_b.mutbl, hir::Mutability::Not); // can only coerce &T -> &U
return success(vec![], ty, obligations);
}
@ -441,8 +441,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
_ => span_bug!(span, "expected a ref type, got {:?}", ty),
};
let mutbl = match mt_b.mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
allow_two_phase_borrow: self.allow_two_phase,
}
};
@ -487,8 +487,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let coercion = Coercion(self.cause.span);
let r_borrow = self.next_region_var(coercion);
let mutbl = match mutbl_b {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// We don't allow two-phase borrows here, at least for initial
// implementation. If it happens that this coercion is a function argument,
// the reborrow in coerce_borrowed_ptr will pick it up.

View File

@ -534,8 +534,8 @@ fn compare_self_type<'tcx>(
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty).is_ok();
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
ExplicitSelf::ByValue => "self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Immutable) => "&self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Mutable) => "&mut self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),
_ => format!("self: {}", self_arg_ty)
}
})

View File

@ -436,10 +436,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// bar(&x); // error, expected &mut
// ```
let ref_ty = match mutability {
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
self.tcx.mk_mut_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
}
hir::Mutability::Immutable => {
hir::Mutability::Not => {
self.tcx.mk_imm_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
}
};
@ -489,7 +489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})) = self.tcx.hir().find(
self.tcx.hir().get_parent_node(expr.hir_id),
) {
if mutability == hir::Mutability::Mutable {
if mutability == hir::Mutability::Mut {
// Found the following case:
// fn foo(opt: &mut Option<String>){ opt = None }
// --- ^^^^
@ -508,12 +508,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
return Some(match mutability {
hir::Mutability::Mutable => (
hir::Mutability::Mut => (
sp,
"consider mutably borrowing here",
format!("{}&mut {}", field_name, sugg_expr),
),
hir::Mutability::Immutable => (
hir::Mutability::Not => (
sp,
"consider borrowing here",
format!("{}&{}", field_name, sugg_expr),

View File

@ -365,8 +365,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let method = self.register_infer_ok_obligations(ok);
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind {
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// (It shouldn't actually matter for unary ops whether
// we enable two-phase borrows or not, since a unary
// op has no additional operands.)

View File

@ -165,7 +165,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
"prefetch_read_instruction" | "prefetch_write_instruction" => {
(1, vec![tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Immutable
mutbl: hir::Mutability::Not
}), tcx.types.i32],
tcx.mk_unit())
}
@ -181,13 +181,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Immutable
mutbl: hir::Mutability::Not
}),
tcx.types.isize
],
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Immutable
mutbl: hir::Mutability::Not
}))
}
"copy" | "copy_nonoverlapping" => {
@ -195,11 +195,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Immutable
mutbl: hir::Mutability::Not
}),
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
}),
tcx.types.usize,
],
@ -210,11 +210,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
}),
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Immutable
mutbl: hir::Mutability::Not
}),
tcx.types.usize,
],
@ -225,7 +225,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![
tcx.mk_ptr(ty::TypeAndMut {
ty: param(0),
mutbl: hir::Mutability::Mutable
mutbl: hir::Mutability::Mut
}),
tcx.types.u8,
tcx.types.usize,
@ -351,14 +351,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
}
"va_start" | "va_end" => {
match mk_va_list_ty(hir::Mutability::Mutable) {
match mk_va_list_ty(hir::Mutability::Mut) {
Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk_unit()),
None => bug!("`va_list` language item needed for C-variadic intrinsics")
}
}
"va_copy" => {
match mk_va_list_ty(hir::Mutability::Immutable) {
match mk_va_list_ty(hir::Mutability::Not) {
Some((va_list_ref_ty, va_list_ty)) => {
let va_list_ptr_ty = tcx.mk_mut_ptr(va_list_ty);
(0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk_unit())
@ -368,7 +368,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
}
"va_arg" => {
match mk_va_list_ty(hir::Mutability::Mutable) {
match mk_va_list_ty(hir::Mutability::Mut) {
Some((va_list_ref_ty, _)) => (1, vec![va_list_ref_ty], param(0)),
None => bug!("`va_list` language item needed for C-variadic intrinsics")
}

View File

@ -131,7 +131,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
sig: method_sig,
};
if let Some(hir::Mutability::Mutable) = pick.autoref {
if let Some(hir::Mutability::Mut) = pick.autoref {
self.convert_place_derefs_to_mutable();
}
@ -172,8 +172,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
ty: target
});
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// Method call receivers are the primary use case
// for two-phase borrows.
allow_two_phase_borrow: AllowTwoPhase::Yes,
@ -554,8 +554,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
if let Adjust::Borrow(AutoBorrow::Ref(..)) = adjustment.kind {
debug!("convert_place_op_to_mutable: converting autoref {:?}", adjustment);
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// For initial two-phase borrow
// deployment, conservatively omit
// overloaded operators.

View File

@ -608,11 +608,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let lang_def_id = lang_items.slice_u8_alloc_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Immutable }) => {
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
let lang_def_id = lang_items.const_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mutable }) => {
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mut }) => {
let lang_def_id = lang_items.mut_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
@ -1047,8 +1047,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
});
self.pick_by_value_method(step, self_ty).or_else(|| {
self.pick_autorefd_method(step, self_ty, hir::Mutability::Immutable).or_else(|| {
self.pick_autorefd_method(step, self_ty, hir::Mutability::Mutable)
self.pick_autorefd_method(step, self_ty, hir::Mutability::Not).or_else(|| {
self.pick_autorefd_method(step, self_ty, hir::Mutability::Mut)
})})})
.next()
}

View File

@ -397,8 +397,8 @@ pub enum Needs {
impl Needs {
fn maybe_mut_place(m: hir::Mutability) -> Self {
match m {
hir::Mutability::Mutable => Needs::MutPlace,
hir::Mutability::Immutable => Needs::None,
hir::Mutability::Mut => Needs::MutPlace,
hir::Mutability::Not => Needs::None,
}
}
}
@ -1436,7 +1436,7 @@ fn check_fn<'a, 'tcx>(
ty::Ref(region, ty, mutbl) => match ty.kind {
ty::Adt(ref adt, _) => {
adt.did == panic_info_did &&
mutbl == hir::Mutability::Immutable &&
mutbl == hir::Mutability::Not &&
*region != RegionKind::ReStatic
},
_ => false,
@ -3419,8 +3419,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut adjustments = autoderef.adjust_steps(self, needs);
if let ty::Ref(region, _, r_mutbl) = method.sig.inputs()[0].kind {
let mutbl = match r_mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// Indexing can be desugared to a method call,
// so maybe we could use two-phase here.
// See the documentation of AllowTwoPhase for why that's

View File

@ -206,8 +206,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if is_assign == IsAssign::Yes || by_ref_binop {
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind {
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// Allow two-phase borrows for binops in initial deployment
// since they desugar to methods
allow_two_phase_borrow: AllowTwoPhase::Yes,
@ -223,8 +223,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if by_ref_binop {
if let ty::Ref(region, _, mutbl) = method.sig.inputs()[1].kind {
let mutbl = match mutbl {
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
// Allow two-phase borrows for binops in initial deployment
// since they desugar to methods
allow_two_phase_borrow: AllowTwoPhase::Yes,

View File

@ -32,7 +32,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects";
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_pat_top(&self, pat: &'tcx Pat, expected: Ty<'tcx>, discrim_span: Option<Span>) {
let def_bm = BindingMode::BindByValue(hir::Mutability::Immutable);
let def_bm = BindingMode::BindByValue(hir::Mutability::Not);
self.check_pat(pat, expected, def_bm, discrim_span);
}
@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
//
// See issue #46688.
let def_bm = match pat.kind {
PatKind::Ref(..) => ty::BindByValue(hir::Mutability::Immutable),
PatKind::Ref(..) => ty::BindByValue(hir::Mutability::Not),
_ => def_bm,
};
(expected, def_bm)
@ -277,10 +277,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (depending on whether we observe `&` or `&mut`).
ty::BindByValue(_) |
// When `ref mut`, stay a `ref mut` (on `&mut`) or downgrade to `ref` (on `&`).
ty::BindByReference(hir::Mutability::Mutable) => inner_mutability,
ty::BindByReference(hir::Mutability::Mut) => inner_mutability,
// Once a `ref`, always a `ref`.
// This is because a `& &mut` cannot mutate the underlying value.
ty::BindByReference(m @ hir::Mutability::Immutable) => m,
ty::BindByReference(m @ hir::Mutability::Not) => m,
});
}

View File

@ -1255,7 +1255,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
// know whether this scenario has occurred; but I wanted to show
// how all the types get adjusted.)
match ref_mutability {
hir::Mutability::Immutable => {
hir::Mutability::Not => {
// The reference being reborrowed is a shareable ref of
// type `&'a T`. In this case, it doesn't matter where we
// *found* the `&T` pointer, the memory it references will
@ -1263,7 +1263,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
true
}
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
// The reference being reborrowed is either an `&mut T`. This is
// the case where recursion is needed.
false

View File

@ -353,7 +353,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
// borrowed pointer implies that the
// pointer itself must be unique, but not
// necessarily *mutable*
ty::Ref(.., hir::Mutability::Mutable) => borrow_kind = ty::UniqueImmBorrow,
ty::Ref(.., hir::Mutability::Mut) => borrow_kind = ty::UniqueImmBorrow,
_ => (),
}
}

View File

@ -360,7 +360,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
mt_b: ty::TypeAndMut<'tcx>,
mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'tcx>| {
if (mt_a.mutbl, mt_b.mutbl) == (hir::Mutability::Immutable, hir::Mutability::Mutable) {
if (mt_a.mutbl, mt_b.mutbl) == (hir::Mutability::Not, hir::Mutability::Mut) {
infcx.report_mismatched_types(&cause,
mk_ptr(mt_b.ty),
target,

View File

@ -109,7 +109,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
"[T]",
item.span);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Immutable }) => {
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
self.check_primitive_impl(def_id,
lang_items.const_ptr_impl(),
None,
@ -117,7 +117,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
"*const T",
item.span);
}
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mutable }) => {
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mut }) => {
self.check_primitive_impl(def_id,
lang_items.mut_ptr_impl(),
None,

View File

@ -454,12 +454,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
mt: &ty::TypeAndMut<'tcx>,
variance: VarianceTermPtr<'a>) {
match mt.mutbl {
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
let invar = self.invariant(variance);
self.add_constraints_from_ty(current, mt.ty, invar);
}
hir::Mutability::Immutable => {
hir::Mutability::Not => {
self.add_constraints_from_ty(current, mt.ty, variance);
}
}

View File

@ -2101,8 +2101,8 @@ impl Clean<Item> for doctree::Constant<'_> {
impl Clean<Mutability> for hir::Mutability {
fn clean(&self, _: &DocContext<'_>) -> Mutability {
match self {
&hir::Mutability::Mutable => Mutable,
&hir::Mutability::Immutable => Immutable,
&hir::Mutability::Mut => Mutable,
&hir::Mutability::Not => Immutable,
}
}
}

View File

@ -509,7 +509,7 @@ impl Pat {
// In a type expression `_` is an inference variable.
PatKind::Wild => TyKind::Infer,
// An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None) => {
PatKind::Ident(BindingMode::ByValue(Mutability::Not), ident, None) => {
TyKind::Path(None, Path::from_ident(*ident))
}
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
@ -695,30 +695,30 @@ pub enum PatKind {
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)]
pub enum Mutability {
Mutable,
Immutable,
Mut,
Not,
}
impl Mutability {
/// Returns `MutMutable` only if both `self` and `other` are mutable.
pub fn and(self, other: Self) -> Self {
match self {
Mutability::Mutable => other,
Mutability::Immutable => Mutability::Immutable,
Mutability::Mut => other,
Mutability::Not => Mutability::Not,
}
}
pub fn invert(self) -> Self {
match self {
Mutability::Mutable => Mutability::Immutable,
Mutability::Immutable => Mutability::Mutable,
Mutability::Mut => Mutability::Not,
Mutability::Not => Mutability::Mut,
}
}
pub fn prefix_str(&self) -> &'static str {
match self {
Mutability::Mutable => "mut ",
Mutability::Immutable => "",
Mutability::Mut => "mut ",
Mutability::Not => "",
}
}
}
@ -2037,7 +2037,7 @@ impl Param {
SelfKind::Explicit(ty, mutbl) => param(mutbl, ty),
SelfKind::Value(mutbl) => param(mutbl, infer_ty),
SelfKind::Region(lt, mutbl) => param(
Mutability::Immutable,
Mutability::Not,
P(Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Rptr(

View File

@ -1071,7 +1071,7 @@ impl<'a> State<'a> {
}
ast::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == ast::Mutability::Mutable {
if m == ast::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
@ -1162,7 +1162,7 @@ impl<'a> State<'a> {
}
ast::ItemKind::Static(ref ty, m, ref expr) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == ast::Mutability::Mutable {
if m == ast::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
@ -2302,8 +2302,8 @@ impl<'a> State<'a> {
self.word_nbsp("ref");
self.print_mutability(mutbl, false);
}
ast::BindingMode::ByValue(ast::Mutability::Immutable) => {}
ast::BindingMode::ByValue(ast::Mutability::Mutable) => {
ast::BindingMode::ByValue(ast::Mutability::Not) => {}
ast::BindingMode::ByValue(ast::Mutability::Mut) => {
self.word_nbsp("mut");
}
}
@ -2366,7 +2366,7 @@ impl<'a> State<'a> {
}
PatKind::Ref(ref inner, mutbl) => {
self.s.word("&");
if mutbl == ast::Mutability::Mutable {
if mutbl == ast::Mutability::Mut {
self.s.word("mut ");
}
self.print_pat(inner);
@ -2667,8 +2667,8 @@ impl<'a> State<'a> {
pub fn print_mutability(&mut self, mutbl: ast::Mutability, print_const: bool) {
match mutbl {
ast::Mutability::Mutable => self.word_nbsp("mut"),
ast::Mutability::Immutable => if print_const { self.word_nbsp("const"); },
ast::Mutability::Mut => self.word_nbsp("mut"),
ast::Mutability::Not => if print_const { self.word_nbsp("const"); },
}
}

View File

@ -179,7 +179,7 @@ impl<'a> ExtCtxt<'a> {
pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
ex: P<ast::Expr>) -> ast::Stmt {
let pat = if mutbl {
let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable);
let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mut);
self.pat_ident_binding_mode(sp, ident, binding_mode)
} else {
self.pat_ident(sp, ident)
@ -270,7 +270,7 @@ impl<'a> ExtCtxt<'a> {
}
pub fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Immutable, e))
self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e))
}
pub fn expr_call(
@ -422,7 +422,7 @@ impl<'a> ExtCtxt<'a> {
self.pat(span, PatKind::Lit(expr))
}
pub fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat> {
let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Immutable);
let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Not);
self.pat_ident_binding_mode(span, ident, binding_mode)
}

View File

@ -18,7 +18,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>,
push: &mut dyn FnMut(Annotatable)) {
// &mut ::std::fmt::Formatter
let fmtr = Ptr(Box::new(Literal(path_std!(cx, fmt::Formatter))),
Borrowed(None, ast::Mutability::Mutable));
Borrowed(None, ast::Mutability::Mut));
let trait_def = TraitDef {
span,

View File

@ -39,7 +39,7 @@ pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt<'_>,
},
explicit_self: None,
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable)), "d")],
Borrowed(None, Mutability::Mut)), "d")],
ret_ty:
Literal(Path::new_(pathvec_std!(cx, result::Result),
None,

View File

@ -123,7 +123,7 @@ pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt<'_>,
},
explicit_self: borrowed_explicit_self(),
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable)), "s")],
Borrowed(None, Mutability::Mut)), "s")],
ret_ty: Literal(Path::new_(
pathvec_std!(cx, result::Result),
None,

View File

@ -1018,7 +1018,7 @@ impl<'a> MethodDef<'a> {
struct_path,
struct_def,
&format!("__self_{}", i),
ast::Mutability::Immutable,
ast::Mutability::Not,
use_temporaries);
patterns.push(pat);
raw_fields.push(ident_expr);
@ -1228,8 +1228,8 @@ impl<'a> MethodDef<'a> {
type_ident,
variant,
self_arg_name,
ast::Mutability::Immutable);
(cx.pat(sp, PatKind::Ref(p, ast::Mutability::Immutable)), idents)
ast::Mutability::Not);
(cx.pat(sp, PatKind::Ref(p, ast::Mutability::Not)), idents)
};
// A single arm has form (&VariantK, &VariantK, ...) => BodyK
@ -1559,7 +1559,7 @@ impl<'a> TraitDef<'a> {
field_paths.iter()
.map(|path| {
let binding_mode = if use_temporaries {
ast::BindingMode::ByValue(ast::Mutability::Immutable)
ast::BindingMode::ByValue(ast::Mutability::Not)
} else {
ast::BindingMode::ByRef(mutbl)
};

View File

@ -108,7 +108,7 @@ pub enum Ty<'a> {
}
pub fn borrowed_ptrty() -> PtrTy {
Borrowed(None, ast::Mutability::Immutable)
Borrowed(None, ast::Mutability::Not)
}
pub fn borrowed(ty: Box<Ty<'_>>) -> Ty<'_> {
Ptr(ty, borrowed_ptrty())
@ -268,7 +268,7 @@ pub fn get_explicit_self(cx: &ExtCtxt<'_>,
// this constructs a fresh `self` path
let self_path = cx.expr_self(span);
match *self_ptr {
None => (self_path, respan(span, SelfKind::Value(ast::Mutability::Immutable))),
None => (self_path, respan(span, SelfKind::Value(ast::Mutability::Not))),
Some(ref ptr) => {
let self_ty =
respan(span,

View File

@ -35,7 +35,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
},
explicit_self: borrowed_explicit_self(),
args: vec![(Ptr(Box::new(Literal(arg)),
Borrowed(None, Mutability::Mutable)), "state")],
Borrowed(None, Mutability::Mut)), "state")],
ret_ty: nil_ty(),
attributes: vec![],
is_unsafe: false,

View File

@ -31,7 +31,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
cx.ty_ident(sp,
Ident::new(sym::str, sp)),
Some(lt),
ast::Mutability::Immutable))],
ast::Mutability::Not))],
))
}
Ok(s) => {

View File

@ -180,6 +180,6 @@ impl AllocFnFactory<'_, '_> {
fn ptr_u8(&self) -> P<Ty> {
let u8 = self.cx.path_ident(self.span, Ident::new(sym::u8, self.span));
let ty_u8 = self.cx.ty_path(u8);
self.cx.ty_ptr(self.span, ty_u8, Mutability::Mutable)
self.cx.ty_ptr(self.span, ty_u8, Mutability::Mut)
}
}

View File

@ -415,8 +415,8 @@ fn mk_decls(
cx.ty(span, ast::TyKind::Slice(
cx.ty_path(cx.path(span,
vec![proc_macro, bridge, client, proc_macro_ty])))),
None, ast::Mutability::Immutable),
ast::Mutability::Immutable,
None, ast::Mutability::Not),
ast::Mutability::Not,
cx.expr_vec_slice(span, decls),
).map(|mut i| {
let attr = cx.meta_word(span, sym::rustc_proc_macro_decls);

View File

@ -141,7 +141,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
15 => {
iter_exprs(
depth - 1,
&mut |e| g(ExprKind::AddrOf(BorrowKind::Ref, Mutability::Immutable, e)),
&mut |e| g(ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, e)),
);
},
16 => {