1
Fork 0

Do not insert impl_trait_in_bindings opaque definitions twice.

This commit is contained in:
Camille GILLOT 2021-03-14 20:02:35 +01:00
parent 178bd9130e
commit 3612953487

View file

@ -1788,14 +1788,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) )
} }
fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) { fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
let mut ids = SmallVec::<[NodeId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
visitor.visit_ty(ty);
}
}
let ty = l.ty.as_ref().map(|t| { let ty = l.ty.as_ref().map(|t| {
let mut capturable_lifetimes; let mut capturable_lifetimes;
self.lower_ty( self.lower_ty(
@ -1814,17 +1807,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let init = l.init.as_ref().map(|e| self.lower_expr(e)); let init = l.init.as_ref().map(|e| self.lower_expr(e));
let hir_id = self.lower_node_id(l.id); let hir_id = self.lower_node_id(l.id);
self.lower_attrs(hir_id, &l.attrs); self.lower_attrs(hir_id, &l.attrs);
( hir::Local {
hir::Local { hir_id,
hir_id, ty,
ty, pat: self.lower_pat(&l.pat),
pat: self.lower_pat(&l.pat), init,
init, span: l.span,
span: l.span, source: hir::LocalSource::Normal,
source: hir::LocalSource::Normal, }
},
ids,
)
} }
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] { fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@ -2438,27 +2428,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> { fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
let (hir_id, kind) = match s.kind { let (hir_id, kind) = match s.kind {
StmtKind::Local(ref l) => { StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l); let l = self.lower_local(l);
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
.into_iter()
.map(|item_id| {
let item_id = hir::ItemId {
// All the items that `lower_local` finds are `impl Trait` types.
def_id: self.lower_node_id(item_id).expect_owner(),
};
self.stmt(s.span, hir::StmtKind::Item(item_id))
})
.collect();
let hir_id = self.lower_node_id(s.id); let hir_id = self.lower_node_id(s.id);
self.alias_attrs(hir_id, l.hir_id); self.alias_attrs(hir_id, l.hir_id);
ids.push({ return smallvec![hir::Stmt {
hir::Stmt { hir_id,
hir_id, kind: hir::StmtKind::Local(self.arena.alloc(l)),
kind: hir::StmtKind::Local(self.arena.alloc(l)), span: s.span,
span: s.span, }];
}
});
return ids;
} }
StmtKind::Item(ref it) => { StmtKind::Item(ref it) => {
// Can only use the ID once. // Can only use the ID once.