about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2023-02-28 13:13:31 -0300
committerSantiago Pastorino <spastorino@gmail.com>2023-03-01 14:13:41 -0300
commit73e2fe0494cd91565f2f836af59b2fa37ab3ebdd (patch)
tree77b9fa7f6942ad048cdf3874b55ba75f7a4145f7
parent811a1cabda19ea4d6c6636e43dc760a3fcc685fd (diff)
downloadrust-73e2fe0494cd91565f2f836af59b2fa37ab3ebdd.tar.gz
rust-73e2fe0494cd91565f2f836af59b2fa37ab3ebdd.zip
Properly implement should_encode_fn_impl_trait_in_trait using new unstable option
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 27490a09a36..ccb07804b96 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -1101,9 +1101,18 @@ fn should_encode_const(def_kind: DefKind) -> bool {
     }
 }
 
-// Return `false` to avoid encoding impl trait in trait, while we don't use the query.
-fn should_encode_fn_impl_trait_in_trait<'tcx>(_tcx: TyCtxt<'tcx>, _def_id: DefId) -> bool {
-    false
+// We only encode impl trait in trait when using `lower-impl-trait-in-trait-to-assoc-ty` unstable
+// option.
+fn should_encode_fn_impl_trait_in_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
+    if tcx.sess.opts.unstable_opts.lower_impl_trait_in_trait_to_assoc_ty
+        && let Some(assoc_item) = tcx.opt_associated_item(def_id)
+        && assoc_item.container == ty::AssocItemContainer::TraitContainer
+        && assoc_item.kind == ty::AssocKind::Fn
+    {
+        true
+    } else {
+        false
+    }
 }
 
 impl<'a, 'tcx> EncodeContext<'a, 'tcx> {