Skip to content

Commit 27821fa

Browse files
authored
Unrolled build for rust-lang#134313
Rollup merge of rust-lang#134313 - compiler-errors:no-itib-def-id, r=oli-obk Don't make a def id for `impl_trait_in_bindings` The def collector is awkward, so for now just wrap let statements in a new `ImplTraitContext::InBinding` which tells `visit_ty` not to make a def id for the type. This will not generalize to other ITIB cases, like if we allow them in turbofishes (e.g. `foo::<impl Fn()>(|| {})`). Fixes rust-lang#134307 r? oli-obk
2 parents 87139bd + ca055ee commit 27821fa

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-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,10 @@
1+
//@ check-pass
2+
3+
// Make sure we don't create an opaque def id for ITIB.
4+
5+
#![crate_type = "lib"]
6+
#![feature(impl_trait_in_bindings)]
7+
8+
fn foo() {
9+
let _: impl Sized = 0;
10+
}

0 commit comments

Comments
 (0)