diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 278f45371b151..02afdc27acdca 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1213,7 +1213,7 @@ impl<'a> LoweringContext<'a> { &NodeMap::default(), ImplTraitContext::disallowed(), ), - unsafety: this.lower_unsafety(f.unsafety), + unsafety: f.unsafety, abi: this.lower_abi(f.abi), decl: this.lower_fn_decl(&f.decl, None, false, None), param_names: this.lower_fn_params_to_names(&f.decl), @@ -2077,13 +2077,6 @@ impl<'a> LoweringContext<'a> { }, ids) } - fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability { - match m { - Mutability::Mutable => hir::MutMutable, - Mutability::Immutable => hir::MutImmutable, - } - } - fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec { // Skip the `...` (`CVarArgs`) trailing arguments from the AST, // as they are not explicit in HIR/Ty function signatures. @@ -2653,7 +2646,7 @@ impl<'a> LoweringContext<'a> { fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy { hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), - mutbl: self.lower_mutability(mt.mutbl), + mutbl: mt.mutbl, } } @@ -2754,7 +2747,7 @@ impl<'a> LoweringContext<'a> { } PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)), PatKind::Ref(ref inner, mutbl) => { - hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl)) + hir::PatKind::Ref(self.lower_pat(inner), mutbl) } PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range( P(self.lower_expr(e1)), diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 73db762a64bda..ff5a9a34053ae 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -64,7 +64,6 @@ impl LoweringContext<'_> { hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed())) } ExprKind::AddrOf(m, ref ohs) => { - let m = self.lower_mutability(m); let ohs = P(self.lower_expr(ohs)); hir::ExprKind::AddrOf(m, ohs) } @@ -474,7 +473,6 @@ impl LoweringContext<'_> { async_gen_kind: hir::AsyncGeneratorKind, body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, ) -> hir::ExprKind { - let capture_clause = self.lower_capture_clause(capture_clause); let output = match ret_ty { Some(ty) => FunctionRetTy::Ty(ty), None => FunctionRetTy::Default(span), @@ -495,7 +493,7 @@ impl LoweringContext<'_> { decl, body_id, span, - Some(hir::GeneratorMovability::Static) + Some(hir::Movability::Static) ); let generator = hir::Expr { hir_id: self.lower_node_id(closure_node_id), @@ -701,7 +699,6 @@ impl LoweringContext<'_> { generator_kind, movability, ); - let capture_clause = this.lower_capture_clause(capture_clause); this.current_item = prev; hir::ExprKind::Closure( 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( &mut self, decl: &FnDecl, fn_decl_span: Span, generator_kind: Option, movability: Movability, - ) -> Option { + ) -> Option { match generator_kind { Some(hir::GeneratorKind::Gen) => { if !decl.inputs.is_empty() { @@ -737,10 +727,7 @@ impl LoweringContext<'_> { "generators cannot have explicit parameters" ); } - Some(match movability { - Movability::Movable => hir::GeneratorMovability::Movable, - Movability::Static => hir::GeneratorMovability::Static, - }) + Some(movability) }, Some(hir::GeneratorKind::Async(_)) => { bug!("non-`async` closure body turned `async` during lowering"); @@ -811,7 +798,7 @@ impl LoweringContext<'_> { this.expr(fn_decl_span, async_body, ThinVec::new()) }); hir::ExprKind::Closure( - this.lower_capture_clause(capture_clause), + capture_clause, fn_decl, body_id, fn_decl_span, @@ -1350,7 +1337,7 @@ impl LoweringContext<'_> { } fn expr_mut_addr_of(&mut self, span: Span, e: P) -> hir::Expr { - self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new()) + self.expr(span, hir::ExprKind::AddrOf(hir::Mutability::Mutable, e), ThinVec::new()) } fn expr_unit(&mut self, sp: Span) -> hir::Expr { diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 7aa1aa8bb514a..beb10edd14840 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -19,7 +19,7 @@ use smallvec::SmallVec; use syntax::attr; use syntax::ast::*; use syntax::visit::{self, Visitor}; -use syntax::source_map::{respan, DesugaringKind, Spanned}; +use syntax::source_map::{respan, DesugaringKind}; use syntax::symbol::{kw, sym}; use syntax_pos::Span; @@ -289,7 +289,7 @@ impl LoweringContext<'_> { ImplTraitContext::Disallowed(ImplTraitPosition::Binding) } ), - self.lower_mutability(m), + m, self.lower_const_body(e), ) } @@ -433,8 +433,8 @@ impl LoweringContext<'_> { ); hir::ItemKind::Impl( - self.lower_unsafety(unsafety), - self.lower_impl_polarity(polarity), + unsafety, + polarity, self.lower_defaultness(defaultness, true /* [1] */), generics, trait_ref, @@ -449,8 +449,8 @@ impl LoweringContext<'_> { .map(|item| self.lower_trait_item_ref(item)) .collect(); hir::ItemKind::Trait( - self.lower_is_auto(is_auto), - self.lower_unsafety(unsafety), + is_auto, + unsafety, self.lower_generics(generics, ImplTraitContext::disallowed()), bounds, items, @@ -719,7 +719,7 @@ impl LoweringContext<'_> { } ForeignItemKind::Static(ref t, m) => { hir::ForeignItemKind::Static( - self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m)) + self.lower_ty(t, ImplTraitContext::disallowed()), m) } ForeignItemKind::Ty => hir::ForeignItemKind::Type, ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"), @@ -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, value: hir::Expr) -> hir::BodyId { let body = hir::Body { generator_kind: self.generator_kind, @@ -1275,18 +1268,11 @@ impl LoweringContext<'_> { (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 { hir::FnHeader { - unsafety: self.lower_unsafety(h.unsafety), + unsafety: h.unsafety, asyncness: self.lower_asyncness(h.asyncness.node), - constness: self.lower_constness(h.constness), + constness: h.constness.node, abi: self.lower_abi(h.abi), } } @@ -1311,20 +1297,6 @@ impl LoweringContext<'_> { .emit(); } - pub(super) fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety { - match u { - Unsafety::Unsafe => hir::Unsafety::Unsafe, - Unsafety::Normal => hir::Unsafety::Normal, - } - } - - fn lower_constness(&mut self, c: Spanned) -> hir::Constness { - match c.node { - Constness::Const => hir::Constness::Const, - Constness::NotConst => hir::Constness::NotConst, - } - } - fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync { match a { IsAsync::Async { .. } => hir::IsAsync::Async, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 83f68e210bd94..bbd3b40e1be90 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -3,9 +3,7 @@ //! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html pub use self::BlockCheckMode::*; -pub use self::CaptureClause::*; pub use self::FunctionRetTy::*; -pub use self::Mutability::*; pub use self::PrimTy::*; pub use self::UnOp::*; pub use self::UnsafeSource::*; @@ -23,6 +21,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan}; use syntax::source_map::Spanned; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; +pub use syntax::ast::{Mutability, Constness, Unsafety, Movability, CaptureBy, IsAuto, ImplPolarity}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::symbol::{Symbol, kw}; use syntax::tokenstream::TokenStream; @@ -1053,37 +1052,6 @@ pub enum PatKind { Slice(HirVec>, Option>, HirVec>), } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, - RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Mutability { - MutMutable, - MutImmutable, -} - -impl Mutability { - /// Returns `MutMutable` only if both `self` and `other` are mutable. - pub fn and(self, other: Self) -> Self { - match self { - MutMutable => other, - MutImmutable => MutImmutable, - } - } - - pub fn invert(self) -> Self { - match self { - MutMutable => MutImmutable, - MutImmutable => MutMutable, - } - } - - pub fn prefix_str(&self) -> &'static str { - match self { - MutMutable => "mut ", - MutImmutable => "", - } - } -} - #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum BinOpKind { /// The `+` operator (addition). @@ -1659,8 +1627,8 @@ pub enum ExprKind { /// The `Span` is the argument block `|...|`. /// /// This may also be a generator literal or an `async block` as indicated by the - /// `Option`. - Closure(CaptureClause, P, BodyId, Span, Option), + /// `Option`. + Closure(CaptureBy, P, BodyId, Span, Option), /// A block (e.g., `'label: { ... }`). Block(P, Option