Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove unused lowering field and method #51034

Merged
merged 1 commit into from
May 26, 2018
Merged
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
101 changes: 35 additions & 66 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ pub struct LoweringContext<'a> {

cstore: &'a CrateStore,

// As we walk the AST we must keep track of the current 'parent' def id (in
// the form of a DefIndex) so that if we create a new node which introduces
// a definition, then we can properly create the def id.
parent_def: Option<DefIndex>,
resolver: &'a mut Resolver,
name_map: FxHashMap<Ident, Name>,

Expand Down Expand Up @@ -205,7 +201,6 @@ pub fn lower_crate(
crate_root: std_inject::injected_crate_name(),
sess,
cstore,
parent_def: None,
resolver,
name_map: FxHashMap(),
items: BTreeMap::new(),
Expand Down Expand Up @@ -885,22 +880,6 @@ impl<'a> LoweringContext<'a> {
result
}

fn with_parent_def<T, F>(&mut self, parent_id: NodeId, f: F) -> T
where
F: FnOnce(&mut LoweringContext) -> T,
{
let old_def = self.parent_def;
self.parent_def = {
let defs = self.resolver.definitions();
Some(defs.opt_def_index(parent_id).unwrap())
};

let result = f(self);

self.parent_def = old_def;
result
}

fn def_key(&mut self, id: DefId) -> DefKey {
if id.is_local() {
self.resolver.definitions().def_key(id.index)
Expand Down Expand Up @@ -2461,23 +2440,22 @@ impl<'a> LoweringContext<'a> {
}

fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
self.with_parent_def(i.id, |this| {
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(i.id);
let trait_item_def_id = this.resolver.definitions().local_def_id(node_id);
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
let trait_item_def_id = self.resolver.definitions().local_def_id(node_id);

let (generics, node) = match i.node {
TraitItemKind::Const(ref ty, ref default) => (
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::TraitItemKind::Const(
this.lower_ty(ty, ImplTraitContext::Disallowed),
self.lower_ty(ty, ImplTraitContext::Disallowed),
default
.as_ref()
.map(|x| this.lower_body(None, |this| this.lower_expr(x))),
.map(|x| self.lower_body(None, |this| this.lower_expr(x))),
),
),
TraitItemKind::Method(ref sig, None) => {
let names = this.lower_fn_args_to_names(&sig.decl);
this.add_in_band_defs(
let names = self.lower_fn_args_to_names(&sig.decl);
self.add_in_band_defs(
&i.generics,
trait_item_def_id,
AnonymousLifetimeMode::PassThrough,
Expand All @@ -2490,12 +2468,12 @@ impl<'a> LoweringContext<'a> {
)
}
TraitItemKind::Method(ref sig, Some(ref body)) => {
let body_id = this.lower_body(Some(&sig.decl), |this| {
let body_id = self.lower_body(Some(&sig.decl), |this| {
let body = this.lower_block(body, false);
this.expr_block(body, ThinVec::new())
});

this.add_in_band_defs(
self.add_in_band_defs(
&i.generics,
trait_item_def_id,
AnonymousLifetimeMode::PassThrough,
Expand All @@ -2508,12 +2486,12 @@ impl<'a> LoweringContext<'a> {
)
}
TraitItemKind::Type(ref bounds, ref default) => (
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::TraitItemKind::Type(
this.lower_bounds(bounds, ImplTraitContext::Disallowed),
self.lower_bounds(bounds, ImplTraitContext::Disallowed),
default
.as_ref()
.map(|x| this.lower_ty(x, ImplTraitContext::Disallowed)),
.map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)),
),
),
TraitItemKind::Macro(..) => panic!("Shouldn't exist any more"),
Expand All @@ -2522,13 +2500,12 @@ impl<'a> LoweringContext<'a> {
hir::TraitItem {
id: node_id,
hir_id,
name: this.lower_ident(i.ident),
attrs: this.lower_attrs(&i.attrs),
name: self.lower_ident(i.ident),
attrs: self.lower_attrs(&i.attrs),
generics,
node,
span: i.span,
}
})
}

fn lower_trait_item_ref(&mut self, i: &TraitItem) -> hir::TraitItemRef {
Expand Down Expand Up @@ -2557,29 +2534,28 @@ impl<'a> LoweringContext<'a> {
}

fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
self.with_parent_def(i.id, |this| {
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(i.id);
let impl_item_def_id = this.resolver.definitions().local_def_id(node_id);
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
let impl_item_def_id = self.resolver.definitions().local_def_id(node_id);

let (generics, node) = match i.node {
ImplItemKind::Const(ref ty, ref expr) => {
let body_id = this.lower_body(None, |this| this.lower_expr(expr));
let body_id = self.lower_body(None, |this| this.lower_expr(expr));
(
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::ImplItemKind::Const(
this.lower_ty(ty, ImplTraitContext::Disallowed),
self.lower_ty(ty, ImplTraitContext::Disallowed),
body_id,
),
)
}
ImplItemKind::Method(ref sig, ref body) => {
let body_id = this.lower_body(Some(&sig.decl), |this| {
let body_id = self.lower_body(Some(&sig.decl), |this| {
let body = this.lower_block(body, false);
this.expr_block(body, ThinVec::new())
});
let impl_trait_return_allow = !this.is_in_trait_impl;
let impl_trait_return_allow = !self.is_in_trait_impl;

this.add_in_band_defs(
self.add_in_band_defs(
&i.generics,
impl_item_def_id,
AnonymousLifetimeMode::PassThrough,
Expand All @@ -2596,24 +2572,23 @@ impl<'a> LoweringContext<'a> {
)
}
ImplItemKind::Type(ref ty) => (
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::ImplItemKind::Type(this.lower_ty(ty, ImplTraitContext::Disallowed)),
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::ImplItemKind::Type(self.lower_ty(ty, ImplTraitContext::Disallowed)),
),
ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"),
};

hir::ImplItem {
id: node_id,
hir_id,
name: this.lower_ident(i.ident),
attrs: this.lower_attrs(&i.attrs),
name: self.lower_ident(i.ident),
attrs: self.lower_attrs(&i.attrs),
generics,
vis: this.lower_visibility(&i.vis, None),
defaultness: this.lower_defaultness(i.defaultness, true /* [1] */),
vis: self.lower_visibility(&i.vis, None),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
node,
span: i.span,
}
})

// [1] since `default impl` is not yet implemented, this is always true in impls
}
Expand Down Expand Up @@ -2689,9 +2664,7 @@ impl<'a> LoweringContext<'a> {
return None;
}

let node = self.with_parent_def(i.id, |this| {
this.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node)
});
let node = self.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node);

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);

Expand All @@ -2707,16 +2680,15 @@ impl<'a> LoweringContext<'a> {
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem {
self.with_parent_def(i.id, |this| {
let node_id = this.lower_node_id(i.id).node_id;
let def_id = this.resolver.definitions().local_def_id(node_id);
let node_id = self.lower_node_id(i.id).node_id;
let def_id = self.resolver.definitions().local_def_id(node_id);
hir::ForeignItem {
id: node_id,
name: i.ident.name,
attrs: this.lower_attrs(&i.attrs),
attrs: self.lower_attrs(&i.attrs),
node: match i.node {
ForeignItemKind::Fn(ref fdec, ref generics) => {
let (generics, (fn_dec, fn_args)) = this.add_in_band_defs(
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
generics,
def_id,
AnonymousLifetimeMode::PassThrough,
Expand All @@ -2732,15 +2704,14 @@ impl<'a> LoweringContext<'a> {
hir::ForeignItemFn(fn_dec, fn_args, generics)
}
ForeignItemKind::Static(ref t, m) => {
hir::ForeignItemStatic(this.lower_ty(t, ImplTraitContext::Disallowed), m)
hir::ForeignItemStatic(self.lower_ty(t, ImplTraitContext::Disallowed), m)
}
ForeignItemKind::Ty => hir::ForeignItemType,
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),
},
vis: this.lower_visibility(&i.vis, None),
vis: self.lower_visibility(&i.vis, None),
span: i.span,
}
})
}

fn lower_method_sig(
Expand Down Expand Up @@ -3064,7 +3035,6 @@ impl<'a> LoweringContext<'a> {
),
ExprKind::Closure(capture_clause, movability, ref decl, ref body, fn_decl_span) => {
self.with_new_scopes(|this| {
this.with_parent_def(e.id, |this| {
let mut is_generator = false;
let body_id = this.lower_body(Some(decl), |this| {
let e = this.lower_expr(body);
Expand Down Expand Up @@ -3104,7 +3074,6 @@ impl<'a> LoweringContext<'a> {
generator_option,
)
})
})
}
ExprKind::Block(ref blk, opt_label) => {
hir::ExprBlock(self.lower_block(blk,
Expand Down