Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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<Ident> {
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
// as they are not explicit in HIR/Ty function signatures.
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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)),
Expand Down
23 changes: 5 additions & 18 deletions src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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<hir::GeneratorKind>,
movability: Movability,
) -> Option<hir::GeneratorMovability> {
) -> Option<hir::Movability> {
match generator_kind {
Some(hir::GeneratorKind::Gen) => {
if !decl.inputs.is_empty() {
Expand All @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1350,7 +1337,7 @@ impl LoweringContext<'_> {
}

fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
self.expr(span, hir::ExprKind::AddrOf(hir::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 {
Expand Down
46 changes: 9 additions & 37 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -289,7 +289,7 @@ impl LoweringContext<'_> {
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
}
),
self.lower_mutability(m),
m,
self.lower_const_body(e),
)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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 {
let body = hir::Body {
generator_kind: self.generator_kind,
Expand Down Expand Up @@ -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),
}
}
Expand All @@ -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<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 {
match a {
IsAsync::Async { .. } => hir::IsAsync::Async,
Expand Down
Loading