From ed640c6a27aca3b2446ab8d6f00df0a2d78f1192 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 17:44:11 +0100 Subject: [PATCH 1/8] Merge hir::Mutability into ast::Mutability. --- src/librustc/hir/lowering.rs | 11 ++----- src/librustc/hir/lowering/expr.rs | 3 +- src/librustc/hir/lowering/item.rs | 4 +-- src/librustc/hir/mod.rs | 33 +------------------ src/librustc/hir/pat_util.rs | 4 +-- src/librustc/hir/print.rs | 16 ++++----- src/librustc/lint/internal.rs | 2 +- src/librustc/middle/mem_categorization.rs | 12 +++---- src/librustc/mir/mod.rs | 4 +-- src/librustc/mir/tcx.rs | 8 ++--- src/librustc/traits/error_reporting.rs | 6 ++-- src/librustc/traits/select.rs | 4 +-- src/librustc/ty/adjustment.rs | 8 ++--- src/librustc/ty/binding.rs | 8 ++--- src/librustc/ty/context.rs | 8 ++--- src/librustc/ty/error.rs | 2 +- src/librustc/ty/layout.rs | 4 +-- src/librustc/ty/mod.rs | 10 +++--- src/librustc/ty/print/obsolete.rs | 4 +-- src/librustc/ty/print/pretty.rs | 4 +-- src/librustc/ty/relate.rs | 4 +-- src/librustc/ty/sty.rs | 6 ++-- src/librustc/ty/util.rs | 4 +-- src/librustc_codegen_llvm/intrinsic.rs | 2 +- .../debuginfo/type_names.rs | 4 +-- src/librustc_codegen_utils/symbol_names/v0.rs | 8 ++--- src/librustc_lint/builtin.rs | 4 +-- src/librustc_metadata/rmeta/decoder.rs | 4 +-- src/librustc_metadata/rmeta/encoder.rs | 8 ++--- src/librustc_mir/borrow_check/mod.rs | 10 +++--- .../borrow_check/mutability_errors.rs | 6 ++-- .../borrow_check/nll/type_check/mod.rs | 14 ++++---- src/librustc_mir/borrow_check/place_ext.rs | 2 +- .../borrow_check/places_conflict.rs | 4 +-- src/librustc_mir/borrow_check/prefixes.rs | 4 +-- src/librustc_mir/build/mod.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 8 ++--- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/hair/pattern/mod.rs | 8 ++--- src/librustc_mir/interpret/intern.rs | 14 ++++---- src/librustc_mir/shim.rs | 4 +-- .../transform/check_consts/mod.rs | 4 +-- src/librustc_mir/transform/generator.rs | 4 +-- src/librustc_mir/transform/qualify_consts.rs | 4 +-- .../transform/qualify_min_const_fn.rs | 2 +- src/librustc_mir/util/elaborate_drops.rs | 4 +-- .../chalk_context/program_clauses/builtin.rs | 4 +-- src/librustc_typeck/check/_match.rs | 4 +-- src/librustc_typeck/check/callee.rs | 4 +-- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/coercion.rs | 20 +++++------ src/librustc_typeck/check/compare_method.rs | 4 +-- src/librustc_typeck/check/demand.rs | 10 +++--- src/librustc_typeck/check/expr.rs | 4 +-- src/librustc_typeck/check/intrinsic.rs | 22 ++++++------- src/librustc_typeck/check/method/confirm.rs | 10 +++--- src/librustc_typeck/check/method/probe.rs | 8 ++--- src/librustc_typeck/check/mod.rs | 10 +++--- src/librustc_typeck/check/op.rs | 8 ++--- src/librustc_typeck/check/pat.rs | 8 ++--- src/librustc_typeck/coherence/builtin.rs | 2 +- .../coherence/inherent_impls.rs | 4 +-- src/librustc_typeck/variance/constraints.rs | 4 +-- src/librustdoc/clean/mod.rs | 4 +-- src/libsyntax/ast.rs | 24 ++++++++++++++ 65 files changed, 218 insertions(+), 233 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 278f45371b151..a22db239d2829 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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 { // 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)), diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 73db762a64bda..74a2be8cf56cf 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -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 { - 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 { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 7aa1aa8bb514a..10c2342919ec2 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -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"), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 83f68e210bd94..43f1844b9538f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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>, Option>, HirVec>), } -#[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). diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index feb0d97822c42..c2bd998d5e998 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -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), _ => {} } }); diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index d5fdde8732929..d460e23ec6794 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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 => {}, } } diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index a08722e940295..1c5f86f480147 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -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; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index cbf336fdbe2f3..3510fe4d12359 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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 = Result; 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 diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2eaf05beb2e9f..220362868abdf 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -491,8 +491,8 @@ pub enum Mutability { impl From 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, } } } diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index e87aabf9a0566..c65f2b0478670 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -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, } } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 23c4ec062ea3f..f77db9621351e 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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( diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index d8a27f1e04051..f5ac1533d060b 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -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 diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index 1d5ed4273abf6..f5ab1eb38c3c6 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -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 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, } } } diff --git a/src/librustc/ty/binding.rs b/src/librustc/ty/binding.rs index 5570144489cdf..905d7abb7828c 100644 --- a/src/librustc/ty/binding.rs +++ b/src/librustc/ty/binding.rs @@ -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), } } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 0906d9ebd8e7f..55f85809a406d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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] diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 723ed6b03dadc..c61d559af53f5 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -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 { diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 4bf500555f14b..e5f22277f8e31 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -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 diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1b1cc423fd457..e4ed1cd198e52 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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, } } diff --git a/src/librustc/ty/print/obsolete.rs b/src/librustc/ty/print/obsolete.rs index ddbba972e51a7..0389218b61d24 100644 --- a/src/librustc/ty/print/obsolete.rs +++ b/src/librustc/ty/print/obsolete.rs @@ -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); diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 4c75e47401138..568f18f48be20 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -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)) } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 1da65f4b51d36..9b5cdc489a8b5 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -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 }) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 3a9994ac64c77..422e48f34de49 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -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 }), diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 5555dace45bfa..d46320abff2ad 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -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. diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 6935e09054d0b..e1ce7f622e2ef 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -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))), _ => { diff --git a/src/librustc_codegen_ssa/debuginfo/type_names.rs b/src/librustc_codegen_ssa/debuginfo/type_names.rs index f40b942b1e322..8ff08e832dc17 100644 --- a/src/librustc_codegen_ssa/debuginfo/type_names.rs +++ b/src/librustc_codegen_ssa/debuginfo/type_names.rs @@ -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); diff --git a/src/librustc_codegen_utils/symbol_names/v0.rs b/src/librustc_codegen_utils/symbol_names/v0.rs index 0fe4c7c674873..1dfcc21f3903d 100644 --- a/src/librustc_codegen_utils/symbol_names/v0.rs +++ b/src/librustc_codegen_utils/symbol_names/v0.rs @@ -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)?; } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 9d1fa4613b8d4..38624034022f0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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); } } diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 40ec04537b0e6..7cebf2512d645 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -1236,9 +1236,9 @@ impl<'a, 'tcx> CrateMetadata { fn static_mutability(&self, id: DefIndex) -> Option { 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, } } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index ad1ab16a41074..908561f55fd8f 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -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] <- diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index c3369e872151a..0d3b35a228c5f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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, diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 68b33331a1ffb..11e89de810e5b 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -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 diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index d5fd214a9d988..37fc0b09e5b9f 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -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. diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs index f437c7172966b..f0d2927ba45e7 100644 --- a/src/librustc_mir/borrow_check/place_ext.rs +++ b/src/librustc_mir/borrow_check/place_ext.rs @@ -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, diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index 264e4807af07e..36586e80ee0f0 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -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"); diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index 1be1fcef61b6e..57833cac9cb44 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -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, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index e2541eeedbc06..fb605bb2b557b 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -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; diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index fbdc4ceeeede8..2ff690b7ccc9f 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -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, diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 29423536e653a..52af8c13e78be 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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; } diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 477ad10460f6b..0885c9578294d 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -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)), }; diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index a7de533506c01..68bb0a3e435df 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -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), }; diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 177639956f717..2913d6e59eb3f 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -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 )); diff --git a/src/librustc_mir/transform/check_consts/mod.rs b/src/librustc_mir/transform/check_consts/mod.rs index 364e23ed8d0f9..a5b711e75a603 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -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) diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 911901be36b24..1170e7cc2d885 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -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, diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 5ad5363768d34..39720af4cb5d6 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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, } } diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index ab4b6153aa135..83bde5ed34eae 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -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(), )), diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index a1846a1fb5eaf..67e5bfafafd12 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -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)); diff --git a/src/librustc_traits/chalk_context/program_clauses/builtin.rs b/src/librustc_traits/chalk_context/program_clauses/builtin.rs index 13bbe021ccf34..3ad68d4a9dfa6 100644 --- a/src/librustc_traits/chalk_context/program_clauses/builtin.rs +++ b/src/librustc_traits/chalk_context/program_clauses/builtin.rs @@ -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(..) | diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index a1daed005f302..6a35f9b845258 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -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 { diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 300b730b5bbfa..c195e91a52be7 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -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. diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 6ef3ec00dc3d3..81732ed4ba347 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -627,7 +627,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { ) -> Result { // 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 diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index f79351dc90310..a105755ca9aac 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -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. diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index af0943db4cc9e..2f0b1c358f08d 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -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) } }) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 309e73f57c964..5d9b3a8fba4d7 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -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){ 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), diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index bc1189e443e28..cfe36b57c2da1 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -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.) diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 693f6f05fab28..1a1b98f582ff2 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -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") } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 59636d32bc037..4bdab84faf123 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -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. diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 593cf77a4a6c7..7ea7dba5a2822 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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() } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 39a7996df0cdc..098300f1740bc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 819c347d3ae95..81a3159790559 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -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, diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index a520ae13c58fb..a4c9862bc742d 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -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) { - 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, }); } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 1e3939cbfcdf2..d613abc435288 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -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, diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 90cedb455e3dd..5daa8f5d3191b 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -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, diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 4431abdaf50a0..1e1be72221fcb 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -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); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6696447ceae57..97f41fdc5ba46 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3859,8 +3859,8 @@ pub enum Mutability { impl Clean for hir::Mutability { fn clean(&self, _: &DocContext<'_>) -> Mutability { match self { - &hir::MutMutable => Mutable, - &hir::MutImmutable => Immutable, + &hir::Mutability::Mutable => Mutable, + &hir::Mutability::Immutable => Immutable, } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b57d223899184..b0f83f03f626b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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) From 1f21c080ebee10e0ad14197e7d7dbfcb687e303a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 17:54:28 +0100 Subject: [PATCH 2/8] Merge hir::Constness into ast::Constness. --- src/librustc/hir/lowering/item.rs | 11 ++--------- src/librustc/hir/mod.rs | 8 +------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 10c2342919ec2..2d03e92139e40 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -19,7 +19,7 @@ use smallvec::SmallVec; use syntax::attr; use syntax::ast::*; use syntax::visit::{self, Visitor}; -use syntax::source_map::{respan, DesugaringKind, Spanned}; +use syntax::source_map::{respan, DesugaringKind}; use syntax::symbol::{kw, sym}; use syntax_pos::Span; @@ -1286,7 +1286,7 @@ impl LoweringContext<'_> { hir::FnHeader { unsafety: self.lower_unsafety(h.unsafety), asyncness: self.lower_asyncness(h.asyncness.node), - constness: self.lower_constness(h.constness), + constness: h.constness.node, abi: self.lower_abi(h.abi), } } @@ -1318,13 +1318,6 @@ impl LoweringContext<'_> { } } - fn lower_constness(&mut self, c: Spanned) -> hir::Constness { - match c.node { - Constness::Const => hir::Constness::Const, - Constness::NotConst => hir::Constness::NotConst, - } - } - fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync { match a { IsAsync::Async { .. } => hir::IsAsync::Async, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 43f1844b9538f..63d4ba6d8b758 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +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; +pub use syntax::ast::{Mutability, Constness}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -2170,12 +2170,6 @@ impl Unsafety { } } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum Constness { - Const, - NotConst, -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Defaultness { Default { has_value: bool }, From f03cbc313ddc16d7aba6c21c197a52ee4d2e85e9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 18:01:12 +0100 Subject: [PATCH 3/8] Merge hir::Unsafety into ast::Unsafety. --- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/lowering/item.rs | 13 +++-------- src/librustc/hir/mod.rs | 27 +---------------------- src/libsyntax/ast.rs | 36 ++++++++++++++++++++----------- 4 files changed, 28 insertions(+), 50 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a22db239d2829..02afdc27acdca 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1213,7 +1213,7 @@ impl<'a> LoweringContext<'a> { &NodeMap::default(), ImplTraitContext::disallowed(), ), - unsafety: this.lower_unsafety(f.unsafety), + unsafety: f.unsafety, abi: this.lower_abi(f.abi), decl: this.lower_fn_decl(&f.decl, None, false, None), param_names: this.lower_fn_params_to_names(&f.decl), diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 2d03e92139e40..bf288f271a69f 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -433,7 +433,7 @@ impl LoweringContext<'_> { ); hir::ItemKind::Impl( - self.lower_unsafety(unsafety), + unsafety, self.lower_impl_polarity(polarity), self.lower_defaultness(defaultness, true /* [1] */), generics, @@ -450,7 +450,7 @@ impl LoweringContext<'_> { .collect(); hir::ItemKind::Trait( self.lower_is_auto(is_auto), - self.lower_unsafety(unsafety), + unsafety, self.lower_generics(generics, ImplTraitContext::disallowed()), bounds, items, @@ -1284,7 +1284,7 @@ impl LoweringContext<'_> { fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader { hir::FnHeader { - unsafety: self.lower_unsafety(h.unsafety), + unsafety: h.unsafety, asyncness: self.lower_asyncness(h.asyncness.node), constness: h.constness.node, abi: self.lower_abi(h.abi), @@ -1311,13 +1311,6 @@ impl LoweringContext<'_> { .emit(); } - pub(super) fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety { - match u { - Unsafety::Unsafe => hir::Unsafety::Unsafe, - Unsafety::Normal => hir::Unsafety::Normal, - } - } - fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync { match a { IsAsync::Async { .. } => hir::IsAsync::Async, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 63d4ba6d8b758..645d7b5fdb015 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +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, Constness}; +pub use syntax::ast::{Mutability, Constness, Unsafety}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -2154,22 +2154,6 @@ pub enum IsAsync { NotAsync, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, - RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Unsafety { - Unsafe, - Normal, -} - -impl Unsafety { - pub fn prefix_str(&self) -> &'static str { - match self { - Unsafety::Unsafe => "unsafe ", - Unsafety::Normal => "", - } - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Defaultness { Default { has_value: bool }, @@ -2196,15 +2180,6 @@ impl Defaultness { } } -impl fmt::Display for Unsafety { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match self { - Unsafety::Normal => "normal", - Unsafety::Unsafe => "unsafe", - }) - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] pub enum ImplPolarity { /// `impl Trait for Type` diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b0f83f03f626b..887d7beed6ded 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1991,12 +1991,34 @@ pub enum IsAuto { No, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, Debug)] pub enum Unsafety { Unsafe, Normal, } +impl Unsafety { + pub fn prefix_str(&self) -> &'static str { + match self { + Unsafety::Unsafe => "unsafe ", + Unsafety::Normal => "", + } + } +} + +impl fmt::Display for Unsafety { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt( + match *self { + Unsafety::Normal => "normal", + Unsafety::Unsafe => "unsafe", + }, + f, + ) + } +} + #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] pub enum IsAsync { Async { @@ -2041,18 +2063,6 @@ pub enum Defaultness { Final, } -impl fmt::Display for Unsafety { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt( - match *self { - Unsafety::Normal => "normal", - Unsafety::Unsafe => "unsafe", - }, - f, - ) - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub enum ImplPolarity { /// `impl Trait for Type` From 5b30da10b64cf9b3567554e651bb6a9d62ad554b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 18:06:57 +0100 Subject: [PATCH 4/8] Merge hir::GeneratorMovability into ast::Movability. --- src/librustc/hir/lowering/expr.rs | 9 +++------ src/librustc/hir/mod.rs | 17 +++-------------- src/librustc/ich/impls_syntax.rs | 1 + src/librustc/mir/mod.rs | 2 +- src/librustc/traits/select.rs | 4 ++-- src/librustc/ty/context.rs | 2 +- src/librustc/ty/print/pretty.rs | 7 +++---- src/librustc/ty/sty.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/hair/mod.rs | 2 +- src/librustc_mir/transform/generator.rs | 2 +- src/librustc_passes/loops.rs | 4 ++-- src/librustc_traits/generic_types.rs | 2 +- src/librustc_typeck/check/closure.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/libsyntax/ast.rs | 8 ++++++-- 17 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 74a2be8cf56cf..6c92a997b1f98 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -494,7 +494,7 @@ impl LoweringContext<'_> { decl, body_id, span, - Some(hir::GeneratorMovability::Static) + Some(hir::Movability::Static) ); let generator = hir::Expr { hir_id: self.lower_node_id(closure_node_id), @@ -725,7 +725,7 @@ impl LoweringContext<'_> { fn_decl_span: Span, generator_kind: Option, movability: Movability, - ) -> Option { + ) -> Option { match generator_kind { Some(hir::GeneratorKind::Gen) => { if !decl.inputs.is_empty() { @@ -736,10 +736,7 @@ impl LoweringContext<'_> { "generators cannot have explicit parameters" ); } - Some(match movability { - Movability::Movable => hir::GeneratorMovability::Movable, - Movability::Static => hir::GeneratorMovability::Static, - }) + Some(movability) }, Some(hir::GeneratorKind::Async(_)) => { bug!("non-`async` closure body turned `async` during lowering"); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 645d7b5fdb015..297022600f9ee 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +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, Constness, Unsafety}; +pub use syntax::ast::{Mutability, Constness, Unsafety, Movability}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -1628,8 +1628,8 @@ pub enum ExprKind { /// The `Span` is the argument block `|...|`. /// /// This may also be a generator literal or an `async block` as indicated by the - /// `Option`. - Closure(CaptureClause, P, BodyId, Span, Option), + /// `Option`. + Closure(CaptureClause, P, BodyId, Span, Option), /// A block (e.g., `'label: { ... }`). Block(P, Option