diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2024-12-15 20:01:39 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-15 20:01:39 +1100 |
| commit | 81378c82587d688223b87602c17d733aa823459a (patch) | |
| tree | fccf469f718e3c39cb521717ec6b8c05cdec0b7a | |
| parent | b9741879509e2ca0c10477f01b07b997e6cbd8e0 (diff) | |
| parent | ca055ee7db17fbeccb2893db8f24440a25afff44 (diff) | |
| download | rust-81378c82587d688223b87602c17d733aa823459a.tar.gz rust-81378c82587d688223b87602c17d733aa823459a.zip | |
Rollup merge of #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 #134307
r? oli-obk
| -rw-r--r-- | compiler/rustc_resolve/src/def_collector.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 1 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-bindings/dont-make-def-id.rs | 10 |
3 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 66492842581..ec442e22204 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -356,6 +356,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { let kind = match self.impl_trait_context { ImplTraitContext::Universal => DefKind::TyParam, ImplTraitContext::Existential => DefKind::OpaqueTy, + ImplTraitContext::InBinding => return visit::walk_ty(self, ty), }; let id = self.create_def(*id, name, kind, ty.span); match self.impl_trait_context { @@ -365,6 +366,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { ImplTraitContext::Existential => { self.with_parent(id, |this| visit::walk_ty(this, ty)) } + ImplTraitContext::InBinding => unreachable!(), }; } _ => visit::walk_ty(self, ty), @@ -374,6 +376,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { fn visit_stmt(&mut self, stmt: &'a Stmt) { match stmt.kind { StmtKind::MacCall(..) => self.visit_macro_invoc(stmt.id), + // FIXME(impl_trait_in_bindings): We don't really have a good way of + // introducing the right `ImplTraitContext` here for all the cases we + // care about, in case we want to introduce ITIB to other positions + // such as turbofishes (e.g. `foo::<impl Fn()>(|| {})`). + StmtKind::Let(ref local) => self.with_impl_trait(ImplTraitContext::InBinding, |this| { + visit::walk_local(this, local) + }), _ => visit::walk_stmt(self, stmt), } } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 94adfcd3b91..5c4c401af31 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -190,6 +190,7 @@ impl InvocationParent { enum ImplTraitContext { Existential, Universal, + InBinding, } /// Used for tracking import use types which will be used for redundant import checking. diff --git a/tests/ui/impl-trait/in-bindings/dont-make-def-id.rs b/tests/ui/impl-trait/in-bindings/dont-make-def-id.rs new file mode 100644 index 00000000000..d159e9ab0f9 --- /dev/null +++ b/tests/ui/impl-trait/in-bindings/dont-make-def-id.rs @@ -0,0 +1,10 @@ +//@ check-pass + +// Make sure we don't create an opaque def id for ITIB. + +#![crate_type = "lib"] +#![feature(impl_trait_in_bindings)] + +fn foo() { + let _: impl Sized = 0; +} |
