Skip to content

Commit 17a627f

Browse files
committed
Auto merge of #101682 - compiler-errors:rpitit-encode, r=fee1-dead
Only encode return-position `impl Trait` in trait when parent function has a default body Semi-blocked on #101679, because I can't currently write a test for when we _should_ encode the type of the return-position `impl Trait` in trait, which is when a trait has a default function body, like so: ```rust trait Foo { fn bar() -> impl Sized { } } ``` Though this can land even without #101679, since it does prevent ICEs from occuring any time you use `#![feature(return_position_impl_trait_in_trait)]` in a library, which is kind annoying.
2 parents 6f0c4a6 + 1335da9 commit 17a627f

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)