Skip to content

Commit 73e2fe0

Browse files
committed
Properly implement should_encode_fn_impl_trait_in_trait using new unstable option
1 parent 811a1ca commit 73e2fe0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,18 @@ fn should_encode_const(def_kind: DefKind) -> bool {
11011101
}
11021102
}
11031103

1104-
// Return `false` to avoid encoding impl trait in trait, while we don't use the query.
1105-
fn should_encode_fn_impl_trait_in_trait<'tcx>(_tcx: TyCtxt<'tcx>, _def_id: DefId) -> bool {
1106-
false
1104+
// We only encode impl trait in trait when using `lower-impl-trait-in-trait-to-assoc-ty` unstable
1105+
// option.
1106+
fn should_encode_fn_impl_trait_in_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1107+
if tcx.sess.opts.unstable_opts.lower_impl_trait_in_trait_to_assoc_ty
1108+
&& let Some(assoc_item) = tcx.opt_associated_item(def_id)
1109+
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
1110+
&& assoc_item.kind == ty::AssocKind::Fn
1111+
{
1112+
true
1113+
} else {
1114+
false
1115+
}
11071116
}
11081117

11091118
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

0 commit comments

Comments
 (0)