Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ast::Mutability and mir::Mutability #67355

Merged
merged 3 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ impl<'a> LoweringContext<'a> {
let is_mutable_pat = match arg.pat.kind {
PatKind::Ident(BindingMode::ByValue(mt), _, _) |
PatKind::Ident(BindingMode::ByRef(mt), _, _) =>
mt == Mutability::Mutable,
mt == Mutability::Mut,
_ => false,
};

Expand All @@ -2265,7 +2265,7 @@ impl<'a> LoweringContext<'a> {
// the case where we have a mutable pattern to a reference as that would
// no longer be an `ImplicitSelf`.
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() &&
mt.mutbl == ast::Mutability::Mutable =>
mt.mutbl == ast::Mutability::Mut =>
hir::ImplicitSelfKind::MutRef,
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() =>
hir::ImplicitSelfKind::ImmRef,
Expand Down Expand Up @@ -3069,10 +3069,10 @@ impl<'a> LoweringContext<'a> {

fn lower_binding_mode(&mut self, b: &BindingMode) -> hir::BindingAnnotation {
match *b {
BindingMode::ByValue(Mutability::Immutable) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Immutable) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mutable) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mutable) => hir::BindingAnnotation::RefMut,
BindingMode::ByValue(Mutability::Not) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Not) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mut) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mut) => hir::BindingAnnotation::RefMut,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ impl LoweringContext<'_> {
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
self.expr(
span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, e),
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
ThinVec::new(),
)
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ impl hir::Pat {
self.each_binding(|annotation, _, _, _| {
match annotation {
hir::BindingAnnotation::Ref => match result {
None | Some(hir::Mutability::Immutable) =>
result = Some(hir::Mutability::Immutable),
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
_ => {}
}
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
_ => {}
}
});
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -502,7 +502,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Static(ref ty, m, expr) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -1632,11 +1632,11 @@ impl<'a> State<'a> {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Immutable, false);
self.print_mutability(hir::Mutability::Not, false);
}
hir::BindingAnnotation::RefMut => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Mutable, false);
self.print_mutability(hir::Mutability::Mut, false);
}
hir::BindingAnnotation::Unannotated => {}
hir::BindingAnnotation::Mutable => {
Expand Down Expand Up @@ -2065,8 +2065,8 @@ impl<'a> State<'a> {

pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
match mutbl {
hir::Mutability::Mutable => self.word_nbsp("mut"),
hir::Mutability::Immutable => if print_const { self.word_nbsp("const") },
hir::Mutability::Mut => self.word_nbsp("mut"),
hir::Mutability::Not => if print_const { self.word_nbsp("const") },
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
}
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => {
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) {
if cx.tcx.impl_trait_ref(impl_did).is_some() {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, true),
size,
align,
mutability: Mutability::Immutable,
mutability: Mutability::Not,
extra: (),
}
}
Expand All @@ -123,7 +123,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, false),
size,
align,
mutability: Mutability::Mutable,
mutability: Mutability::Mut,
extra: (),
}
}
Expand Down
19 changes: 2 additions & 17 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::ops::Index;
use std::slice;
use std::{iter, mem, option, u32};
use syntax::ast::Name;
pub use syntax::ast::Mutability;
use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};

Expand Down Expand Up @@ -396,22 +397,7 @@ pub struct SourceInfo {
}

///////////////////////////////////////////////////////////////////////////
// Mutability and borrow kinds

#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
pub enum Mutability {
Mut,
Not,
}

impl From<Mutability> for hir::Mutability {
fn from(m: Mutability) -> Self {
match m {
Mutability::Mut => hir::Mutability::Mutable,
Mutability::Not => hir::Mutability::Immutable,
}
}
}
// Borrow kinds

#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, HashStable,
Expand Down Expand Up @@ -2886,7 +2872,6 @@ pub enum ClosureOutlivesSubject<'tcx> {
CloneTypeFoldableAndLiftImpls! {
BlockTailInfo,
MirPhase,
Mutability,
SourceInfo,
FakeReadCause,
RetagKind,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,17 @@ impl<'tcx> BinOp {
impl BorrowKind {
pub fn to_mutbl_lossy(self) -> hir::Mutability {
match self {
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
BorrowKind::Shared => hir::Mutability::Immutable,
BorrowKind::Mut { .. } => hir::Mutability::Mut,
BorrowKind::Shared => hir::Mutability::Not,

// We have no type corresponding to a unique imm borrow, so
// use `&mut`. It gives all the capabilities of an `&uniq`
// and hence is a safe "over approximation".
BorrowKind::Unique => hir::Mutability::Mutable,
BorrowKind::Unique => hir::Mutability::Mut,

// We have no type corresponding to a shallow borrow, so use
// `&` as an approximation.
BorrowKind::Shallow => hir::Mutability::Immutable,
BorrowKind::Shallow => hir::Mutability::Not,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
let trait_type = match mutability {
hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
};

let new_obligation = self.mk_obligation_for_def_id(
Expand All @@ -1565,7 +1565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let sp = self.tcx.sess.source_map()
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
if points_at_arg &&
mutability == hir::Mutability::Immutable &&
mutability == hir::Mutability::Not &&
refs_number > 0
{
err.span_suggestion(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Char
| ty::RawPtr(..)
| ty::Never
| ty::Ref(_, _, hir::Mutability::Immutable) => {
| ty::Ref(_, _, hir::Mutability::Not) => {
// Implementations provided in libcore
None
}
Expand All @@ -2633,7 +2633,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::Foreign(..)
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
| ty::Ref(_, _, hir::Mutability::Mut) => None,

ty::Array(element_ty, _) => {
// (*) binder moved here
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
impl<'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
hir::Mutability::Not => tcx.lang_items().deref_trait(),
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait()
};
let method_def_id = tcx.associated_items(trait_def_id.unwrap())
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
Expand Down Expand Up @@ -138,15 +138,15 @@ pub enum AllowTwoPhase {

#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum AutoBorrowMutability {
Mutable { allow_two_phase_borrow: AllowTwoPhase },
Immutable,
Mut { allow_two_phase_borrow: AllowTwoPhase },
Not,
}

impl From<AutoBorrowMutability> for hir::Mutability {
fn from(m: AutoBorrowMutability) -> Self {
match m {
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
AutoBorrowMutability::Mut { .. } => hir::Mutability::Mut,
AutoBorrowMutability::Not => hir::Mutability::Not,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
impl BindingMode {
pub fn convert(ba: BindingAnnotation) -> BindingMode {
match ba {
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
Mutable => BindingMode::BindByValue(Mutability::Mutable),
Ref => BindingMode::BindByReference(Mutability::Immutable),
RefMut => BindingMode::BindByReference(Mutability::Mutable),
Unannotated => BindingMode::BindByValue(Mutability::Not),
Mutable => BindingMode::BindByValue(Mutability::Mut),
Ref => BindingMode::BindByReference(Mutability::Not),
RefMut => BindingMode::BindByReference(Mutability::Mut),
}
}
}
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2406,22 +2406,22 @@ impl<'tcx> TyCtxt<'tcx> {

#[inline]
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
}

#[inline]
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
}

#[inline]
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
}

#[inline]
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'tcx> ty::TyS<'tcx> {
format!("`&{}`", tymut_string).into()
} else { // Unknown type name, it's long or has type arguments
match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference",
}.into()
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Slice(_) => "slice".into(),
ty::RawPtr(_) => "raw pointer".into(),
ty::Ref(.., mutbl) => match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference"
}.into(),
ty::FnDef(..) => "fn item".into(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,12 +2221,12 @@ where
let tcx = cx.tcx();
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
let kind = match mt {
hir::Mutability::Immutable => if is_freeze {
hir::Mutability::Not => if is_freeze {
PointerKind::Frozen
} else {
PointerKind::Shared
},
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
// Previously we would only emit noalias annotations for LLVM >= 6 or in
// panic=abort mode. That was deemed right, as prior versions had many bugs
// in conjunction with unwinding, but later versions didn’t seem to have
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2657,8 +2657,8 @@ impl<'tcx> TyS<'tcx> {
impl BorrowKind {
pub fn from_mutbl(m: hir::Mutability) -> BorrowKind {
match m {
hir::Mutability::Mutable => MutBorrow,
hir::Mutability::Immutable => ImmBorrow,
hir::Mutability::Mut => MutBorrow,
hir::Mutability::Not => ImmBorrow,
}
}

Expand All @@ -2668,13 +2668,13 @@ impl BorrowKind {
/// question.
pub fn to_mutbl_lossy(self) -> hir::Mutability {
match self {
MutBorrow => hir::Mutability::Mutable,
ImmBorrow => hir::Mutability::Immutable,
MutBorrow => hir::Mutability::Mut,
ImmBorrow => hir::Mutability::Not,

// We have no type corresponding to a unique imm borrow, so
// use `&mut`. It gives all the capabilities of an `&uniq`
// and hence is a safe "over approximation".
UniqueImmBorrow => hir::Mutability::Mutable,
UniqueImmBorrow => hir::Mutability::Mut,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/print/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl DefPathBasedNames<'tcx> {
ty::RawPtr(ty::TypeAndMut { ty: inner_type, mutbl }) => {
output.push('*');
match mutbl {
hir::Mutability::Immutable => output.push_str("const "),
hir::Mutability::Mutable => output.push_str("mut "),
hir::Mutability::Not => output.push_str("const "),
hir::Mutability::Mut => output.push_str("mut "),
}

self.push_type_name(inner_type, output, debug);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ pub trait PrettyPrinter<'tcx>:
ty::Float(t) => p!(write("{}", t.name_str())),
ty::RawPtr(ref tm) => {
p!(write("*{} ", match tm.mutbl {
hir::Mutability::Mutable => "mut",
hir::Mutability::Immutable => "const",
hir::Mutability::Mut => "mut",
hir::Mutability::Not => "const",
}));
p!(print(tm.ty))
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
} else {
let mutbl = a.mutbl;
let variance = match mutbl {
ast::Mutability::Immutable => ty::Covariant,
ast::Mutability::Mutable => ty::Invariant,
ast::Mutability::Not => ty::Covariant,
ast::Mutability::Mut => ty::Invariant,
};
let ty = relation.relate_with_variance(variance, &a.ty, &b.ty)?;
Ok(ty::TypeAndMut { ty, mutbl })
Expand Down
Loading