Auto merge of #66252 - cjgillot:trees, r=oli-obk

Merge repeated definitions

Step forward on #66149

I may need further context to understand the need for a separate crate.

Also, please tell me if you think of other definitions to merge.
This commit is contained in:
bors 2019-11-11 14:05:43 +00:00
commit 56237d75b4
72 changed files with 298 additions and 404 deletions

View File

@ -1217,7 +1217,7 @@ impl<'a> LoweringContext<'a> {
&NodeMap::default(), &NodeMap::default(),
ImplTraitContext::disallowed(), ImplTraitContext::disallowed(),
), ),
unsafety: this.lower_unsafety(f.unsafety), unsafety: f.unsafety,
abi: this.lower_abi(f.abi), abi: this.lower_abi(f.abi),
decl: this.lower_fn_decl(&f.decl, None, false, None), decl: this.lower_fn_decl(&f.decl, None, false, None),
param_names: this.lower_fn_params_to_names(&f.decl), param_names: this.lower_fn_params_to_names(&f.decl),
@ -2081,13 +2081,6 @@ impl<'a> LoweringContext<'a> {
}, ids) }, ids)
} }
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
match m {
Mutability::Mutable => hir::MutMutable,
Mutability::Immutable => hir::MutImmutable,
}
}
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> { fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
// Skip the `...` (`CVarArgs`) trailing arguments from the AST, // Skip the `...` (`CVarArgs`) trailing arguments from the AST,
// as they are not explicit in HIR/Ty function signatures. // as they are not explicit in HIR/Ty function signatures.
@ -2657,7 +2650,7 @@ impl<'a> LoweringContext<'a> {
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy { fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy {
hir::MutTy { hir::MutTy {
ty: self.lower_ty(&mt.ty, itctx), ty: self.lower_ty(&mt.ty, itctx),
mutbl: self.lower_mutability(mt.mutbl), mutbl: mt.mutbl,
} }
} }
@ -2758,7 +2751,7 @@ impl<'a> LoweringContext<'a> {
} }
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)), PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
PatKind::Ref(ref inner, mutbl) => { 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( PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range(
P(self.lower_expr(e1)), P(self.lower_expr(e1)),

View File

@ -64,7 +64,6 @@ impl LoweringContext<'_> {
hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed())) hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
} }
ExprKind::AddrOf(m, ref ohs) => { ExprKind::AddrOf(m, ref ohs) => {
let m = self.lower_mutability(m);
let ohs = P(self.lower_expr(ohs)); let ohs = P(self.lower_expr(ohs));
hir::ExprKind::AddrOf(m, ohs) hir::ExprKind::AddrOf(m, ohs)
} }
@ -474,7 +473,6 @@ impl LoweringContext<'_> {
async_gen_kind: hir::AsyncGeneratorKind, async_gen_kind: hir::AsyncGeneratorKind,
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
) -> hir::ExprKind { ) -> hir::ExprKind {
let capture_clause = self.lower_capture_clause(capture_clause);
let output = match ret_ty { let output = match ret_ty {
Some(ty) => FunctionRetTy::Ty(ty), Some(ty) => FunctionRetTy::Ty(ty),
None => FunctionRetTy::Default(span), None => FunctionRetTy::Default(span),
@ -495,7 +493,7 @@ impl LoweringContext<'_> {
decl, decl,
body_id, body_id,
span, span,
Some(hir::GeneratorMovability::Static) Some(hir::Movability::Static)
); );
let generator = hir::Expr { let generator = hir::Expr {
hir_id: self.lower_node_id(closure_node_id), hir_id: self.lower_node_id(closure_node_id),
@ -701,7 +699,6 @@ impl LoweringContext<'_> {
generator_kind, generator_kind,
movability, movability,
); );
let capture_clause = this.lower_capture_clause(capture_clause);
this.current_item = prev; this.current_item = prev;
hir::ExprKind::Closure( hir::ExprKind::Closure(
capture_clause, capture_clause,
@ -713,20 +710,13 @@ impl LoweringContext<'_> {
}) })
} }
fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
match c {
CaptureBy::Value => hir::CaptureByValue,
CaptureBy::Ref => hir::CaptureByRef,
}
}
fn generator_movability_for_fn( fn generator_movability_for_fn(
&mut self, &mut self,
decl: &FnDecl, decl: &FnDecl,
fn_decl_span: Span, fn_decl_span: Span,
generator_kind: Option<hir::GeneratorKind>, generator_kind: Option<hir::GeneratorKind>,
movability: Movability, movability: Movability,
) -> Option<hir::GeneratorMovability> { ) -> Option<hir::Movability> {
match generator_kind { match generator_kind {
Some(hir::GeneratorKind::Gen) => { Some(hir::GeneratorKind::Gen) => {
if !decl.inputs.is_empty() { if !decl.inputs.is_empty() {
@ -737,10 +727,7 @@ impl LoweringContext<'_> {
"generators cannot have explicit parameters" "generators cannot have explicit parameters"
); );
} }
Some(match movability { Some(movability)
Movability::Movable => hir::GeneratorMovability::Movable,
Movability::Static => hir::GeneratorMovability::Static,
})
}, },
Some(hir::GeneratorKind::Async(_)) => { Some(hir::GeneratorKind::Async(_)) => {
bug!("non-`async` closure body turned `async` during lowering"); bug!("non-`async` closure body turned `async` during lowering");
@ -811,7 +798,7 @@ impl LoweringContext<'_> {
this.expr(fn_decl_span, async_body, ThinVec::new()) this.expr(fn_decl_span, async_body, ThinVec::new())
}); });
hir::ExprKind::Closure( hir::ExprKind::Closure(
this.lower_capture_clause(capture_clause), capture_clause,
fn_decl, fn_decl,
body_id, body_id,
fn_decl_span, fn_decl_span,
@ -1350,7 +1337,7 @@ impl LoweringContext<'_> {
} }
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr { fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new()) self.expr(span, hir::ExprKind::AddrOf(hir::Mutability::Mutable, e), ThinVec::new())
} }
fn expr_unit(&mut self, sp: Span) -> hir::Expr { fn expr_unit(&mut self, sp: Span) -> hir::Expr {

View File

@ -19,7 +19,7 @@ use smallvec::SmallVec;
use syntax::attr; use syntax::attr;
use syntax::ast::*; use syntax::ast::*;
use syntax::visit::{self, Visitor}; 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::symbol::{kw, sym};
use syntax_pos::Span; use syntax_pos::Span;
@ -289,7 +289,7 @@ impl LoweringContext<'_> {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding) ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
} }
), ),
self.lower_mutability(m), m,
self.lower_const_body(e), self.lower_const_body(e),
) )
} }
@ -433,8 +433,8 @@ impl LoweringContext<'_> {
); );
hir::ItemKind::Impl( hir::ItemKind::Impl(
self.lower_unsafety(unsafety), unsafety,
self.lower_impl_polarity(polarity), polarity,
self.lower_defaultness(defaultness, true /* [1] */), self.lower_defaultness(defaultness, true /* [1] */),
generics, generics,
trait_ref, trait_ref,
@ -449,8 +449,8 @@ impl LoweringContext<'_> {
.map(|item| self.lower_trait_item_ref(item)) .map(|item| self.lower_trait_item_ref(item))
.collect(); .collect();
hir::ItemKind::Trait( hir::ItemKind::Trait(
self.lower_is_auto(is_auto), is_auto,
self.lower_unsafety(unsafety), unsafety,
self.lower_generics(generics, ImplTraitContext::disallowed()), self.lower_generics(generics, ImplTraitContext::disallowed()),
bounds, bounds,
items, items,
@ -719,7 +719,7 @@ impl LoweringContext<'_> {
} }
ForeignItemKind::Static(ref t, m) => { ForeignItemKind::Static(ref t, m) => {
hir::ForeignItemKind::Static( 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::Ty => hir::ForeignItemKind::Type,
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"), ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
@ -1011,13 +1011,6 @@ impl LoweringContext<'_> {
} }
} }
fn lower_impl_polarity(&mut self, i: ImplPolarity) -> hir::ImplPolarity {
match i {
ImplPolarity::Positive => hir::ImplPolarity::Positive,
ImplPolarity::Negative => hir::ImplPolarity::Negative,
}
}
fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId { fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId {
let body = hir::Body { let body = hir::Body {
generator_kind: self.generator_kind, generator_kind: self.generator_kind,
@ -1275,18 +1268,11 @@ impl LoweringContext<'_> {
(generics, hir::FnSig { header, decl }) (generics, hir::FnSig { header, decl })
} }
fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {
match a {
IsAuto::Yes => hir::IsAuto::Yes,
IsAuto::No => hir::IsAuto::No,
}
}
fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader { fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
hir::FnHeader { hir::FnHeader {
unsafety: self.lower_unsafety(h.unsafety), unsafety: h.unsafety,
asyncness: self.lower_asyncness(h.asyncness.node), asyncness: self.lower_asyncness(h.asyncness.node),
constness: self.lower_constness(h.constness), constness: h.constness.node,
abi: self.lower_abi(h.abi), abi: self.lower_abi(h.abi),
} }
} }
@ -1311,20 +1297,6 @@ impl LoweringContext<'_> {
.emit(); .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_constness(&mut self, c: Spanned<Constness>) -> hir::Constness {
match c.node {
Constness::Const => hir::Constness::Const,
Constness::NotConst => hir::Constness::NotConst,
}
}
fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync { fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync {
match a { match a {
IsAsync::Async { .. } => hir::IsAsync::Async, IsAsync::Async { .. } => hir::IsAsync::Async,

View File

@ -3,9 +3,7 @@
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html //! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
pub use self::BlockCheckMode::*; pub use self::BlockCheckMode::*;
pub use self::CaptureClause::*;
pub use self::FunctionRetTy::*; pub use self::FunctionRetTy::*;
pub use self::Mutability::*;
pub use self::PrimTy::*; pub use self::PrimTy::*;
pub use self::UnOp::*; pub use self::UnOp::*;
pub use self::UnsafeSource::*; pub use self::UnsafeSource::*;
@ -23,6 +21,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability, CaptureBy, IsAuto, ImplPolarity};
use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::attr::{InlineAttr, OptimizeAttr};
use syntax::symbol::{Symbol, kw}; use syntax::symbol::{Symbol, kw};
use syntax::tokenstream::TokenStream; use syntax::tokenstream::TokenStream;
@ -1053,37 +1052,6 @@ pub enum PatKind {
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>), Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
} }
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Mutability {
MutMutable,
MutImmutable,
}
impl Mutability {
/// Returns `MutMutable` only if both `self` and `other` are mutable.
pub fn and(self, other: Self) -> Self {
match self {
MutMutable => other,
MutImmutable => MutImmutable,
}
}
pub fn invert(self) -> Self {
match self {
MutMutable => MutImmutable,
MutImmutable => MutMutable,
}
}
pub fn prefix_str(&self) -> &'static str {
match self {
MutMutable => "mut ",
MutImmutable => "",
}
}
}
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum BinOpKind { pub enum BinOpKind {
/// The `+` operator (addition). /// The `+` operator (addition).
@ -1659,8 +1627,8 @@ pub enum ExprKind {
/// The `Span` is the argument block `|...|`. /// The `Span` is the argument block `|...|`.
/// ///
/// This may also be a generator literal or an `async block` as indicated by the /// This may also be a generator literal or an `async block` as indicated by the
/// `Option<GeneratorMovability>`. /// `Option<Movability>`.
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<GeneratorMovability>), Closure(CaptureBy, P<FnDecl>, BodyId, Span, Option<Movability>),
/// A block (e.g., `'label: { ... }`). /// A block (e.g., `'label: { ... }`).
Block(P<Block>, Option<Label>), Block(P<Block>, Option<Label>),
@ -1833,17 +1801,6 @@ pub struct Destination {
pub target_id: Result<HirId, LoopIdError>, pub target_id: Result<HirId, LoopIdError>,
} }
/// Whether a generator contains self-references, causing it to be `!Unpin`.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum GeneratorMovability {
/// May contain self-references, `!Unpin`.
Static,
/// Must not contain self-references, `Unpin`.
Movable,
}
/// The yield kind that caused an `ExprKind::Yield`. /// The yield kind that caused an `ExprKind::Yield`.
#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)] #[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum YieldSource { pub enum YieldSource {
@ -1862,12 +1819,6 @@ impl fmt::Display for YieldSource {
} }
} }
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum CaptureClause {
CaptureByValue,
CaptureByRef,
}
// N.B., if you change this, you'll probably want to change the corresponding // N.B., if you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well. // type structure in middle/ty.rs as well.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@ -2171,13 +2122,6 @@ impl ImplicitSelfKind {
} }
} }
/// Is the trait definition an auto trait?
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum IsAuto {
Yes,
No
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, HashStable, #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, HashStable,
Ord, RustcEncodable, RustcDecodable, Debug)] Ord, RustcEncodable, RustcDecodable, Debug)]
pub enum IsAsync { pub enum IsAsync {
@ -2185,28 +2129,6 @@ pub enum IsAsync {
NotAsync, 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 Constness {
Const,
NotConst,
}
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum Defaultness { pub enum Defaultness {
Default { has_value: bool }, Default { has_value: bool },
@ -2233,33 +2155,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`
Positive,
/// `impl !Trait for Type`
Negative,
}
impl fmt::Debug for ImplPolarity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
ImplPolarity::Positive => "positive",
ImplPolarity::Negative => "negative",
})
}
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum FunctionRetTy { pub enum FunctionRetTy {
/// Return type is not specified. /// Return type is not specified.
@ -2693,7 +2588,7 @@ pub struct Upvar {
pub span: Span pub span: Span
} }
pub type CaptureModeMap = NodeMap<CaptureClause>; pub type CaptureModeMap = NodeMap<CaptureBy>;
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and // The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
// has length > 0 if the trait is found through an chain of imports, starting with the // has length > 0 if the trait is found through an chain of imports, starting with the

View File

@ -169,10 +169,11 @@ impl hir::Pat {
self.each_binding(|annotation, _, _, _| { self.each_binding(|annotation, _, _, _| {
match annotation { match annotation {
hir::BindingAnnotation::Ref => match result { 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),
_ => {} _ => {}
} }
}); });

View File

@ -295,8 +295,8 @@ impl<'a> State<'a> {
hir::TyKind::Ptr(ref mt) => { hir::TyKind::Ptr(ref mt) => {
self.s.word("*"); self.s.word("*");
match mt.mutbl { match mt.mutbl {
hir::MutMutable => self.word_nbsp("mut"), hir::Mutability::Mutable => self.word_nbsp("mut"),
hir::MutImmutable => self.word_nbsp("const"), hir::Mutability::Immutable => self.word_nbsp("const"),
} }
self.print_type(&mt.ty); self.print_type(&mt.ty);
} }
@ -390,7 +390,7 @@ impl<'a> State<'a> {
} }
hir::ForeignItemKind::Static(ref t, m) => { hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static")); self.head(visibility_qualified(&item.vis, "static"));
if m == hir::MutMutable { if m == hir::Mutability::Mutable {
self.word_space("mut"); self.word_space("mut");
} }
self.print_ident(item.ident); self.print_ident(item.ident);
@ -506,7 +506,7 @@ impl<'a> State<'a> {
} }
hir::ItemKind::Static(ref ty, m, expr) => { hir::ItemKind::Static(ref ty, m, expr) => {
self.head(visibility_qualified(&item.vis, "static")); self.head(visibility_qualified(&item.vis, "static"));
if m == hir::MutMutable { if m == hir::Mutability::Mutable {
self.word_space("mut"); self.word_space("mut");
} }
self.print_ident(item.ident); self.print_ident(item.ident);
@ -1628,11 +1628,11 @@ impl<'a> State<'a> {
match binding_mode { match binding_mode {
hir::BindingAnnotation::Ref => { hir::BindingAnnotation::Ref => {
self.word_nbsp("ref"); self.word_nbsp("ref");
self.print_mutability(hir::MutImmutable); self.print_mutability(hir::Mutability::Immutable);
} }
hir::BindingAnnotation::RefMut => { hir::BindingAnnotation::RefMut => {
self.word_nbsp("ref"); self.word_nbsp("ref");
self.print_mutability(hir::MutMutable); self.print_mutability(hir::Mutability::Mutable);
} }
hir::BindingAnnotation::Unannotated => {} hir::BindingAnnotation::Unannotated => {}
hir::BindingAnnotation::Mutable => { hir::BindingAnnotation::Mutable => {
@ -1909,10 +1909,10 @@ impl<'a> State<'a> {
} }
} }
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureClause) { pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureBy) {
match capture_clause { match capture_clause {
hir::CaptureByValue => self.word_space("move"), hir::CaptureBy::Value => self.word_space("move"),
hir::CaptureByRef => {}, hir::CaptureBy::Ref => {},
} }
} }
@ -2061,8 +2061,8 @@ impl<'a> State<'a> {
pub fn print_mutability(&mut self, mutbl: hir::Mutability) { pub fn print_mutability(&mut self, mutbl: hir::Mutability) {
match mutbl { match mutbl {
hir::MutMutable => self.word_nbsp("mut"), hir::Mutability::Mutable => self.word_nbsp("mut"),
hir::MutImmutable => {}, hir::Mutability::Immutable => {},
} }
} }

View File

@ -168,6 +168,10 @@ impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) }); impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner }); impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
impl_stable_hash_for!(enum ::syntax::ast::CaptureBy { Value, Ref });
impl_stable_hash_for!(enum ::syntax::ast::IsAuto { Yes, No });
impl_stable_hash_for!(enum ::syntax::ast::ImplPolarity { Positive, Negative });
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] { impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

View File

@ -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 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() { if cx.tcx.impl_trait_ref(impl_did).is_some() {
return; return;

View File

@ -67,7 +67,7 @@ use crate::ty::adjustment;
use crate::ty::{self, DefIdTree, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::fold::TypeFoldable; 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::pat_util::EnumerateAndAdjustIterator;
use crate::hir; use crate::hir;
use syntax::ast::{self, Name}; use syntax::ast::{self, Name};
@ -226,8 +226,8 @@ pub type McResult<T> = Result<T, ()>;
impl MutabilityCategory { impl MutabilityCategory {
pub fn from_mutbl(m: hir::Mutability) -> MutabilityCategory { pub fn from_mutbl(m: hir::Mutability) -> MutabilityCategory {
let ret = match m { let ret = match m {
MutImmutable => McImmutable, Mutability::Immutable => McImmutable,
MutMutable => McDeclared Mutability::Mutable => McDeclared
}; };
debug!("MutabilityCategory::{}({:?}) => {:?}", debug!("MutabilityCategory::{}({:?}) => {:?}",
"from_mutbl", m, ret); "from_mutbl", m, ret);
@ -274,7 +274,7 @@ impl MutabilityCategory {
let bm = *tables.pat_binding_modes() let bm = *tables.pat_binding_modes()
.get(p.hir_id) .get(p.hir_id)
.expect("missing binding mode"); .expect("missing binding mode");
if bm == ty::BindByValue(hir::MutMutable) { if bm == ty::BindByValue(Mutability::Mutable) {
McDeclared McDeclared
} else { } else {
McImmutable McImmutable
@ -663,8 +663,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
span, span,
cat, cat,
mutbl: match self.tcx.static_mutability(def_id).unwrap() { mutbl: match self.tcx.static_mutability(def_id).unwrap() {
hir::MutImmutable => McImmutable, Mutability::Immutable => McImmutable,
hir::MutMutable => McDeclared, Mutability::Mutable => McDeclared,
}, },
ty:expr_ty, ty:expr_ty,
note: NoteNone note: NoteNone

View File

@ -491,8 +491,8 @@ pub enum Mutability {
impl From<Mutability> for hir::Mutability { impl From<Mutability> for hir::Mutability {
fn from(m: Mutability) -> Self { fn from(m: Mutability) -> Self {
match m { match m {
Mutability::Mut => hir::MutMutable, Mutability::Mut => hir::Mutability::Mutable,
Mutability::Not => hir::MutImmutable, Mutability::Not => hir::Mutability::Immutable,
} }
} }
} }
@ -2161,7 +2161,7 @@ pub enum AggregateKind<'tcx> {
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>), Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
Closure(DefId, SubstsRef<'tcx>), Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] #[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

View File

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

View File

@ -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 { if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
let trait_type = match mutability { let trait_type = match mutability {
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type), hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type), hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
}; };
let substs = self.tcx.mk_substs_trait(&trait_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() let sp = self.tcx.sess.source_map()
.span_take_while(span, |c| c.is_whitespace() || *c == '&'); .span_take_while(span, |c| c.is_whitespace() || *c == '&');
if points_at_arg && if points_at_arg &&
mutability == hir::Mutability::MutImmutable && mutability == hir::Mutability::Immutable &&
refs_number > 0 refs_number > 0
{ {
err.span_suggestion( err.span_suggestion(

View File

@ -2195,11 +2195,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if self.tcx().lang_items().unpin_trait() == Some(def_id) => if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
{ {
match movability { match movability {
hir::GeneratorMovability::Static => { hir::Movability::Static => {
// Immovable generators are never `Unpin`, so // Immovable generators are never `Unpin`, so
// suppress the normal auto-impl candidate for it. // suppress the normal auto-impl candidate for it.
} }
hir::GeneratorMovability::Movable => { hir::Movability::Movable => {
// Movable generators are always `Unpin`, so add an // Movable generators are always `Unpin`, so add an
// unconditional builtin candidate. // unconditional builtin candidate.
candidates.vec.push(BuiltinCandidate { candidates.vec.push(BuiltinCandidate {
@ -2652,7 +2652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Char | ty::Char
| ty::RawPtr(..) | ty::RawPtr(..)
| ty::Never | ty::Never
| ty::Ref(_, _, hir::MutImmutable) => { | ty::Ref(_, _, hir::Mutability::Immutable) => {
// Implementations provided in libcore // Implementations provided in libcore
None None
} }
@ -2663,7 +2663,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Generator(..) | ty::Generator(..)
| ty::GeneratorWitness(..) | ty::GeneratorWitness(..)
| ty::Foreign(..) | ty::Foreign(..)
| ty::Ref(_, _, hir::MutMutable) => None, | ty::Ref(_, _, hir::Mutability::Mutable) => None,
ty::Array(element_ty, _) => { ty::Array(element_ty, _) => {
// (*) binder moved here // (*) binder moved here

View File

@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
impl<'tcx> OverloadedDeref<'tcx> { impl<'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) { pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl { let trait_def_id = match self.mutbl {
hir::MutImmutable => tcx.lang_items().deref_trait(), hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
hir::MutMutable => tcx.lang_items().deref_mut_trait() hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
}; };
let method_def_id = tcx.associated_items(trait_def_id.unwrap()) let method_def_id = tcx.associated_items(trait_def_id.unwrap())
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id; .find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
@ -145,8 +145,8 @@ pub enum AutoBorrowMutability {
impl From<AutoBorrowMutability> for hir::Mutability { impl From<AutoBorrowMutability> for hir::Mutability {
fn from(m: AutoBorrowMutability) -> Self { fn from(m: AutoBorrowMutability) -> Self {
match m { match m {
AutoBorrowMutability::Mutable { .. } => hir::MutMutable, AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
AutoBorrowMutability::Immutable => hir::MutImmutable, AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
} }
} }
} }

View File

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

View File

@ -2410,22 +2410,22 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline] #[inline]
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { 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] #[inline]
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { 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] #[inline]
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { 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] #[inline]
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { 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] #[inline]
@ -2516,7 +2516,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn mk_generator(self, pub fn mk_generator(self,
id: DefId, id: DefId,
generator_substs: SubstsRef<'tcx>, generator_substs: SubstsRef<'tcx>,
movability: hir::GeneratorMovability) movability: hir::Movability)
-> Ty<'tcx> { -> Ty<'tcx> {
self.mk_ty(Generator(id, generator_substs, movability)) self.mk_ty(Generator(id, generator_substs, movability))
} }

View File

@ -211,7 +211,7 @@ impl<'tcx> ty::TyS<'tcx> {
region.to_string() != "'_" //... or a complex type region.to_string() != "'_" //... or a complex type
{ {
format!("{}reference", match mutbl { format!("{}reference", match mutbl {
hir::Mutability::MutMutable => "mutable ", hir::Mutability::Mutable => "mutable ",
_ => "" _ => ""
}).into() }).into()
} else { } else {

View File

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

View File

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

View File

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

View File

@ -471,8 +471,8 @@ pub trait PrettyPrinter<'tcx>:
ty::Float(t) => p!(write("{}", t.name_str())), ty::Float(t) => p!(write("{}", t.name_str())),
ty::RawPtr(ref tm) => { ty::RawPtr(ref tm) => {
p!(write("*{} ", match tm.mutbl { p!(write("*{} ", match tm.mutbl {
hir::MutMutable => "mut", hir::Mutability::Mutable => "mut",
hir::MutImmutable => "const", hir::Mutability::Immutable => "const",
})); }));
p!(print(tm.ty)) p!(print(tm.ty))
} }
@ -607,10 +607,9 @@ pub trait PrettyPrinter<'tcx>:
ty::Generator(did, substs, movability) => { ty::Generator(did, substs, movability) => {
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx()); let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
let witness = substs.as_generator().witness(did, self.tcx()); let witness = substs.as_generator().witness(did, self.tcx());
if movability == hir::GeneratorMovability::Movable { match movability {
p!(write("[generator")); hir::Movability::Movable => p!(write("[generator")),
} else { hir::Movability::Static => p!(write("[static generator")),
p!(write("[static generator"));
} }
// FIXME(eddyb) should use `def_span`. // FIXME(eddyb) should use `def_span`.

View File

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

View File

@ -162,7 +162,7 @@ pub enum TyKind<'tcx> {
/// The anonymous type of a generator. Used to represent the type of /// The anonymous type of a generator. Used to represent the type of
/// `|a| yield a`. /// `|a| yield a`.
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
/// A type representin the types stored inside a generator. /// A type representin the types stored inside a generator.
/// This should only appear in GeneratorInteriors. /// This should only appear in GeneratorInteriors.
@ -1839,8 +1839,8 @@ impl<'tcx> TyS<'tcx> {
#[inline] #[inline]
pub fn is_mutable_ptr(&self) -> bool { pub fn is_mutable_ptr(&self) -> bool {
match self.kind { match self.kind {
RawPtr(TypeAndMut { mutbl: hir::Mutability::MutMutable, .. }) | RawPtr(TypeAndMut { mutbl: hir::Mutability::Mutable, .. }) |
Ref(_, _, hir::Mutability::MutMutable) => true, Ref(_, _, hir::Mutability::Mutable) => true,
_ => false _ => false
} }
} }
@ -2030,7 +2030,7 @@ impl<'tcx> TyS<'tcx> {
Adt(def, _) if def.is_box() => { Adt(def, _) if def.is_box() => {
Some(TypeAndMut { Some(TypeAndMut {
ty: self.boxed_ty(), ty: self.boxed_ty(),
mutbl: hir::MutImmutable, mutbl: hir::Mutability::Immutable,
}) })
}, },
Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl }), Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl }),

View File

@ -184,7 +184,7 @@ impl<'tcx> ty::ParamEnv<'tcx> {
// Now libcore provides that impl. // Now libcore provides that impl.
ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Float(_) | ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Float(_) |
ty::Char | ty::RawPtr(..) | ty::Never | 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), 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. /// 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 { 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. /// Expands the given impl trait type, stopping if the type is recursive.

View File

@ -1573,7 +1573,7 @@ fn generic_simd_intrinsic(
// The second argument must be a simd vector with an element type that's a pointer // The second argument must be a simd vector with an element type that's a pointer
// to the element type of the first argument // to the element type of the first argument
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind { 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)), => (ptr_count(arg_tys[1].simd_type(tcx)),
non_ptr(arg_tys[1].simd_type(tcx))), non_ptr(arg_tys[1].simd_type(tcx))),
_ => { _ => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -137,7 +137,7 @@ fn do_mir_borrowck<'a, 'tcx>(
}; };
let bm = *tables.pat_binding_modes().get(var_hir_id) let bm = *tables.pat_binding_modes().get(var_hir_id)
.expect("missing binding mode"); .expect("missing binding mode");
if bm == ty::BindByValue(hir::MutMutable) { if bm == ty::BindByValue(hir::Mutability::Mutable) {
upvar.mutability = Mutability::Mut; upvar.mutability = Mutability::Mut;
} }
upvar upvar
@ -235,7 +235,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let movable_generator = match tcx.hir().get(id) { let movable_generator = match tcx.hir().get(id) {
Node::Expr(&hir::Expr { Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
.. ..
}) => false, }) => false,
_ => true, _ => true,
@ -2118,10 +2118,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::Ref(_, _, mutbl) => { ty::Ref(_, _, mutbl) => {
match mutbl { match mutbl {
// Shared borrowed data is never mutable // 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 // Mutably borrowed data is mutable, but only if we have a
// unique path to the `&mut` // unique path to the `&mut`
hir::MutMutable => { hir::Mutability::Mutable => {
let mode = match self.is_upvar_field_projection(place) { let mode = match self.is_upvar_field_projection(place) {
Some(field) Some(field)
if self.upvars[field.index()].by_ref => if self.upvars[field.index()].by_ref =>
@ -2141,10 +2141,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::RawPtr(tnm) => { ty::RawPtr(tnm) => {
match tnm.mutbl { match tnm.mutbl {
// `*const` raw pointers are not mutable // `*const` raw pointers are not mutable
hir::MutImmutable => Err(place), hir::Mutability::Immutable => Err(place),
// `*mut` raw pointers are always mutable, regardless of // `*mut` raw pointers are always mutable, regardless of
// context. The users have to check by themselves. // context. The users have to check by themselves.
hir::MutMutable => { hir::Mutability::Mutable => {
Ok(RootPlace { Ok(RootPlace {
place_base: place.base, place_base: place.base,
place_projection: place.projection, place_projection: place.projection,

View File

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

View File

@ -2138,7 +2138,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_from = match op.ty(body, tcx).kind { let ty_from = match op.ty(body, tcx).kind {
ty::RawPtr(ty::TypeAndMut { ty::RawPtr(ty::TypeAndMut {
ty: ty_from, ty: ty_from,
mutbl: hir::MutMutable, mutbl: hir::Mutability::Mutable,
}) => ty_from, }) => ty_from,
_ => { _ => {
span_mirbug!( span_mirbug!(
@ -2153,7 +2153,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_to = match ty.kind { let ty_to = match ty.kind {
ty::RawPtr(ty::TypeAndMut { ty::RawPtr(ty::TypeAndMut {
ty: ty_to, ty: ty_to,
mutbl: hir::MutImmutable, mutbl: hir::Mutability::Immutable,
}) => ty_to, }) => ty_to,
_ => { _ => {
span_mirbug!( span_mirbug!(
@ -2187,7 +2187,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let opt_ty_elem = match ty_from.kind { let opt_ty_elem = match ty_from.kind {
ty::RawPtr( ty::RawPtr(
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: array_ty } ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: array_ty }
) => { ) => {
match array_ty.kind { match array_ty.kind {
ty::Array(ty_elem, _) => Some(ty_elem), ty::Array(ty_elem, _) => Some(ty_elem),
@ -2212,7 +2212,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_to = match ty.kind { let ty_to = match ty.kind {
ty::RawPtr( ty::RawPtr(
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: ty_to } ty::TypeAndMut { mutbl: hir::Mutability::Immutable, ty: ty_to }
) => { ) => {
ty_to ty_to
} }
@ -2250,7 +2250,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let cast_ty_to = CastTy::from_ty(ty); let cast_ty_to = CastTy::from_ty(ty);
match (cast_ty_from, cast_ty_to) { match (cast_ty_from, cast_ty_to) {
(Some(CastTy::RPtr(ref_tm)), Some(CastTy::Ptr(ptr_tm))) => { (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( if let Err(terr) = self.eq_types(
ref_tm.ty, ref_tm.ty,
ptr_tm.ty, ptr_tm.ty,
@ -2504,13 +2504,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}); });
match mutbl { match mutbl {
hir::Mutability::MutImmutable => { hir::Mutability::Immutable => {
// Immutable reference. We don't need the base // Immutable reference. We don't need the base
// to be valid for the entire lifetime of // to be valid for the entire lifetime of
// the borrow. // the borrow.
break; break;
} }
hir::Mutability::MutMutable => { hir::Mutability::Mutable => {
// Mutable reference. We *do* need the base // Mutable reference. We *do* need the base
// to be valid, because after the base becomes // to be valid, because after the base becomes
// invalid, someone else can use our mutable deref. // invalid, someone else can use our mutable deref.

View File

@ -90,7 +90,7 @@ pub enum DefiningTy<'tcx> {
/// The MIR is a generator. The signature is that generators take /// The MIR is a generator. The signature is that generators take
/// no parameters and return the result of /// no parameters and return the result of
/// `ClosureSubsts::generator_return_ty`. /// `ClosureSubsts::generator_return_ty`.
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
/// The MIR is a fn item with the given `DefId` and substs. The signature /// The MIR is a fn item with the given `DefId` and substs. The signature
/// of the function can be bound then with the `fn_sig` query. /// of the function can be bound then with the `fn_sig` query.

View File

@ -57,7 +57,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
if *elem == ProjectionElem::Deref { if *elem == ProjectionElem::Deref {
let ty = Place::ty_from(&self.base, proj_base, body, tcx).ty; 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` // For both derefs of raw pointers and `&T`
// references, the original path is `Copy` and // references, the original path is `Copy` and
// therefore not significant. In particular, // therefore not significant. In particular,

View File

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

View File

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

View File

@ -581,7 +581,7 @@ where
if let hir::PatKind::Binding(_, _, ident, _) = pat.kind { if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
debuginfo.debug_name = ident.name; debuginfo.debug_name = ident.name;
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) { 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; mutability = Mutability::Mut;
} else { } else {
mutability = Mutability::Not; mutability = Mutability::Not;

View File

@ -860,8 +860,8 @@ impl ToBorrowKind for AutoBorrowMutability {
impl ToBorrowKind for hir::Mutability { impl ToBorrowKind for hir::Mutability {
fn to_borrow_kind(&self) -> BorrowKind { fn to_borrow_kind(&self) -> BorrowKind {
match *self { match *self {
hir::MutMutable => BorrowKind::Mut { allow_two_phase_borrow: false }, hir::Mutability::Mutable => BorrowKind::Mut { allow_two_phase_borrow: false },
hir::MutImmutable => BorrowKind::Shared, hir::Mutability::Immutable => BorrowKind::Shared,
} }
} }
} }
@ -1013,7 +1013,7 @@ fn convert_var(
let ref_closure_ty = cx.tcx.mk_ref(region, let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut { ty::TypeAndMut {
ty: closure_ty, ty: closure_ty,
mutbl: hir::MutImmutable, mutbl: hir::Mutability::Immutable,
}); });
Expr { Expr {
ty: closure_ty, ty: closure_ty,
@ -1034,7 +1034,7 @@ fn convert_var(
let ref_closure_ty = cx.tcx.mk_ref(region, let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut { ty::TypeAndMut {
ty: closure_ty, ty: closure_ty,
mutbl: hir::MutMutable, mutbl: hir::Mutability::Mutable,
}); });
Expr { Expr {
ty: closure_ty, ty: closure_ty,

View File

@ -257,7 +257,7 @@ pub enum ExprKind<'tcx> {
closure_id: DefId, closure_id: DefId,
substs: UpvarSubsts<'tcx>, substs: UpvarSubsts<'tcx>,
upvars: Vec<ExprRef<'tcx>>, upvars: Vec<ExprRef<'tcx>>,
movability: Option<hir::GeneratorMovability>, movability: Option<hir::Movability>,
}, },
Literal { Literal {
literal: &'tcx Const<'tcx>, literal: &'tcx Const<'tcx>,

View File

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

View File

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

View File

@ -214,16 +214,16 @@ for
// const qualification enforces it. We can lift it in the future. // const qualification enforces it. We can lift it in the future.
match (self.mode, mutability) { match (self.mode, mutability) {
// immutable references are fine everywhere // immutable references are fine everywhere
(_, hir::Mutability::MutImmutable) => {}, (_, hir::Mutability::Immutable) => {},
// all is "good and well" in the unsoundness of `static mut` // all is "good and well" in the unsoundness of `static mut`
// mutable references are ok in `static`. Either they are treated as immutable // 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` // because they are behind an immutable one, or they are behind an `UnsafeCell`
// and thus ok. // 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 // we statically prevent `&mut T` via `const_qualif` and double check this here
(InternMode::ConstBase, hir::Mutability::MutMutable) | (InternMode::ConstBase, hir::Mutability::Mutable) |
(InternMode::Const, hir::Mutability::MutMutable) => { (InternMode::Const, hir::Mutability::Mutable) => {
match referenced_ty.kind { match referenced_ty.kind {
ty::Array(_, n) ty::Array(_, n)
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {} 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 // 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: // mutable reference is equivalent to an immutable one. As an example:
// `&&mut Foo` is semantically equivalent to `&&Foo` // `&&mut Foo` is semantically equivalent to `&&Foo`
(Mutability::Mutable, hir::Mutability::MutMutable) => Mutability::Mutable, (Mutability::Mutable, hir::Mutability::Mutable) => Mutability::Mutable,
_ => Mutability::Immutable, _ => Mutability::Immutable,
}; };
// Recursing behind references changes the intern mode for constants in order to // Recursing behind references changes the intern mode for constants in order to
@ -273,9 +273,9 @@ pub fn intern_const_alloc_recursive(
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
let tcx = ecx.tcx; let tcx = ecx.tcx;
let (base_mutability, base_intern_mode) = match place_mut { 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 // `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? // consts, promoteds. FIXME: what about array lengths, array initializers?
None => (Mutability::Immutable, InternMode::ConstBase), None => (Mutability::Immutable, InternMode::ConstBase),
}; };

View File

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

View File

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

View File

@ -392,7 +392,7 @@ fn make_generator_state_argument_indirect<'tcx>(
let ref_gen_ty = tcx.mk_ref(region, ty::TypeAndMut { let ref_gen_ty = tcx.mk_ref(region, ty::TypeAndMut {
ty: gen_ty, ty: gen_ty,
mutbl: hir::MutMutable mutbl: hir::Mutability::Mutable
}); });
// Replace the by value generator argument // Replace the by value generator argument
@ -977,7 +977,7 @@ fn create_generator_drop_shim<'tcx>(
mutability: Mutability::Mut, mutability: Mutability::Mut,
ty: tcx.mk_ptr(ty::TypeAndMut { ty: tcx.mk_ptr(ty::TypeAndMut {
ty: gen_ty, ty: gen_ty,
mutbl: hir::Mutability::MutMutable, mutbl: hir::Mutability::Mutable,
}), }),
user_ty: UserTypeProjections::none(), user_ty: UserTypeProjections::none(),
name: None, name: None,
@ -1192,7 +1192,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
(substs.upvar_tys(def_id, tcx).collect(), (substs.upvar_tys(def_id, tcx).collect(),
substs.witness(def_id, tcx), substs.witness(def_id, tcx),
substs.discr_ty(tcx), substs.discr_ty(tcx),
movability == hir::GeneratorMovability::Movable) movability == hir::Movability::Movable)
} }
_ => bug!(), _ => bug!(),
}; };

View File

@ -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 if tcx.is_const_fn(def_id) => Mode::ConstFn,
hir::BodyOwnerKind::Fn => Mode::NonConstFn, hir::BodyOwnerKind::Fn => Mode::NonConstFn,
hir::BodyOwnerKind::Const => Mode::Const, hir::BodyOwnerKind::Const => Mode::Const,
hir::BodyOwnerKind::Static(hir::MutImmutable) => Mode::Static, hir::BodyOwnerKind::Static(hir::Mutability::Immutable) => Mode::Static,
hir::BodyOwnerKind::Static(hir::MutMutable) => Mode::StaticMut, hir::BodyOwnerKind::Static(hir::Mutability::Mutable) => Mode::StaticMut,
} }
} }

View File

@ -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 { fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult {
for ty in ty.walk() { for ty in ty.walk() {
match ty.kind { match ty.kind {
ty::Ref(_, _, hir::Mutability::MutMutable) => return Err(( ty::Ref(_, _, hir::Mutability::Mutable) => return Err((
span, span,
"mutable references in const fn are unstable".into(), "mutable references in const fn are unstable".into(),
)), )),

View File

@ -521,7 +521,7 @@ where
let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
ty, ty,
mutbl: hir::Mutability::MutMutable mutbl: hir::Mutability::Mutable
}); });
let ref_place = self.new_temp(ref_ty); let ref_place = self.new_temp(ref_ty);
let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); 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 { let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut {
ty: ety, ty: ety,
mutbl: hir::Mutability::MutMutable mutbl: hir::Mutability::Mutable
}); });
let ptr = &Place::from(self.new_temp(ref_ty)); let ptr = &Place::from(self.new_temp(ref_ty));
let can_go = &Place::from(self.new_temp(tcx.types.bool)); let can_go = &Place::from(self.new_temp(tcx.types.bool));

View File

@ -7,7 +7,7 @@ use rustc::ty::TyCtxt;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::hir::map::Map; use rustc::hir::map::Map;
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::{self, Node, Destination, GeneratorMovability}; use rustc::hir::{self, Node, Destination, Movability};
use syntax::struct_span_err; use syntax::struct_span_err;
use syntax_pos::Span; use syntax_pos::Span;
use errors::Applicability; use errors::Applicability;
@ -59,7 +59,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
self.with_context(Loop(source), |v| v.visit_block(&b)); self.with_context(Loop(source), |v| v.visit_block(&b));
} }
hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => { hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
let cx = if let Some(GeneratorMovability::Static) = movability { let cx = if let Some(Movability::Static) = movability {
AsyncClosure(span) AsyncClosure(span)
} else { } else {
Closure(span) Closure(span)

View File

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

View File

@ -76,6 +76,6 @@ crate fn generator(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
tcx.mk_generator( tcx.mk_generator(
def_id, def_id,
InternalSubsts::bound_vars_for_item(tcx, def_id), InternalSubsts::bound_vars_for_item(tcx, def_id),
hir::GeneratorMovability::Movable hir::Movability::Movable
) )
} }

View File

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

View File

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

View File

@ -627,7 +627,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
) -> Result<CastKind, CastError> { ) -> Result<CastKind, CastError> {
// array-ptr-cast. // 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 { if let ty::Array(ety, _) = m_expr.ty.kind {
// Due to the limitations of LLVM global constants, // Due to the limitations of LLVM global constants,
// region pointers end up pointing at copies of // region pointers end up pointing at copies of

View File

@ -36,10 +36,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_expr_closure( pub fn check_expr_closure(
&self, &self,
expr: &hir::Expr, expr: &hir::Expr,
_capture: hir::CaptureClause, _capture: hir::CaptureBy,
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
body_id: hir::BodyId, body_id: hir::BodyId,
gen: Option<hir::GeneratorMovability>, gen: Option<hir::Movability>,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!( debug!(
@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_kind: Option<ty::ClosureKind>, opt_kind: Option<ty::ClosureKind>,
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body, body: &'tcx hir::Body,
gen: Option<hir::GeneratorMovability>, gen: Option<hir::Movability>,
expected_sig: Option<ExpectedSig<'tcx>>, expected_sig: Option<ExpectedSig<'tcx>>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!( debug!(

View File

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

View File

@ -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(); 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) { match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
ExplicitSelf::ByValue => "self".to_owned(), ExplicitSelf::ByValue => "self".to_owned(),
ExplicitSelf::ByReference(_, hir::MutImmutable) => "&self".to_owned(), ExplicitSelf::ByReference(_, hir::Mutability::Immutable) => "&self".to_owned(),
ExplicitSelf::ByReference(_, hir::MutMutable) => "&mut self".to_owned(), ExplicitSelf::ByReference(_, hir::Mutability::Mutable) => "&mut self".to_owned(),
_ => format!("self: {}", self_arg_ty) _ => format!("self: {}", self_arg_ty)
} }
}) })

View File

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

View File

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

View File

@ -172,7 +172,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
"prefetch_read_instruction" | "prefetch_write_instruction" => { "prefetch_read_instruction" | "prefetch_write_instruction" => {
(1, vec![tcx.mk_ptr(ty::TypeAndMut { (1, vec![tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutImmutable mutbl: hir::Mutability::Immutable
}), tcx.types.i32], }), tcx.types.i32],
tcx.mk_unit()) tcx.mk_unit())
} }
@ -188,13 +188,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutImmutable mutbl: hir::Mutability::Immutable
}), }),
tcx.types.isize tcx.types.isize
], ],
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutImmutable mutbl: hir::Mutability::Immutable
})) }))
} }
"copy" | "copy_nonoverlapping" => { "copy" | "copy_nonoverlapping" => {
@ -202,11 +202,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutImmutable mutbl: hir::Mutability::Immutable
}), }),
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutMutable mutbl: hir::Mutability::Mutable
}), }),
tcx.types.usize, tcx.types.usize,
], ],
@ -217,11 +217,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutMutable mutbl: hir::Mutability::Mutable
}), }),
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutImmutable mutbl: hir::Mutability::Immutable
}), }),
tcx.types.usize, tcx.types.usize,
], ],
@ -232,7 +232,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { tcx.mk_ptr(ty::TypeAndMut {
ty: param(0), ty: param(0),
mutbl: hir::MutMutable mutbl: hir::Mutability::Mutable
}), }),
tcx.types.u8, tcx.types.u8,
tcx.types.usize, tcx.types.usize,
@ -357,14 +357,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
} }
"va_start" | "va_end" => { "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()), 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") None => bug!("`va_list` language item needed for C-variadic intrinsics")
} }
} }
"va_copy" => { "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)) => { Some((va_list_ref_ty, va_list_ty)) => {
let va_list_ptr_ty = tcx.mk_mut_ptr(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()) (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" => { "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)), Some((va_list_ref_ty, _)) => (1, vec![va_list_ref_ty], param(0)),
None => bug!("`va_list` language item needed for C-variadic intrinsics") None => bug!("`va_list` language item needed for C-variadic intrinsics")
} }

View File

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

View File

@ -606,11 +606,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let lang_def_id = lang_items.slice_u8_alloc_impl(); let lang_def_id = lang_items.slice_u8_alloc_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id); 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(); let lang_def_id = lang_items.const_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id); 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(); let lang_def_id = lang_items.mut_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id); 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) 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_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::Mutability::Immutable).or_else(|| {
self.pick_autorefd_method(step, self_ty, hir::MutMutable) self.pick_autorefd_method(step, self_ty, hir::Mutability::Mutable)
})})}) })})})
.next() .next()
} }

View File

@ -387,8 +387,8 @@ pub enum Needs {
impl Needs { impl Needs {
fn maybe_mut_place(m: hir::Mutability) -> Self { fn maybe_mut_place(m: hir::Mutability) -> Self {
match m { match m {
hir::MutMutable => Needs::MutPlace, hir::Mutability::Mutable => Needs::MutPlace,
hir::MutImmutable => Needs::None, hir::Mutability::Immutable => Needs::None,
} }
} }
} }
@ -1090,7 +1090,7 @@ struct GeneratorTypes<'tcx> {
interior: Ty<'tcx>, interior: Ty<'tcx>,
/// Indicates if the generator is movable or static (immovable). /// Indicates if the generator is movable or static (immovable).
movability: hir::GeneratorMovability, movability: hir::Movability,
} }
/// Helper used for fns and closures. Does the grungy work of checking a function /// Helper used for fns and closures. Does the grungy work of checking a function
@ -1106,7 +1106,7 @@ fn check_fn<'a, 'tcx>(
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
fn_id: hir::HirId, fn_id: hir::HirId,
body: &'tcx hir::Body, body: &'tcx hir::Body,
can_be_generator: Option<hir::GeneratorMovability>, can_be_generator: Option<hir::Movability>,
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) { ) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
let mut fn_sig = fn_sig.clone(); let mut fn_sig = fn_sig.clone();
@ -1281,7 +1281,7 @@ fn check_fn<'a, 'tcx>(
ty::Ref(region, ty, mutbl) => match ty.kind { ty::Ref(region, ty, mutbl) => match ty.kind {
ty::Adt(ref adt, _) => { ty::Adt(ref adt, _) => {
adt.did == panic_info_did && adt.did == panic_info_did &&
mutbl == hir::Mutability::MutImmutable && mutbl == hir::Mutability::Immutable &&
*region != RegionKind::ReStatic *region != RegionKind::ReStatic
}, },
_ => false, _ => false,
@ -3197,8 +3197,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut adjustments = autoderef.adjust_steps(self, needs); let mut adjustments = autoderef.adjust_steps(self, needs);
if let ty::Ref(region, _, r_mutbl) = method.sig.inputs()[0].kind { if let ty::Ref(region, _, r_mutbl) = method.sig.inputs()[0].kind {
let mutbl = match r_mutbl { let mutbl = match r_mutbl {
hir::MutImmutable => AutoBorrowMutability::Immutable, hir::Mutability::Immutable => AutoBorrowMutability::Immutable,
hir::MutMutable => AutoBorrowMutability::Mutable { hir::Mutability::Mutable => AutoBorrowMutability::Mutable {
// Indexing can be desugared to a method call, // Indexing can be desugared to a method call,
// so maybe we could use two-phase here. // so maybe we could use two-phase here.
// See the documentation of AllowTwoPhase for why that's // See the documentation of AllowTwoPhase for why that's

View File

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

View File

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

View File

@ -81,7 +81,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
closure_hir_id: hir::HirId, closure_hir_id: hir::HirId,
span: Span, span: Span,
body: &hir::Body, body: &hir::Body,
capture_clause: hir::CaptureClause, capture_clause: hir::CaptureBy,
) { ) {
/*! /*!
* Analysis starting point. * Analysis starting point.
@ -141,8 +141,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
upvar_list.insert(var_hir_id, upvar_id); upvar_list.insert(var_hir_id, upvar_id);
let capture_kind = match capture_clause { let capture_kind = match capture_clause {
hir::CaptureByValue => ty::UpvarCapture::ByValue, hir::CaptureBy::Value => ty::UpvarCapture::ByValue,
hir::CaptureByRef => { hir::CaptureBy::Ref => {
let origin = UpvarRegion(upvar_id, span); let origin = UpvarRegion(upvar_id, span);
let upvar_region = self.next_region_var(origin); let upvar_region = self.next_region_var(origin);
let upvar_borrow = ty::UpvarBorrow { let upvar_borrow = ty::UpvarBorrow {

View File

@ -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>, let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
mt_b: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'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, infcx.report_mismatched_types(&cause,
mk_ptr(mt_b.ty), mk_ptr(mt_b.ty),
target, target,

View File

@ -107,7 +107,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
"[T]", "[T]",
item.span); 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, self.check_primitive_impl(def_id,
lang_items.const_ptr_impl(), lang_items.const_ptr_impl(),
None, None,
@ -115,7 +115,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
"*const T", "*const T",
item.span); 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, self.check_primitive_impl(def_id,
lang_items.mut_ptr_impl(), lang_items.mut_ptr_impl(),
None, None,

View File

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

View File

@ -3859,8 +3859,8 @@ pub enum Mutability {
impl Clean<Mutability> for hir::Mutability { impl Clean<Mutability> for hir::Mutability {
fn clean(&self, _: &DocContext<'_>) -> Mutability { fn clean(&self, _: &DocContext<'_>) -> Mutability {
match self { match self {
&hir::MutMutable => Mutable, &hir::Mutability::Mutable => Mutable,
&hir::MutImmutable => Immutable, &hir::Mutability::Immutable => Immutable,
} }
} }
} }

View File

@ -733,6 +733,30 @@ pub enum Mutability {
Immutable, 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)] #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
pub enum BinOpKind { pub enum BinOpKind {
/// The `+` operator (addition) /// The `+` operator (addition)
@ -1315,10 +1339,14 @@ pub enum CaptureBy {
Ref, Ref,
} }
/// The movability of a generator / closure literal. /// The movability of a generator / closure literal:
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] /// whether a generator contains self-references, causing it to be `!Unpin`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, Debug, Copy)]
pub enum Movability { pub enum Movability {
/// May contain self-references, `!Unpin`.
Static, Static,
/// Must not contain self-references, `Unpin`.
Movable, Movable,
} }
@ -1967,12 +1995,34 @@ pub enum IsAuto {
No, No,
} }
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, Debug)]
pub enum Unsafety { pub enum Unsafety {
Unsafe, Unsafe,
Normal, 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)] #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum IsAsync { pub enum IsAsync {
Async { Async {
@ -2017,18 +2067,6 @@ pub enum Defaultness {
Final, 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)] #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub enum ImplPolarity { pub enum ImplPolarity {
/// `impl Trait for Type` /// `impl Trait for Type`