Merge hir::Mutability into ast::Mutability.
This commit is contained in:
parent
57a5f92bef
commit
ed640c6a27
65 changed files with 218 additions and 233 deletions
|
@ -2077,13 +2077,6 @@ impl<'a> LoweringContext<'a> {
|
|||
}, ids)
|
||||
}
|
||||
|
||||
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
|
||||
match m {
|
||||
Mutability::Mutable => hir::MutMutable,
|
||||
Mutability::Immutable => hir::MutImmutable,
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
|
||||
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
|
||||
// as they are not explicit in HIR/Ty function signatures.
|
||||
|
@ -2653,7 +2646,7 @@ impl<'a> LoweringContext<'a> {
|
|||
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy {
|
||||
hir::MutTy {
|
||||
ty: self.lower_ty(&mt.ty, itctx),
|
||||
mutbl: self.lower_mutability(mt.mutbl),
|
||||
mutbl: mt.mutbl,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2754,7 +2747,7 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
|
||||
PatKind::Ref(ref inner, mutbl) => {
|
||||
hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl))
|
||||
hir::PatKind::Ref(self.lower_pat(inner), mutbl)
|
||||
}
|
||||
PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range(
|
||||
P(self.lower_expr(e1)),
|
||||
|
|
|
@ -64,7 +64,6 @@ impl LoweringContext<'_> {
|
|||
hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
|
||||
}
|
||||
ExprKind::AddrOf(m, ref ohs) => {
|
||||
let m = self.lower_mutability(m);
|
||||
let ohs = P(self.lower_expr(ohs));
|
||||
hir::ExprKind::AddrOf(m, ohs)
|
||||
}
|
||||
|
@ -1350,7 +1349,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::MutMutable, e), ThinVec::new())
|
||||
self.expr(span, hir::ExprKind::AddrOf(hir::Mutability::Mutable, e), ThinVec::new())
|
||||
}
|
||||
|
||||
fn expr_unit(&mut self, sp: Span) -> hir::Expr {
|
||||
|
|
|
@ -289,7 +289,7 @@ impl LoweringContext<'_> {
|
|||
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
|
||||
}
|
||||
),
|
||||
self.lower_mutability(m),
|
||||
m,
|
||||
self.lower_const_body(e),
|
||||
)
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ impl LoweringContext<'_> {
|
|||
}
|
||||
ForeignItemKind::Static(ref t, m) => {
|
||||
hir::ForeignItemKind::Static(
|
||||
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
|
||||
self.lower_ty(t, ImplTraitContext::disallowed()), m)
|
||||
}
|
||||
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
|
||||
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
pub use self::BlockCheckMode::*;
|
||||
pub use self::CaptureClause::*;
|
||||
pub use self::FunctionRetTy::*;
|
||||
pub use self::Mutability::*;
|
||||
pub use self::PrimTy::*;
|
||||
pub use self::UnOp::*;
|
||||
pub use self::UnsafeSource::*;
|
||||
|
@ -23,6 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
|
|||
use syntax::source_map::Spanned;
|
||||
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
|
||||
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
|
||||
pub use syntax::ast::Mutability;
|
||||
use syntax::attr::{InlineAttr, OptimizeAttr};
|
||||
use syntax::symbol::{Symbol, kw};
|
||||
use syntax::tokenstream::TokenStream;
|
||||
|
@ -1053,37 +1053,6 @@ pub enum PatKind {
|
|||
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
|
||||
RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum Mutability {
|
||||
MutMutable,
|
||||
MutImmutable,
|
||||
}
|
||||
|
||||
impl Mutability {
|
||||
/// Returns `MutMutable` only if both `self` and `other` are mutable.
|
||||
pub fn and(self, other: Self) -> Self {
|
||||
match self {
|
||||
MutMutable => other,
|
||||
MutImmutable => MutImmutable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn invert(self) -> Self {
|
||||
match self {
|
||||
MutMutable => MutImmutable,
|
||||
MutImmutable => MutMutable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefix_str(&self) -> &'static str {
|
||||
match self {
|
||||
MutMutable => "mut ",
|
||||
MutImmutable => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
|
||||
pub enum BinOpKind {
|
||||
/// The `+` operator (addition).
|
||||
|
|
|
@ -169,10 +169,10 @@ impl hir::Pat {
|
|||
self.each_binding(|annotation, _, _, _| {
|
||||
match annotation {
|
||||
hir::BindingAnnotation::Ref => match result {
|
||||
None | Some(hir::MutImmutable) => result = Some(hir::MutImmutable),
|
||||
None | Some(hir::Mutability::Immutable) => result = Some(hir::Mutability::Immutable),
|
||||
_ => {}
|
||||
}
|
||||
hir::BindingAnnotation::RefMut => result = Some(hir::MutMutable),
|
||||
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -295,8 +295,8 @@ impl<'a> State<'a> {
|
|||
hir::TyKind::Ptr(ref mt) => {
|
||||
self.s.word("*");
|
||||
match mt.mutbl {
|
||||
hir::MutMutable => self.word_nbsp("mut"),
|
||||
hir::MutImmutable => self.word_nbsp("const"),
|
||||
hir::Mutability::Mutable => self.word_nbsp("mut"),
|
||||
hir::Mutability::Immutable => self.word_nbsp("const"),
|
||||
}
|
||||
self.print_type(&mt.ty);
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
hir::ForeignItemKind::Static(ref t, m) => {
|
||||
self.head(visibility_qualified(&item.vis, "static"));
|
||||
if m == hir::MutMutable {
|
||||
if m == hir::Mutability::Mutable {
|
||||
self.word_space("mut");
|
||||
}
|
||||
self.print_ident(item.ident);
|
||||
|
@ -506,7 +506,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
hir::ItemKind::Static(ref ty, m, expr) => {
|
||||
self.head(visibility_qualified(&item.vis, "static"));
|
||||
if m == hir::MutMutable {
|
||||
if m == hir::Mutability::Mutable {
|
||||
self.word_space("mut");
|
||||
}
|
||||
self.print_ident(item.ident);
|
||||
|
@ -1628,11 +1628,11 @@ impl<'a> State<'a> {
|
|||
match binding_mode {
|
||||
hir::BindingAnnotation::Ref => {
|
||||
self.word_nbsp("ref");
|
||||
self.print_mutability(hir::MutImmutable);
|
||||
self.print_mutability(hir::Mutability::Immutable);
|
||||
}
|
||||
hir::BindingAnnotation::RefMut => {
|
||||
self.word_nbsp("ref");
|
||||
self.print_mutability(hir::MutMutable);
|
||||
self.print_mutability(hir::Mutability::Mutable);
|
||||
}
|
||||
hir::BindingAnnotation::Unannotated => {}
|
||||
hir::BindingAnnotation::Mutable => {
|
||||
|
@ -2061,8 +2061,8 @@ impl<'a> State<'a> {
|
|||
|
||||
pub fn print_mutability(&mut self, mutbl: hir::Mutability) {
|
||||
match mutbl {
|
||||
hir::MutMutable => self.word_nbsp("mut"),
|
||||
hir::MutImmutable => {},
|
||||
hir::Mutability::Mutable => self.word_nbsp("mut"),
|
||||
hir::Mutability::Immutable => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
|
|||
}
|
||||
}
|
||||
}
|
||||
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::MutImmutable }) => {
|
||||
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
|
||||
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;
|
||||
|
|
|
@ -67,7 +67,7 @@ use crate::ty::adjustment;
|
|||
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
|
||||
use crate::hir::{MutImmutable, MutMutable, PatKind};
|
||||
use crate::hir::{Mutability, PatKind};
|
||||
use crate::hir::pat_util::EnumerateAndAdjustIterator;
|
||||
use crate::hir;
|
||||
use syntax::ast::{self, Name};
|
||||
|
@ -226,8 +226,8 @@ pub type McResult<T> = Result<T, ()>;
|
|||
impl MutabilityCategory {
|
||||
pub fn from_mutbl(m: hir::Mutability) -> MutabilityCategory {
|
||||
let ret = match m {
|
||||
MutImmutable => McImmutable,
|
||||
MutMutable => McDeclared
|
||||
Mutability::Immutable => McImmutable,
|
||||
Mutability::Mutable => McDeclared
|
||||
};
|
||||
debug!("MutabilityCategory::{}({:?}) => {:?}",
|
||||
"from_mutbl", m, ret);
|
||||
|
@ -274,7 +274,7 @@ impl MutabilityCategory {
|
|||
let bm = *tables.pat_binding_modes()
|
||||
.get(p.hir_id)
|
||||
.expect("missing binding mode");
|
||||
if bm == ty::BindByValue(hir::MutMutable) {
|
||||
if bm == ty::BindByValue(Mutability::Mutable) {
|
||||
McDeclared
|
||||
} else {
|
||||
McImmutable
|
||||
|
@ -663,8 +663,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||
span,
|
||||
cat,
|
||||
mutbl: match self.tcx.static_mutability(def_id).unwrap() {
|
||||
hir::MutImmutable => McImmutable,
|
||||
hir::MutMutable => McDeclared,
|
||||
Mutability::Immutable => McImmutable,
|
||||
Mutability::Mutable => McDeclared,
|
||||
},
|
||||
ty:expr_ty,
|
||||
note: NoteNone
|
||||
|
|
|
@ -491,8 +491,8 @@ pub enum Mutability {
|
|||
impl From<Mutability> for hir::Mutability {
|
||||
fn from(m: Mutability) -> Self {
|
||||
match m {
|
||||
Mutability::Mut => hir::MutMutable,
|
||||
Mutability::Not => hir::MutImmutable,
|
||||
Mutability::Mut => hir::Mutability::Mutable,
|
||||
Mutability::Not => hir::Mutability::Immutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,17 +276,17 @@ impl<'tcx> BinOp {
|
|||
impl BorrowKind {
|
||||
pub fn to_mutbl_lossy(self) -> hir::Mutability {
|
||||
match self {
|
||||
BorrowKind::Mut { .. } => hir::MutMutable,
|
||||
BorrowKind::Shared => hir::MutImmutable,
|
||||
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
|
||||
BorrowKind::Shared => hir::Mutability::Immutable,
|
||||
|
||||
// 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::MutMutable,
|
||||
BorrowKind::Unique => hir::Mutability::Mutable,
|
||||
|
||||
// We have no type corresponding to a shallow borrow, so use
|
||||
// `&` as an approximation.
|
||||
BorrowKind::Shallow => hir::MutImmutable,
|
||||
BorrowKind::Shallow => hir::Mutability::Immutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1385,8 +1385,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::MutMutable => self.tcx.mk_imm_ref(region, t_type),
|
||||
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
|
||||
hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
|
||||
hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
|
||||
};
|
||||
|
||||
let substs = self.tcx.mk_substs_trait(&trait_type, &[]);
|
||||
|
@ -1403,7 +1403,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::MutImmutable &&
|
||||
mutability == hir::Mutability::Immutable &&
|
||||
refs_number > 0
|
||||
{
|
||||
err.span_suggestion(
|
||||
|
|
|
@ -2652,7 +2652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
| ty::Char
|
||||
| ty::RawPtr(..)
|
||||
| ty::Never
|
||||
| ty::Ref(_, _, hir::MutImmutable) => {
|
||||
| ty::Ref(_, _, hir::Mutability::Immutable) => {
|
||||
// Implementations provided in libcore
|
||||
None
|
||||
}
|
||||
|
@ -2663,7 +2663,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
| ty::Generator(..)
|
||||
| ty::GeneratorWitness(..)
|
||||
| ty::Foreign(..)
|
||||
| ty::Ref(_, _, hir::MutMutable) => None,
|
||||
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
|
||||
|
||||
ty::Array(element_ty, _) => {
|
||||
// (*) binder moved here
|
||||
|
|
|
@ -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::MutImmutable => tcx.lang_items().deref_trait(),
|
||||
hir::MutMutable => tcx.lang_items().deref_mut_trait()
|
||||
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
|
||||
hir::Mutability::Mutable => 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;
|
||||
|
@ -145,8 +145,8 @@ pub enum AutoBorrowMutability {
|
|||
impl From<AutoBorrowMutability> for hir::Mutability {
|
||||
fn from(m: AutoBorrowMutability) -> Self {
|
||||
match m {
|
||||
AutoBorrowMutability::Mutable { .. } => hir::MutMutable,
|
||||
AutoBorrowMutability::Immutable => hir::MutImmutable,
|
||||
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
|
||||
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
|
|||
impl BindingMode {
|
||||
pub fn convert(ba: BindingAnnotation) -> BindingMode {
|
||||
match ba {
|
||||
Unannotated => BindingMode::BindByValue(Mutability::MutImmutable),
|
||||
Mutable => BindingMode::BindByValue(Mutability::MutMutable),
|
||||
Ref => BindingMode::BindByReference(Mutability::MutImmutable),
|
||||
RefMut => BindingMode::BindByReference(Mutability::MutMutable),
|
||||
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
|
||||
Mutable => BindingMode::BindByValue(Mutability::Mutable),
|
||||
Ref => BindingMode::BindByReference(Mutability::Immutable),
|
||||
RefMut => BindingMode::BindByReference(Mutability::Mutable),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2410,22 +2410,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::MutMutable})
|
||||
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
|
||||
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutMutable})
|
||||
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
|
||||
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -211,7 +211,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
region.to_string() != "'_" //... or a complex type
|
||||
{
|
||||
format!("{}reference", match mutbl {
|
||||
hir::Mutability::MutMutable => "mutable ",
|
||||
hir::Mutability::Mutable => "mutable ",
|
||||
_ => ""
|
||||
}).into()
|
||||
} else {
|
||||
|
|
|
@ -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::MutImmutable => if is_freeze {
|
||||
hir::Mutability::Immutable => if is_freeze {
|
||||
PointerKind::Frozen
|
||||
} else {
|
||||
PointerKind::Shared
|
||||
},
|
||||
hir::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
// 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 didn’t seem to have
|
||||
|
|
|
@ -2693,8 +2693,8 @@ impl<'tcx> TyS<'tcx> {
|
|||
impl BorrowKind {
|
||||
pub fn from_mutbl(m: hir::Mutability) -> BorrowKind {
|
||||
match m {
|
||||
hir::MutMutable => MutBorrow,
|
||||
hir::MutImmutable => ImmBorrow,
|
||||
hir::Mutability::Mutable => MutBorrow,
|
||||
hir::Mutability::Immutable => ImmBorrow,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2704,13 +2704,13 @@ impl BorrowKind {
|
|||
/// question.
|
||||
pub fn to_mutbl_lossy(self) -> hir::Mutability {
|
||||
match self {
|
||||
MutBorrow => hir::MutMutable,
|
||||
ImmBorrow => hir::MutImmutable,
|
||||
MutBorrow => hir::Mutability::Mutable,
|
||||
ImmBorrow => hir::Mutability::Immutable,
|
||||
|
||||
// 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::MutMutable,
|
||||
UniqueImmBorrow => hir::Mutability::Mutable,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ impl DefPathBasedNames<'tcx> {
|
|||
ty::RawPtr(ty::TypeAndMut { ty: inner_type, mutbl }) => {
|
||||
output.push('*');
|
||||
match mutbl {
|
||||
hir::MutImmutable => output.push_str("const "),
|
||||
hir::MutMutable => output.push_str("mut "),
|
||||
hir::Mutability::Immutable => output.push_str("const "),
|
||||
hir::Mutability::Mutable => output.push_str("mut "),
|
||||
}
|
||||
|
||||
self.push_type_name(inner_type, output, debug);
|
||||
|
|
|
@ -471,8 +471,8 @@ pub trait PrettyPrinter<'tcx>:
|
|||
ty::Float(t) => p!(write("{}", t.name_str())),
|
||||
ty::RawPtr(ref tm) => {
|
||||
p!(write("*{} ", match tm.mutbl {
|
||||
hir::MutMutable => "mut",
|
||||
hir::MutImmutable => "const",
|
||||
hir::Mutability::Mutable => "mut",
|
||||
hir::Mutability::Immutable => "const",
|
||||
}));
|
||||
p!(print(tm.ty))
|
||||
}
|
||||
|
|
|
@ -121,8 +121,8 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
|
|||
} else {
|
||||
let mutbl = a.mutbl;
|
||||
let variance = match mutbl {
|
||||
ast::Mutability::MutImmutable => ty::Covariant,
|
||||
ast::Mutability::MutMutable => ty::Invariant,
|
||||
ast::Mutability::Immutable => ty::Covariant,
|
||||
ast::Mutability::Mutable => ty::Invariant,
|
||||
};
|
||||
let ty = relation.relate_with_variance(variance, &a.ty, &b.ty)?;
|
||||
Ok(ty::TypeAndMut { ty, mutbl })
|
||||
|
|
|
@ -1839,8 +1839,8 @@ impl<'tcx> TyS<'tcx> {
|
|||
#[inline]
|
||||
pub fn is_mutable_ptr(&self) -> bool {
|
||||
match self.kind {
|
||||
RawPtr(TypeAndMut { mutbl: hir::Mutability::MutMutable, .. }) |
|
||||
Ref(_, _, hir::Mutability::MutMutable) => true,
|
||||
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mutable, .. }) |
|
||||
Ref(_, _, hir::Mutability::Mutable) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -2030,7 +2030,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
Adt(def, _) if def.is_box() => {
|
||||
Some(TypeAndMut {
|
||||
ty: self.boxed_ty(),
|
||||
mutbl: hir::MutImmutable,
|
||||
mutbl: hir::Mutability::Immutable,
|
||||
})
|
||||
},
|
||||
Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl }),
|
||||
|
|
|
@ -184,7 +184,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::MutImmutable) => return Ok(()),
|
||||
ty::Ref(_, _, hir::Mutability::Immutable) => return Ok(()),
|
||||
|
||||
ty::Adt(adt, substs) => (adt, substs),
|
||||
|
||||
|
@ -680,7 +680,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::MutMutable)
|
||||
self.static_mutability(def_id) == Some(hir::Mutability::Mutable)
|
||||
}
|
||||
|
||||
/// Expands the given impl trait type, stopping if the type is recursive.
|
||||
|
|
|
@ -1573,7 +1573,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::MutMutable
|
||||
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mutable
|
||||
=> (ptr_count(arg_tys[1].simd_type(tcx)),
|
||||
non_ptr(arg_tys[1].simd_type(tcx))),
|
||||
_ => {
|
||||
|
|
|
@ -62,8 +62,8 @@ pub fn push_debuginfo_type_name<'tcx>(
|
|||
output.push('*');
|
||||
}
|
||||
match mutbl {
|
||||
hir::MutImmutable => output.push_str("const "),
|
||||
hir::MutMutable => output.push_str("mut "),
|
||||
hir::Mutability::Immutable => output.push_str("const "),
|
||||
hir::Mutability::Mutable => output.push_str("mut "),
|
||||
}
|
||||
|
||||
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
|
||||
|
|
|
@ -373,8 +373,8 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
|
|||
|
||||
ty::Ref(r, ty, mutbl) => {
|
||||
self.push(match mutbl {
|
||||
hir::MutImmutable => "R",
|
||||
hir::MutMutable => "Q",
|
||||
hir::Mutability::Immutable => "R",
|
||||
hir::Mutability::Mutable => "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::MutImmutable => "P",
|
||||
hir::MutMutable => "O",
|
||||
hir::Mutability::Immutable => "P",
|
||||
hir::Mutability::Mutable => "O",
|
||||
});
|
||||
self = mt.ty.print(self)?;
|
||||
}
|
||||
|
|
|
@ -926,8 +926,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::MutMutable &&
|
||||
from_mt == hir::Mutability::MutImmutable {
|
||||
if to_mt == hir::Mutability::Mutable &&
|
||||
from_mt == hir::Mutability::Immutable {
|
||||
cx.span_lint(MUTABLE_TRANSMUTES, expr.span, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1236,9 +1236,9 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> {
|
||||
match self.kind(id) {
|
||||
EntryKind::ImmStatic |
|
||||
EntryKind::ForeignImmStatic => Some(hir::MutImmutable),
|
||||
EntryKind::ForeignImmStatic => Some(hir::Mutability::Immutable),
|
||||
EntryKind::MutStatic |
|
||||
EntryKind::ForeignMutStatic => Some(hir::MutMutable),
|
||||
EntryKind::ForeignMutStatic => Some(hir::Mutability::Mutable),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1086,8 +1086,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::MutMutable, _) => EntryKind::MutStatic,
|
||||
hir::ItemKind::Static(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
|
||||
hir::ItemKind::Static(_, hir::Mutability::Mutable, _) => EntryKind::MutStatic,
|
||||
hir::ItemKind::Static(_, hir::Mutability::Immutable, _) => EntryKind::ImmStatic,
|
||||
hir::ItemKind::Const(_, body_id) => {
|
||||
let mir = self.tcx.at(item.span).mir_const_qualif(def_id);
|
||||
EntryKind::Const(
|
||||
|
@ -1571,8 +1571,8 @@ impl EncodeContext<'tcx> {
|
|||
};
|
||||
EntryKind::ForeignFn(self.lazy(data))
|
||||
}
|
||||
hir::ForeignItemKind::Static(_, hir::MutMutable) => EntryKind::ForeignMutStatic,
|
||||
hir::ForeignItemKind::Static(_, hir::MutImmutable) => EntryKind::ForeignImmStatic,
|
||||
hir::ForeignItemKind::Static(_, hir::Mutability::Mutable) => EntryKind::ForeignMutStatic,
|
||||
hir::ForeignItemKind::Static(_, hir::Mutability::Immutable) => EntryKind::ForeignImmStatic,
|
||||
hir::ForeignItemKind::Type => EntryKind::ForeignType,
|
||||
});
|
||||
record!(self.per_def.visibility[def_id] <-
|
||||
|
|
|
@ -137,7 +137,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::MutMutable) {
|
||||
if bm == ty::BindByValue(hir::Mutability::Mutable) {
|
||||
upvar.mutability = Mutability::Mut;
|
||||
}
|
||||
upvar
|
||||
|
@ -2118,10 +2118,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
ty::Ref(_, _, mutbl) => {
|
||||
match mutbl {
|
||||
// Shared borrowed data is never mutable
|
||||
hir::MutImmutable => Err(place),
|
||||
hir::Mutability::Immutable => Err(place),
|
||||
// Mutably borrowed data is mutable, but only if we have a
|
||||
// unique path to the `&mut`
|
||||
hir::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
let mode = match self.is_upvar_field_projection(place) {
|
||||
Some(field)
|
||||
if self.upvars[field.index()].by_ref =>
|
||||
|
@ -2141,10 +2141,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
ty::RawPtr(tnm) => {
|
||||
match tnm.mutbl {
|
||||
// `*const` raw pointers are not mutable
|
||||
hir::MutImmutable => Err(place),
|
||||
hir::Mutability::Immutable => Err(place),
|
||||
// `*mut` raw pointers are always mutable, regardless of
|
||||
// context. The users have to check by themselves.
|
||||
hir::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
Ok(RootPlace {
|
||||
place_base: place.base,
|
||||
place_projection: place.projection,
|
||||
|
|
|
@ -271,7 +271,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::MutMutable
|
||||
_, _, hir::Mutability::Mutable
|
||||
) = local_decl.ty.kind {
|
||||
true
|
||||
} else {
|
||||
|
@ -593,7 +593,7 @@ fn suggest_ampmut<'tcx>(
|
|||
}
|
||||
|
||||
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
|
||||
assert_eq!(ty_mut.mutbl, hir::MutImmutable);
|
||||
assert_eq!(ty_mut.mutbl, hir::Mutability::Immutable);
|
||||
(highlight_span,
|
||||
if local_decl.ty.is_region_ptr() {
|
||||
format!("&mut {}", ty_mut.ty)
|
||||
|
@ -629,7 +629,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::MutImmutable,
|
||||
mutbl: hir::Mutability::Immutable,
|
||||
ref ty
|
||||
}) = field.ty.kind {
|
||||
// Get the snippets in two parts - the named lifetime (if there is one) and
|
||||
|
|
|
@ -2138,7 +2138,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::MutMutable,
|
||||
mutbl: hir::Mutability::Mutable,
|
||||
}) => ty_from,
|
||||
_ => {
|
||||
span_mirbug!(
|
||||
|
@ -2153,7 +2153,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let ty_to = match ty.kind {
|
||||
ty::RawPtr(ty::TypeAndMut {
|
||||
ty: ty_to,
|
||||
mutbl: hir::MutImmutable,
|
||||
mutbl: hir::Mutability::Immutable,
|
||||
}) => ty_to,
|
||||
_ => {
|
||||
span_mirbug!(
|
||||
|
@ -2187,7 +2187,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
let opt_ty_elem = match ty_from.kind {
|
||||
ty::RawPtr(
|
||||
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: array_ty }
|
||||
ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: array_ty }
|
||||
) => {
|
||||
match array_ty.kind {
|
||||
ty::Array(ty_elem, _) => Some(ty_elem),
|
||||
|
@ -2212,7 +2212,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
let ty_to = match ty.kind {
|
||||
ty::RawPtr(
|
||||
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: ty_to }
|
||||
ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: ty_to }
|
||||
) => {
|
||||
ty_to
|
||||
}
|
||||
|
@ -2250,7 +2250,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let cast_ty_to = CastTy::from_ty(ty);
|
||||
match (cast_ty_from, cast_ty_to) {
|
||||
(Some(CastTy::RPtr(ref_tm)), Some(CastTy::Ptr(ptr_tm))) => {
|
||||
if let hir::MutMutable = ptr_tm.mutbl {
|
||||
if let hir::Mutability::Mutable = ptr_tm.mutbl {
|
||||
if let Err(terr) = self.eq_types(
|
||||
ref_tm.ty,
|
||||
ptr_tm.ty,
|
||||
|
@ -2504,13 +2504,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
});
|
||||
|
||||
match mutbl {
|
||||
hir::Mutability::MutImmutable => {
|
||||
hir::Mutability::Immutable => {
|
||||
// Immutable reference. We don't need the base
|
||||
// to be valid for the entire lifetime of
|
||||
// the borrow.
|
||||
break;
|
||||
}
|
||||
hir::Mutability::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
// Mutable reference. We *do* need the base
|
||||
// to be valid, because after the base becomes
|
||||
// invalid, someone else can use our mutable deref.
|
||||
|
|
|
@ -57,7 +57,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
|
|||
|
||||
if *elem == ProjectionElem::Deref {
|
||||
let ty = Place::ty_from(&self.base, proj_base, body, tcx).ty;
|
||||
if let ty::RawPtr(..) | ty::Ref(_, _, hir::MutImmutable) = ty.kind {
|
||||
if let ty::RawPtr(..) | ty::Ref(_, _, hir::Mutability::Immutable) = ty.kind {
|
||||
// For both derefs of raw pointers and `&T`
|
||||
// references, the original path is `Copy` and
|
||||
// therefore not significant. In particular,
|
||||
|
|
|
@ -246,11 +246,11 @@ fn place_components_conflict<'tcx>(
|
|||
debug!("borrow_conflicts_with_place: shallow access behind ptr");
|
||||
return false;
|
||||
}
|
||||
(ProjectionElem::Deref, ty::Ref(_, _, hir::MutImmutable), _) => {
|
||||
(ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Immutable), _) => {
|
||||
// Shouldn't be tracked
|
||||
bug!("Tracking borrow behind shared reference.");
|
||||
}
|
||||
(ProjectionElem::Deref, ty::Ref(_, _, hir::MutMutable), AccessDepth::Drop) => {
|
||||
(ProjectionElem::Deref, ty::Ref(_, _, hir::Mutability::Mutable), 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");
|
||||
|
|
|
@ -149,7 +149,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
|
|||
ty::Ref(
|
||||
_, /*rgn*/
|
||||
_, /*ty*/
|
||||
hir::MutImmutable
|
||||
hir::Mutability::Immutable
|
||||
) => {
|
||||
// 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::MutMutable,
|
||||
hir::Mutability::Mutable,
|
||||
) => {
|
||||
self.next = Some(PlaceRef {
|
||||
base: cursor.base,
|
||||
|
|
|
@ -581,7 +581,7 @@ where
|
|||
if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
|
||||
debuginfo.debug_name = ident.name;
|
||||
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
|
||||
if bm == ty::BindByValue(hir::MutMutable) {
|
||||
if bm == ty::BindByValue(hir::Mutability::Mutable) {
|
||||
mutability = Mutability::Mut;
|
||||
} else {
|
||||
mutability = Mutability::Not;
|
||||
|
|
|
@ -860,8 +860,8 @@ impl ToBorrowKind for AutoBorrowMutability {
|
|||
impl ToBorrowKind for hir::Mutability {
|
||||
fn to_borrow_kind(&self) -> BorrowKind {
|
||||
match *self {
|
||||
hir::MutMutable => BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
hir::MutImmutable => BorrowKind::Shared,
|
||||
hir::Mutability::Mutable => BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
hir::Mutability::Immutable => BorrowKind::Shared,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1013,7 +1013,7 @@ fn convert_var(
|
|||
let ref_closure_ty = cx.tcx.mk_ref(region,
|
||||
ty::TypeAndMut {
|
||||
ty: closure_ty,
|
||||
mutbl: hir::MutImmutable,
|
||||
mutbl: hir::Mutability::Immutable,
|
||||
});
|
||||
Expr {
|
||||
ty: closure_ty,
|
||||
|
@ -1034,7 +1034,7 @@ fn convert_var(
|
|||
let ref_closure_ty = cx.tcx.mk_ref(region,
|
||||
ty::TypeAndMut {
|
||||
ty: closure_ty,
|
||||
mutbl: hir::MutMutable,
|
||||
mutbl: hir::Mutability::Mutable,
|
||||
});
|
||||
Expr {
|
||||
ty: closure_ty,
|
||||
|
|
|
@ -351,7 +351,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::MutImmutable) {
|
||||
if bm != ty::BindByValue(hir::Mutability::Immutable) {
|
||||
// Nothing to check.
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -591,14 +591,14 @@ 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::MutMutable) =>
|
||||
ty::BindByValue(hir::Mutability::Mutable) =>
|
||||
(Mutability::Mut, BindingMode::ByValue),
|
||||
ty::BindByValue(hir::MutImmutable) =>
|
||||
ty::BindByValue(hir::Mutability::Immutable) =>
|
||||
(Mutability::Not, BindingMode::ByValue),
|
||||
ty::BindByReference(hir::MutMutable) =>
|
||||
ty::BindByReference(hir::Mutability::Mutable) =>
|
||||
(Mutability::Not, BindingMode::ByRef(
|
||||
BorrowKind::Mut { allow_two_phase_borrow: false })),
|
||||
ty::BindByReference(hir::MutImmutable) =>
|
||||
ty::BindByReference(hir::Mutability::Immutable) =>
|
||||
(Mutability::Not, BindingMode::ByRef(
|
||||
BorrowKind::Shared)),
|
||||
};
|
||||
|
|
|
@ -214,16 +214,16 @@ for
|
|||
// const qualification enforces it. We can lift it in the future.
|
||||
match (self.mode, mutability) {
|
||||
// immutable references are fine everywhere
|
||||
(_, hir::Mutability::MutImmutable) => {},
|
||||
(_, hir::Mutability::Immutable) => {},
|
||||
// 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::MutMutable) => {},
|
||||
(InternMode::Static, hir::Mutability::Mutable) => {},
|
||||
// we statically prevent `&mut T` via `const_qualif` and double check this here
|
||||
(InternMode::ConstBase, hir::Mutability::MutMutable) |
|
||||
(InternMode::Const, hir::Mutability::MutMutable) => {
|
||||
(InternMode::ConstBase, hir::Mutability::Mutable) |
|
||||
(InternMode::Const, hir::Mutability::Mutable) => {
|
||||
match referenced_ty.kind {
|
||||
ty::Array(_, n)
|
||||
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
|
||||
|
@ -241,7 +241,7 @@ for
|
|||
// 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::MutMutable) => Mutability::Mutable,
|
||||
(Mutability::Mutable, hir::Mutability::Mutable) => Mutability::Mutable,
|
||||
_ => Mutability::Immutable,
|
||||
};
|
||||
// Recursing behind references changes the intern mode for constants in order to
|
||||
|
@ -273,9 +273,9 @@ pub fn intern_const_alloc_recursive(
|
|||
) -> InterpResult<'tcx> {
|
||||
let tcx = ecx.tcx;
|
||||
let (base_mutability, base_intern_mode) = match place_mut {
|
||||
Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static),
|
||||
Some(hir::Mutability::Immutable) => (Mutability::Immutable, InternMode::Static),
|
||||
// `static mut` doesn't care about interior mutability, it's mutable anyway
|
||||
Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::Static),
|
||||
Some(hir::Mutability::Mutable) => (Mutability::Mutable, InternMode::Static),
|
||||
// consts, promoteds. FIXME: what about array lengths, array initializers?
|
||||
None => (Mutability::Immutable, InternMode::ConstBase),
|
||||
};
|
||||
|
|
|
@ -456,7 +456,7 @@ impl CloneShimBuilder<'tcx> {
|
|||
Mutability::Not,
|
||||
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
|
||||
ty,
|
||||
mutbl: hir::Mutability::MutImmutable,
|
||||
mutbl: hir::Mutability::Immutable,
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -736,7 +736,7 @@ fn build_call_shim<'tcx>(
|
|||
Mutability::Not,
|
||||
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
|
||||
ty: sig.inputs()[0],
|
||||
mutbl: hir::Mutability::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
}),
|
||||
span
|
||||
));
|
||||
|
|
|
@ -82,8 +82,8 @@ impl ConstKind {
|
|||
|
||||
HirKind::Const => ConstKind::Const,
|
||||
|
||||
HirKind::Static(hir::MutImmutable) => ConstKind::Static,
|
||||
HirKind::Static(hir::MutMutable) => ConstKind::StaticMut,
|
||||
HirKind::Static(hir::Mutability::Immutable) => ConstKind::Static,
|
||||
HirKind::Static(hir::Mutability::Mutable) => ConstKind::StaticMut,
|
||||
};
|
||||
|
||||
Some(mode)
|
||||
|
|
|
@ -392,7 +392,7 @@ fn make_generator_state_argument_indirect<'tcx>(
|
|||
|
||||
let ref_gen_ty = tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: gen_ty,
|
||||
mutbl: hir::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
});
|
||||
|
||||
// Replace the by value generator argument
|
||||
|
@ -977,7 +977,7 @@ fn create_generator_drop_shim<'tcx>(
|
|||
mutability: Mutability::Mut,
|
||||
ty: tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: gen_ty,
|
||||
mutbl: hir::Mutability::MutMutable,
|
||||
mutbl: hir::Mutability::Mutable,
|
||||
}),
|
||||
user_ty: UserTypeProjections::none(),
|
||||
name: None,
|
||||
|
|
|
@ -1367,8 +1367,8 @@ fn determine_mode(tcx: TyCtxt<'_>, hir_id: HirId, def_id: DefId) -> Mode {
|
|||
hir::BodyOwnerKind::Fn if tcx.is_const_fn(def_id) => Mode::ConstFn,
|
||||
hir::BodyOwnerKind::Fn => Mode::NonConstFn,
|
||||
hir::BodyOwnerKind::Const => Mode::Const,
|
||||
hir::BodyOwnerKind::Static(hir::MutImmutable) => Mode::Static,
|
||||
hir::BodyOwnerKind::Static(hir::MutMutable) => Mode::StaticMut,
|
||||
hir::BodyOwnerKind::Static(hir::Mutability::Immutable) => Mode::Static,
|
||||
hir::BodyOwnerKind::Static(hir::Mutability::Mutable) => Mode::StaticMut,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,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::MutMutable) => return Err((
|
||||
ty::Ref(_, _, hir::Mutability::Mutable) => return Err((
|
||||
span,
|
||||
"mutable references in const fn are unstable".into(),
|
||||
)),
|
||||
|
|
|
@ -521,7 +521,7 @@ where
|
|||
|
||||
let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
|
||||
ty,
|
||||
mutbl: hir::Mutability::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
});
|
||||
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 ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
|
||||
ty: ety,
|
||||
mutbl: hir::Mutability::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
});
|
||||
let ptr = &Place::from(self.new_temp(ref_ty));
|
||||
let can_go = &Place::from(self.new_temp(tcx.types.bool));
|
||||
|
|
|
@ -243,7 +243,7 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
|
|||
ty::Float(..) |
|
||||
ty::RawPtr(..) |
|
||||
ty::Never |
|
||||
ty::Ref(_, _, hir::MutImmutable) => (),
|
||||
ty::Ref(_, _, hir::Mutability::Immutable) => (),
|
||||
|
||||
// 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::MutMutable) => (),
|
||||
ty::Ref(_, _, hir::Mutability::Mutable) => (),
|
||||
|
||||
ty::Bound(..) |
|
||||
ty::GeneratorWitness(..) |
|
||||
|
|
|
@ -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::MutMutable => 1,
|
||||
hir::MutImmutable => 0,
|
||||
hir::Mutability::Mutable => 1,
|
||||
hir::Mutability::Immutable => 0,
|
||||
});
|
||||
|
||||
if let Some(m) = contains_ref_bindings {
|
||||
|
|
|
@ -215,8 +215,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// For initial two-phase borrow
|
||||
// deployment, conservatively omit
|
||||
// overloaded function call ops.
|
||||
|
|
|
@ -627,7 +627,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
) -> Result<CastKind, CastError> {
|
||||
// array-ptr-cast.
|
||||
|
||||
if m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutImmutable {
|
||||
if m_expr.mutbl == hir::Mutability::Immutable && m_cast.mutbl == hir::Mutability::Immutable {
|
||||
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
|
||||
|
|
|
@ -99,10 +99,10 @@ fn coerce_mutbls<'tcx>(from_mutbl: hir::Mutability,
|
|||
to_mutbl: hir::Mutability)
|
||||
-> RelateResult<'tcx, ()> {
|
||||
match (from_mutbl, to_mutbl) {
|
||||
(hir::MutMutable, hir::MutMutable) |
|
||||
(hir::MutImmutable, hir::MutImmutable) |
|
||||
(hir::MutMutable, hir::MutImmutable) => Ok(()),
|
||||
(hir::MutImmutable, hir::MutMutable) => Err(TypeError::Mutability),
|
||||
(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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
if ty == a && mt_a.mutbl == hir::MutImmutable && autoderef.step_count() == 1 {
|
||||
if ty == a && mt_a.mutbl == hir::Mutability::Immutable && 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
|
||||
|
@ -422,7 +422,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::MutImmutable); // can only coerce &T -> &U
|
||||
assert_eq!(mt_b.mutbl, hir::Mutability::Immutable); // can only coerce &T -> &U
|
||||
return success(vec![], ty, obligations);
|
||||
}
|
||||
|
||||
|
@ -439,8 +439,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
_ => span_bug!(span, "expected a ref type, got {:?}", ty),
|
||||
};
|
||||
let mutbl = match mt_b.mutbl {
|
||||
hir::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
allow_two_phase_borrow: self.allow_two_phase,
|
||||
}
|
||||
};
|
||||
|
@ -485,8 +485,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// 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.
|
||||
|
|
|
@ -532,8 +532,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::MutImmutable) => "&self".to_owned(),
|
||||
ExplicitSelf::ByReference(_, hir::MutMutable) => "&mut self".to_owned(),
|
||||
ExplicitSelf::ByReference(_, hir::Mutability::Immutable) => "&self".to_owned(),
|
||||
ExplicitSelf::ByReference(_, hir::Mutability::Mutable) => "&mut self".to_owned(),
|
||||
_ => format!("self: {}", self_arg_ty)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -398,10 +398,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// bar(&x); // error, expected &mut
|
||||
// ```
|
||||
let ref_ty = match mutability {
|
||||
hir::Mutability::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
self.tcx.mk_mut_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
|
||||
}
|
||||
hir::Mutability::MutImmutable => {
|
||||
hir::Mutability::Immutable => {
|
||||
self.tcx.mk_imm_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
|
||||
}
|
||||
};
|
||||
|
@ -451,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
})) = self.tcx.hir().find(
|
||||
self.tcx.hir().get_parent_node(expr.hir_id),
|
||||
) {
|
||||
if mutability == hir::Mutability::MutMutable {
|
||||
if mutability == hir::Mutability::Mutable {
|
||||
// Found the following case:
|
||||
// fn foo(opt: &mut Option<String>){ opt = None }
|
||||
// --- ^^^^
|
||||
|
@ -470,12 +470,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
return Some(match mutability {
|
||||
hir::Mutability::MutMutable => (
|
||||
hir::Mutability::Mutable => (
|
||||
sp,
|
||||
"consider mutably borrowing here",
|
||||
format!("{}&mut {}", field_name, sugg_expr),
|
||||
),
|
||||
hir::Mutability::MutImmutable => (
|
||||
hir::Mutability::Immutable => (
|
||||
sp,
|
||||
"consider borrowing here",
|
||||
format!("{}&{}", field_name, sugg_expr),
|
||||
|
|
|
@ -363,8 +363,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// (It shouldn't actually matter for unary ops whether
|
||||
// we enable two-phase borrows or not, since a unary
|
||||
// op has no additional operands.)
|
||||
|
|
|
@ -172,7 +172,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::MutImmutable
|
||||
mutbl: hir::Mutability::Immutable
|
||||
}), tcx.types.i32],
|
||||
tcx.mk_unit())
|
||||
}
|
||||
|
@ -188,13 +188,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutImmutable
|
||||
mutbl: hir::Mutability::Immutable
|
||||
}),
|
||||
tcx.types.isize
|
||||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutImmutable
|
||||
mutbl: hir::Mutability::Immutable
|
||||
}))
|
||||
}
|
||||
"copy" | "copy_nonoverlapping" => {
|
||||
|
@ -202,11 +202,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutImmutable
|
||||
mutbl: hir::Mutability::Immutable
|
||||
}),
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
}),
|
||||
tcx.types.usize,
|
||||
],
|
||||
|
@ -217,11 +217,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
}),
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutImmutable
|
||||
mutbl: hir::Mutability::Immutable
|
||||
}),
|
||||
tcx.types.usize,
|
||||
],
|
||||
|
@ -232,7 +232,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: param(0),
|
||||
mutbl: hir::MutMutable
|
||||
mutbl: hir::Mutability::Mutable
|
||||
}),
|
||||
tcx.types.u8,
|
||||
tcx.types.usize,
|
||||
|
@ -357,14 +357,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
}
|
||||
|
||||
"va_start" | "va_end" => {
|
||||
match mk_va_list_ty(hir::MutMutable) {
|
||||
match mk_va_list_ty(hir::Mutability::Mutable) {
|
||||
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::MutImmutable) {
|
||||
match mk_va_list_ty(hir::Mutability::Immutable) {
|
||||
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())
|
||||
|
@ -374,7 +374,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
|||
}
|
||||
|
||||
"va_arg" => {
|
||||
match mk_va_list_ty(hir::MutMutable) {
|
||||
match mk_va_list_ty(hir::Mutability::Mutable) {
|
||||
Some((va_list_ref_ty, _)) => (1, vec![va_list_ref_ty], param(0)),
|
||||
None => bug!("`va_list` language item needed for C-variadic intrinsics")
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||
sig: method_sig,
|
||||
};
|
||||
|
||||
if let Some(hir::MutMutable) = pick.autoref {
|
||||
if let Some(hir::Mutability::Mutable) = 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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// 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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// For initial two-phase borrow
|
||||
// deployment, conservatively omit
|
||||
// overloaded operators.
|
||||
|
|
|
@ -606,11 +606,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::MutImmutable }) => {
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Immutable }) => {
|
||||
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::MutMutable }) => {
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mutable }) => {
|
||||
let lang_def_id = lang_items.mut_ptr_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
|
@ -1045,8 +1045,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::MutImmutable).or_else(|| {
|
||||
self.pick_autorefd_method(step, self_ty, hir::MutMutable)
|
||||
self.pick_autorefd_method(step, self_ty, hir::Mutability::Immutable).or_else(|| {
|
||||
self.pick_autorefd_method(step, self_ty, hir::Mutability::Mutable)
|
||||
})})})
|
||||
.next()
|
||||
}
|
||||
|
|
|
@ -387,8 +387,8 @@ pub enum Needs {
|
|||
impl Needs {
|
||||
fn maybe_mut_place(m: hir::Mutability) -> Self {
|
||||
match m {
|
||||
hir::MutMutable => Needs::MutPlace,
|
||||
hir::MutImmutable => Needs::None,
|
||||
hir::Mutability::Mutable => Needs::MutPlace,
|
||||
hir::Mutability::Immutable => Needs::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1281,7 +1281,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::MutImmutable &&
|
||||
mutbl == hir::Mutability::Immutable &&
|
||||
*region != RegionKind::ReStatic
|
||||
},
|
||||
_ => false,
|
||||
|
@ -3197,8 +3197,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// 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
|
||||
|
|
|
@ -204,8 +204,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// Allow two-phase borrows for binops in initial deployment
|
||||
// since they desugar to methods
|
||||
allow_two_phase_borrow: AllowTwoPhase::Yes,
|
||||
|
@ -221,8 +221,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::MutImmutable => AutoBorrowMutability::Immutable,
|
||||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
|
||||
hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
|
||||
// Allow two-phase borrows for binops in initial deployment
|
||||
// since they desugar to methods
|
||||
allow_two_phase_borrow: AllowTwoPhase::Yes,
|
||||
|
|
|
@ -30,7 +30,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::MutImmutable);
|
||||
let def_bm = BindingMode::BindByValue(hir::Mutability::Immutable);
|
||||
self.check_pat(pat, expected, def_bm, discrim_span);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
//
|
||||
// See issue #46688.
|
||||
let def_bm = match pat.kind {
|
||||
PatKind::Ref(..) => ty::BindByValue(hir::MutImmutable),
|
||||
PatKind::Ref(..) => ty::BindByValue(hir::Mutability::Immutable),
|
||||
_ => def_bm,
|
||||
};
|
||||
(expected, def_bm)
|
||||
|
@ -275,10 +275,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::MutMutable) => inner_mutability,
|
||||
ty::BindByReference(hir::Mutability::Mutable) => inner_mutability,
|
||||
// Once a `ref`, always a `ref`.
|
||||
// This is because a `& &mut` cannot mutate the underlying value.
|
||||
ty::BindByReference(m @ hir::Mutability::MutImmutable) => m,
|
||||
ty::BindByReference(m @ hir::Mutability::Immutable) => m,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -358,7 +358,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::MutImmutable, hir::MutMutable) {
|
||||
if (mt_a.mutbl, mt_b.mutbl) == (hir::Mutability::Immutable, hir::Mutability::Mutable) {
|
||||
infcx.report_mismatched_types(&cause,
|
||||
mk_ptr(mt_b.ty),
|
||||
target,
|
||||
|
|
|
@ -107,7 +107,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
"[T]",
|
||||
item.span);
|
||||
}
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Immutable }) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
lang_items.const_ptr_impl(),
|
||||
None,
|
||||
|
@ -115,7 +115,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
"*const T",
|
||||
item.span);
|
||||
}
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mutable }) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
lang_items.mut_ptr_impl(),
|
||||
None,
|
||||
|
|
|
@ -454,12 +454,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
mt: &ty::TypeAndMut<'tcx>,
|
||||
variance: VarianceTermPtr<'a>) {
|
||||
match mt.mutbl {
|
||||
hir::MutMutable => {
|
||||
hir::Mutability::Mutable => {
|
||||
let invar = self.invariant(variance);
|
||||
self.add_constraints_from_ty(current, mt.ty, invar);
|
||||
}
|
||||
|
||||
hir::MutImmutable => {
|
||||
hir::Mutability::Immutable => {
|
||||
self.add_constraints_from_ty(current, mt.ty, variance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3859,8 +3859,8 @@ pub enum Mutability {
|
|||
impl Clean<Mutability> for hir::Mutability {
|
||||
fn clean(&self, _: &DocContext<'_>) -> Mutability {
|
||||
match self {
|
||||
&hir::MutMutable => Mutable,
|
||||
&hir::MutImmutable => Immutable,
|
||||
&hir::Mutability::Mutable => Mutable,
|
||||
&hir::Mutability::Immutable => Immutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -733,6 +733,30 @@ pub enum Mutability {
|
|||
Immutable,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn invert(self) -> Self {
|
||||
match self {
|
||||
Mutability::Mutable => Mutability::Immutable,
|
||||
Mutability::Immutable => Mutability::Mutable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefix_str(&self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Mutable => "mut ",
|
||||
Mutability::Immutable => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||
pub enum BinOpKind {
|
||||
/// The `+` operator (addition)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue