Skip to content

Commit ed640c6

Browse files
committed
Merge hir::Mutability into ast::Mutability.
1 parent 57a5f92 commit ed640c6

File tree

65 files changed

+218
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+218
-233
lines changed

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,13 +2077,6 @@ impl<'a> LoweringContext<'a> {
20772077
}, ids)
20782078
}
20792079

2080-
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
2081-
match m {
2082-
Mutability::Mutable => hir::MutMutable,
2083-
Mutability::Immutable => hir::MutImmutable,
2084-
}
2085-
}
2086-
20872080
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
20882081
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
20892082
// as they are not explicit in HIR/Ty function signatures.
@@ -2653,7 +2646,7 @@ impl<'a> LoweringContext<'a> {
26532646
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy {
26542647
hir::MutTy {
26552648
ty: self.lower_ty(&mt.ty, itctx),
2656-
mutbl: self.lower_mutability(mt.mutbl),
2649+
mutbl: mt.mutbl,
26572650
}
26582651
}
26592652

@@ -2754,7 +2747,7 @@ impl<'a> LoweringContext<'a> {
27542747
}
27552748
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
27562749
PatKind::Ref(ref inner, mutbl) => {
2757-
hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl))
2750+
hir::PatKind::Ref(self.lower_pat(inner), mutbl)
27582751
}
27592752
PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range(
27602753
P(self.lower_expr(e1)),

src/librustc/hir/lowering/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl LoweringContext<'_> {
6464
hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
6565
}
6666
ExprKind::AddrOf(m, ref ohs) => {
67-
let m = self.lower_mutability(m);
6867
let ohs = P(self.lower_expr(ohs));
6968
hir::ExprKind::AddrOf(m, ohs)
7069
}
@@ -1350,7 +1349,7 @@ impl LoweringContext<'_> {
13501349
}
13511350

13521351
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
1353-
self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new())
1352+
self.expr(span, hir::ExprKind::AddrOf(hir::Mutability::Mutable, e), ThinVec::new())
13541353
}
13551354

13561355
fn expr_unit(&mut self, sp: Span) -> hir::Expr {

src/librustc/hir/lowering/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl LoweringContext<'_> {
289289
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
290290
}
291291
),
292-
self.lower_mutability(m),
292+
m,
293293
self.lower_const_body(e),
294294
)
295295
}
@@ -719,7 +719,7 @@ impl LoweringContext<'_> {
719719
}
720720
ForeignItemKind::Static(ref t, m) => {
721721
hir::ForeignItemKind::Static(
722-
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
722+
self.lower_ty(t, ImplTraitContext::disallowed()), m)
723723
}
724724
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
725725
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),

src/librustc/hir/mod.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
pub use self::BlockCheckMode::*;
66
pub use self::CaptureClause::*;
77
pub use self::FunctionRetTy::*;
8-
pub use self::Mutability::*;
98
pub use self::PrimTy::*;
109
pub use self::UnOp::*;
1110
pub use self::UnsafeSource::*;
@@ -23,6 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
2322
use syntax::source_map::Spanned;
2423
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
2524
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
25+
pub use syntax::ast::Mutability;
2626
use syntax::attr::{InlineAttr, OptimizeAttr};
2727
use syntax::symbol::{Symbol, kw};
2828
use syntax::tokenstream::TokenStream;
@@ -1053,37 +1053,6 @@ pub enum PatKind {
10531053
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
10541054
}
10551055

1056-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
1057-
RustcEncodable, RustcDecodable, Hash, Debug)]
1058-
pub enum Mutability {
1059-
MutMutable,
1060-
MutImmutable,
1061-
}
1062-
1063-
impl Mutability {
1064-
/// Returns `MutMutable` only if both `self` and `other` are mutable.
1065-
pub fn and(self, other: Self) -> Self {
1066-
match self {
1067-
MutMutable => other,
1068-
MutImmutable => MutImmutable,
1069-
}
1070-
}
1071-
1072-
pub fn invert(self) -> Self {
1073-
match self {
1074-
MutMutable => MutImmutable,
1075-
MutImmutable => MutMutable,
1076-
}
1077-
}
1078-
1079-
pub fn prefix_str(&self) -> &'static str {
1080-
match self {
1081-
MutMutable => "mut ",
1082-
MutImmutable => "",
1083-
}
1084-
}
1085-
}
1086-
10871056
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
10881057
pub enum BinOpKind {
10891058
/// The `+` operator (addition).

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ impl hir::Pat {
169169
self.each_binding(|annotation, _, _, _| {
170170
match annotation {
171171
hir::BindingAnnotation::Ref => match result {
172-
None | Some(hir::MutImmutable) => result = Some(hir::MutImmutable),
172+
None | Some(hir::Mutability::Immutable) => result = Some(hir::Mutability::Immutable),
173173
_ => {}
174174
}
175-
hir::BindingAnnotation::RefMut => result = Some(hir::MutMutable),
175+
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
176176
_ => {}
177177
}
178178
});

src/librustc/hir/print.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ impl<'a> State<'a> {
295295
hir::TyKind::Ptr(ref mt) => {
296296
self.s.word("*");
297297
match mt.mutbl {
298-
hir::MutMutable => self.word_nbsp("mut"),
299-
hir::MutImmutable => self.word_nbsp("const"),
298+
hir::Mutability::Mutable => self.word_nbsp("mut"),
299+
hir::Mutability::Immutable => self.word_nbsp("const"),
300300
}
301301
self.print_type(&mt.ty);
302302
}
@@ -390,7 +390,7 @@ impl<'a> State<'a> {
390390
}
391391
hir::ForeignItemKind::Static(ref t, m) => {
392392
self.head(visibility_qualified(&item.vis, "static"));
393-
if m == hir::MutMutable {
393+
if m == hir::Mutability::Mutable {
394394
self.word_space("mut");
395395
}
396396
self.print_ident(item.ident);
@@ -506,7 +506,7 @@ impl<'a> State<'a> {
506506
}
507507
hir::ItemKind::Static(ref ty, m, expr) => {
508508
self.head(visibility_qualified(&item.vis, "static"));
509-
if m == hir::MutMutable {
509+
if m == hir::Mutability::Mutable {
510510
self.word_space("mut");
511511
}
512512
self.print_ident(item.ident);
@@ -1628,11 +1628,11 @@ impl<'a> State<'a> {
16281628
match binding_mode {
16291629
hir::BindingAnnotation::Ref => {
16301630
self.word_nbsp("ref");
1631-
self.print_mutability(hir::MutImmutable);
1631+
self.print_mutability(hir::Mutability::Immutable);
16321632
}
16331633
hir::BindingAnnotation::RefMut => {
16341634
self.word_nbsp("ref");
1635-
self.print_mutability(hir::MutMutable);
1635+
self.print_mutability(hir::Mutability::Mutable);
16361636
}
16371637
hir::BindingAnnotation::Unannotated => {}
16381638
hir::BindingAnnotation::Mutable => {
@@ -2061,8 +2061,8 @@ impl<'a> State<'a> {
20612061

20622062
pub fn print_mutability(&mut self, mutbl: hir::Mutability) {
20632063
match mutbl {
2064-
hir::MutMutable => self.word_nbsp("mut"),
2065-
hir::MutImmutable => {},
2064+
hir::Mutability::Mutable => self.word_nbsp("mut"),
2065+
hir::Mutability::Immutable => {},
20662066
}
20672067
}
20682068

src/librustc/lint/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
131131
}
132132
}
133133
}
134-
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::MutImmutable }) => {
134+
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
135135
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) {
136136
if cx.tcx.impl_trait_ref(impl_did).is_some() {
137137
return;

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use crate::ty::adjustment;
6767
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
6868
use crate::ty::fold::TypeFoldable;
6969

70-
use crate::hir::{MutImmutable, MutMutable, PatKind};
70+
use crate::hir::{Mutability, PatKind};
7171
use crate::hir::pat_util::EnumerateAndAdjustIterator;
7272
use crate::hir;
7373
use syntax::ast::{self, Name};
@@ -226,8 +226,8 @@ pub type McResult<T> = Result<T, ()>;
226226
impl MutabilityCategory {
227227
pub fn from_mutbl(m: hir::Mutability) -> MutabilityCategory {
228228
let ret = match m {
229-
MutImmutable => McImmutable,
230-
MutMutable => McDeclared
229+
Mutability::Immutable => McImmutable,
230+
Mutability::Mutable => McDeclared
231231
};
232232
debug!("MutabilityCategory::{}({:?}) => {:?}",
233233
"from_mutbl", m, ret);
@@ -274,7 +274,7 @@ impl MutabilityCategory {
274274
let bm = *tables.pat_binding_modes()
275275
.get(p.hir_id)
276276
.expect("missing binding mode");
277-
if bm == ty::BindByValue(hir::MutMutable) {
277+
if bm == ty::BindByValue(Mutability::Mutable) {
278278
McDeclared
279279
} else {
280280
McImmutable
@@ -663,8 +663,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
663663
span,
664664
cat,
665665
mutbl: match self.tcx.static_mutability(def_id).unwrap() {
666-
hir::MutImmutable => McImmutable,
667-
hir::MutMutable => McDeclared,
666+
Mutability::Immutable => McImmutable,
667+
Mutability::Mutable => McDeclared,
668668
},
669669
ty:expr_ty,
670670
note: NoteNone

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ pub enum Mutability {
491491
impl From<Mutability> for hir::Mutability {
492492
fn from(m: Mutability) -> Self {
493493
match m {
494-
Mutability::Mut => hir::MutMutable,
495-
Mutability::Not => hir::MutImmutable,
494+
Mutability::Mut => hir::Mutability::Mutable,
495+
Mutability::Not => hir::Mutability::Immutable,
496496
}
497497
}
498498
}

src/librustc/mir/tcx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,17 @@ impl<'tcx> BinOp {
276276
impl BorrowKind {
277277
pub fn to_mutbl_lossy(self) -> hir::Mutability {
278278
match self {
279-
BorrowKind::Mut { .. } => hir::MutMutable,
280-
BorrowKind::Shared => hir::MutImmutable,
279+
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
280+
BorrowKind::Shared => hir::Mutability::Immutable,
281281

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

287287
// We have no type corresponding to a shallow borrow, so use
288288
// `&` as an approximation.
289-
BorrowKind::Shallow => hir::MutImmutable,
289+
BorrowKind::Shallow => hir::Mutability::Immutable,
290290
}
291291
}
292292
}

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13851385

13861386
if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
13871387
let trait_type = match mutability {
1388-
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type),
1389-
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
1388+
hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
1389+
hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
13901390
};
13911391

13921392
let substs = self.tcx.mk_substs_trait(&trait_type, &[]);
@@ -1403,7 +1403,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14031403
let sp = self.tcx.sess.source_map()
14041404
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
14051405
if points_at_arg &&
1406-
mutability == hir::Mutability::MutImmutable &&
1406+
mutability == hir::Mutability::Immutable &&
14071407
refs_number > 0
14081408
{
14091409
err.span_suggestion(

src/librustc/traits/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26522652
| ty::Char
26532653
| ty::RawPtr(..)
26542654
| ty::Never
2655-
| ty::Ref(_, _, hir::MutImmutable) => {
2655+
| ty::Ref(_, _, hir::Mutability::Immutable) => {
26562656
// Implementations provided in libcore
26572657
None
26582658
}
@@ -2663,7 +2663,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26632663
| ty::Generator(..)
26642664
| ty::GeneratorWitness(..)
26652665
| ty::Foreign(..)
2666-
| ty::Ref(_, _, hir::MutMutable) => None,
2666+
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
26672667

26682668
ty::Array(element_ty, _) => {
26692669
// (*) binder moved here

src/librustc/ty/adjustment.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
109109
impl<'tcx> OverloadedDeref<'tcx> {
110110
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
111111
let trait_def_id = match self.mutbl {
112-
hir::MutImmutable => tcx.lang_items().deref_trait(),
113-
hir::MutMutable => tcx.lang_items().deref_mut_trait()
112+
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
113+
hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
114114
};
115115
let method_def_id = tcx.associated_items(trait_def_id.unwrap())
116116
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
@@ -145,8 +145,8 @@ pub enum AutoBorrowMutability {
145145
impl From<AutoBorrowMutability> for hir::Mutability {
146146
fn from(m: AutoBorrowMutability) -> Self {
147147
match m {
148-
AutoBorrowMutability::Mutable { .. } => hir::MutMutable,
149-
AutoBorrowMutability::Immutable => hir::MutImmutable,
148+
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
149+
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
150150
}
151151
}
152152
}

src/librustc/ty/binding.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
1313
impl BindingMode {
1414
pub fn convert(ba: BindingAnnotation) -> BindingMode {
1515
match ba {
16-
Unannotated => BindingMode::BindByValue(Mutability::MutImmutable),
17-
Mutable => BindingMode::BindByValue(Mutability::MutMutable),
18-
Ref => BindingMode::BindByReference(Mutability::MutImmutable),
19-
RefMut => BindingMode::BindByReference(Mutability::MutMutable),
16+
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
17+
Mutable => BindingMode::BindByValue(Mutability::Mutable),
18+
Ref => BindingMode::BindByReference(Mutability::Immutable),
19+
RefMut => BindingMode::BindByReference(Mutability::Mutable),
2020
}
2121
}
2222
}

src/librustc/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,22 +2410,22 @@ impl<'tcx> TyCtxt<'tcx> {
24102410

24112411
#[inline]
24122412
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
2413-
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::MutMutable})
2413+
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
24142414
}
24152415

24162416
#[inline]
24172417
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
2418-
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
2418+
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
24192419
}
24202420

24212421
#[inline]
24222422
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2423-
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutMutable})
2423+
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
24242424
}
24252425

24262426
#[inline]
24272427
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2428-
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
2428+
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
24292429
}
24302430

24312431
#[inline]

src/librustc/ty/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'tcx> ty::TyS<'tcx> {
211211
region.to_string() != "'_" //... or a complex type
212212
{
213213
format!("{}reference", match mutbl {
214-
hir::Mutability::MutMutable => "mutable ",
214+
hir::Mutability::Mutable => "mutable ",
215215
_ => ""
216216
}).into()
217217
} else {

src/librustc/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,12 +2221,12 @@ where
22212221
let tcx = cx.tcx();
22222222
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
22232223
let kind = match mt {
2224-
hir::MutImmutable => if is_freeze {
2224+
hir::Mutability::Immutable => if is_freeze {
22252225
PointerKind::Frozen
22262226
} else {
22272227
PointerKind::Shared
22282228
},
2229-
hir::MutMutable => {
2229+
hir::Mutability::Mutable => {
22302230
// Previously we would only emit noalias annotations for LLVM >= 6 or in
22312231
// panic=abort mode. That was deemed right, as prior versions had many bugs
22322232
// in conjunction with unwinding, but later versions didn’t seem to have

0 commit comments

Comments
 (0)