提交 e4c7e2c9 编写于 作者: C Christopher Vittal

Add bool item is_in_impl_trait to LoweringContext

This is for tracking if an ImplItem is part of a trait impl. Add
a with_trait_impl_ref method to ItemLowerer to appropriately save the
state to allow appropriate nesting of trait and non-trait impls.
上级 8fd48e7d
......@@ -103,6 +103,7 @@ pub struct LoweringContext<'a> {
catch_scopes: Vec<NodeId>,
loop_scopes: Vec<NodeId>,
is_in_loop_condition: bool,
is_in_trait_impl: bool,
type_def_lifetime_params: DefIdMap<usize>,
......@@ -174,6 +175,7 @@ pub fn lower_crate(sess: &Session,
item_local_id_counters: NodeMap(),
node_id_to_hir_id: IndexVec::new(),
is_generator: false,
is_in_trait_impl: false,
}.lower_crate(krate)
}
......@@ -241,6 +243,21 @@ struct ItemLowerer<'lcx, 'interner: 'lcx> {
lctx: &'lcx mut LoweringContext<'interner>,
}
impl<'lcx, 'interner> ItemLowerer<'lcx, 'interner> {
fn with_trait_impl_ref<F>(&mut self, trait_impl_ref: &Option<TraitRef>, f: F)
where F: FnOnce(&mut Self)
{
let old = self.lctx.is_in_trait_impl;
self.lctx.is_in_trait_impl = if let &None = trait_impl_ref {
false
} else {
true
};
f(self);
self.lctx.is_in_trait_impl = old;
}
}
impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
fn visit_item(&mut self, item: &'lcx Item) {
let mut item_lowered = true;
......@@ -253,7 +270,13 @@ fn visit_item(&mut self, item: &'lcx Item) {
});
if item_lowered {
visit::walk_item(self, item);
if let ItemKind::Impl(_,_,_,_,ref opt_trait_ref,_,_) = item.node {
self.with_trait_impl_ref(opt_trait_ref, |this| {
visit::walk_item(this, item)
});
} else {
visit::walk_item(self, item);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册