Skip to content

Commit dba97da

Browse files
authored
Rollup merge of rust-lang#83124 - cjgillot:iiib, r=petrochenkov
Do not insert impl_trait_in_bindings opaque definitions twice. The reference to the item already appears inside the `OpaqueDef`. It does not need to be repeated as a statement.
2 parents c73d157 + e8b2e7b commit dba97da

File tree

2 files changed

+17
-66
lines changed

2 files changed

+17
-66
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+15-63
Original file line numberDiff line numberDiff line change
@@ -438,31 +438,6 @@ impl<'a> TokenStreamLowering<'a> {
438438
}
439439
}
440440

441-
struct ImplTraitTypeIdVisitor<'a> {
442-
ids: &'a mut SmallVec<[NodeId; 1]>,
443-
}
444-
445-
impl Visitor<'_> for ImplTraitTypeIdVisitor<'_> {
446-
fn visit_ty(&mut self, ty: &Ty) {
447-
match ty.kind {
448-
TyKind::Typeof(_) | TyKind::BareFn(_) => return,
449-
450-
TyKind::ImplTrait(id, _) => self.ids.push(id),
451-
_ => {}
452-
}
453-
visit::walk_ty(self, ty);
454-
}
455-
456-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
457-
if let Some(ref p) = path_segment.args {
458-
if let GenericArgs::Parenthesized(_) = **p {
459-
return;
460-
}
461-
}
462-
visit::walk_path_segment(self, path_span, path_segment)
463-
}
464-
}
465-
466441
impl<'a, 'hir> LoweringContext<'a, 'hir> {
467442
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
468443
/// Full-crate AST visitor that inserts into a fresh
@@ -1789,14 +1764,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17891764
)
17901765
}
17911766

1792-
fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
1793-
let mut ids = SmallVec::<[NodeId; 1]>::new();
1794-
if self.sess.features_untracked().impl_trait_in_bindings {
1795-
if let Some(ref ty) = l.ty {
1796-
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
1797-
visitor.visit_ty(ty);
1798-
}
1799-
}
1767+
fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
18001768
let ty = l.ty.as_ref().map(|t| {
18011769
let mut capturable_lifetimes;
18021770
self.lower_ty(
@@ -1815,17 +1783,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18151783
let init = l.init.as_ref().map(|e| self.lower_expr(e));
18161784
let hir_id = self.lower_node_id(l.id);
18171785
self.lower_attrs(hir_id, &l.attrs);
1818-
(
1819-
hir::Local {
1820-
hir_id,
1821-
ty,
1822-
pat: self.lower_pat(&l.pat),
1823-
init,
1824-
span: l.span,
1825-
source: hir::LocalSource::Normal,
1826-
},
1827-
ids,
1828-
)
1786+
hir::Local {
1787+
hir_id,
1788+
ty,
1789+
pat: self.lower_pat(&l.pat),
1790+
init,
1791+
span: l.span,
1792+
source: hir::LocalSource::Normal,
1793+
}
18291794
}
18301795

18311796
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@@ -2445,27 +2410,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24452410
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
24462411
let (hir_id, kind) = match s.kind {
24472412
StmtKind::Local(ref l) => {
2448-
let (l, item_ids) = self.lower_local(l);
2449-
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
2450-
.into_iter()
2451-
.map(|item_id| {
2452-
let item_id = hir::ItemId {
2453-
// All the items that `lower_local` finds are `impl Trait` types.
2454-
def_id: self.lower_node_id(item_id).expect_owner(),
2455-
};
2456-
self.stmt(s.span, hir::StmtKind::Item(item_id))
2457-
})
2458-
.collect();
2413+
let l = self.lower_local(l);
24592414
let hir_id = self.lower_node_id(s.id);
24602415
self.alias_attrs(hir_id, l.hir_id);
2461-
ids.push({
2462-
hir::Stmt {
2463-
hir_id,
2464-
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2465-
span: s.span,
2466-
}
2467-
});
2468-
return ids;
2416+
return smallvec![hir::Stmt {
2417+
hir_id,
2418+
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2419+
span: s.span,
2420+
}];
24692421
}
24702422
StmtKind::Item(ref it) => {
24712423
// Can only use the ID once.

compiler/rustc_middle/src/hir/map/collector.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
5252
if i >= len {
5353
map.extend(repeat(None).take(i - len + 1));
5454
}
55+
debug_assert!(map[k].is_none());
5556
map[k] = Some(v);
5657
}
5758

@@ -216,9 +217,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
216217
// Overwrite the dummy hash with the real HIR owner hash.
217218
nodes.hash = hash;
218219

219-
// FIXME: feature(impl_trait_in_bindings) broken and trigger this assert
220-
//assert!(data.signature.is_none());
221-
220+
debug_assert!(data.signature.is_none());
222221
data.signature =
223222
Some(self.arena.alloc(Owner { parent: entry.parent, node: entry.node }));
224223

0 commit comments

Comments
 (0)