Skip to content

Commit a290c05

Browse files
Don't make a def id for impl_trait_in_bindings
1 parent f1ec5d6 commit a290c05

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

compiler/rustc_resolve/src/def_collector.rs

+9
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
356356
let kind = match self.impl_trait_context {
357357
ImplTraitContext::Universal => DefKind::TyParam,
358358
ImplTraitContext::Existential => DefKind::OpaqueTy,
359+
ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
359360
};
360361
let id = self.create_def(*id, name, kind, ty.span);
361362
match self.impl_trait_context {
@@ -365,6 +366,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
365366
ImplTraitContext::Existential => {
366367
self.with_parent(id, |this| visit::walk_ty(this, ty))
367368
}
369+
ImplTraitContext::InBinding => unreachable!(),
368370
};
369371
}
370372
_ => visit::walk_ty(self, ty),
@@ -374,6 +376,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
374376
fn visit_stmt(&mut self, stmt: &'a Stmt) {
375377
match stmt.kind {
376378
StmtKind::MacCall(..) => self.visit_macro_invoc(stmt.id),
379+
// FIXME(impl_trait_in_bindings): We don't really have a good way of
380+
// introducing the right `ImplTraitContext` here for all the cases we
381+
// care about, in case we want to introduce ITIB to other positions
382+
// such as turbofishes (e.g. `foo::<impl Fn()>(|| {})`).
383+
StmtKind::Let(ref local) => self.with_impl_trait(ImplTraitContext::InBinding, |this| {
384+
visit::walk_local(this, local)
385+
}),
377386
_ => visit::walk_stmt(self, stmt),
378387
}
379388
}

compiler/rustc_resolve/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl InvocationParent {
190190
enum ImplTraitContext {
191191
Existential,
192192
Universal,
193+
InBinding,
193194
}
194195

195196
/// Used for tracking import use types which will be used for redundant import checking.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Make sure we don't create an opaque def id for ITIB.
2+
3+
#![crate_type = "lib"]
4+
#![feature(impl_trait_in_bindings)]
5+
6+
fn foo() {
7+
let _: impl Sized = 0;
8+
}

0 commit comments

Comments
 (0)