Skip to content

Commit 1335da9

Browse files
Only encode RPITIT when trait method has default body
1 parent 1463688 commit 1335da9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
10361036
| DefKind::Static(..)
10371037
| DefKind::TyAlias
10381038
| DefKind::OpaqueTy
1039-
| DefKind::ImplTraitPlaceholder
10401039
| DefKind::ForeignTy
10411040
| DefKind::Impl
10421041
| DefKind::AssocFn
@@ -1047,6 +1046,19 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
10471046
| DefKind::AnonConst
10481047
| DefKind::InlineConst => true,
10491048

1049+
DefKind::ImplTraitPlaceholder => {
1050+
let parent_def_id = tcx.impl_trait_in_trait_parent(def_id.to_def_id());
1051+
let assoc_item = tcx.associated_item(parent_def_id);
1052+
match assoc_item.container {
1053+
// Always encode an RPIT in an impl fn, since it always has a body
1054+
ty::AssocItemContainer::ImplContainer => true,
1055+
ty::AssocItemContainer::TraitContainer => {
1056+
// Encode an RPIT for a trait only if the trait has a default body
1057+
assoc_item.defaultness(tcx).has_value()
1058+
}
1059+
}
1060+
}
1061+
10501062
DefKind::AssocTy => {
10511063
let assoc_item = tcx.associated_item(def_id);
10521064
match assoc_item.container {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
// compile-flags: --crate-type=lib
3+
4+
#![feature(return_position_impl_trait_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
trait Foo {
8+
fn bar() -> impl Sized;
9+
}

0 commit comments

Comments
 (0)