Skip to content
/ rust Public
forked from rust-lang/rust

Commit 126d809

Browse files
Rollup merge of rust-lang#113741 - compiler-errors:rpitit-projects-to-missing-opaque, r=spastorino
Don't install default projection bound for return-position `impl Trait` in trait methods with no body This ensures that we never try to project to an opaque type in a trait method that has no body to infer its hidden type, which means we never later call `type_of` on that opaque. This is because opaque types try to reveal their hidden type when proving auto traits. I thought about this a lot, and I think this is a fix that's less likely to introduce other strange downstream ICEs than rust-lang#113461. Fixes rust-lang#113434 r? `@spastorino`
2 parents 0ad8d6a + 0f0ab89 commit 126d809

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1144,13 +1144,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
11441144
let assoc_item = tcx.associated_item(def_id);
11451145
match assoc_item.container {
11461146
ty::AssocItemContainer::ImplContainer => true,
1147-
// Always encode RPITITs, since we need to be able to project
1148-
// from an RPITIT associated item to an opaque when installing
1149-
// the default projection predicates in default trait methods
1150-
// with RPITITs.
1151-
ty::AssocItemContainer::TraitContainer => {
1152-
assoc_item.defaultness(tcx).has_value() || assoc_item.is_impl_trait_in_trait()
1153-
}
1147+
ty::AssocItemContainer::TraitContainer => assoc_item.defaultness(tcx).has_value(),
11541148
}
11551149
}
11561150
DefKind::TyParam => {

compiler/rustc_ty_utils/src/ty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
129129
// sure that this will succeed without errors anyway.
130130

131131
if tcx.def_kind(def_id) == DefKind::AssocFn
132-
&& tcx.associated_item(def_id).container == ty::AssocItemContainer::TraitContainer
132+
&& let assoc_item = tcx.associated_item(def_id)
133+
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
134+
&& assoc_item.defaultness(tcx).has_value()
133135
{
134136
let sig = tcx.fn_sig(def_id).instantiate_identity();
135137
// We accounted for the binder of the fn sig, so skip the binder.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(return_position_impl_trait_in_trait)]
2+
3+
struct Wrapper<G: Send>(G);
4+
5+
trait Foo {
6+
fn bar() -> Wrapper<impl Sized>;
7+
//~^ ERROR `impl Sized` cannot be sent between threads safely
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: `impl Sized` cannot be sent between threads safely
2+
--> $DIR/check-wf-on-non-defaulted-rpitit.rs:6:17
3+
|
4+
LL | fn bar() -> Wrapper<impl Sized>;
5+
| ^^^^^^^^^^^^^^^^^^^ `impl Sized` cannot be sent between threads safely
6+
|
7+
= help: the trait `Send` is not implemented for `impl Sized`
8+
note: required by a bound in `Wrapper`
9+
--> $DIR/check-wf-on-non-defaulted-rpitit.rs:3:19
10+
|
11+
LL | struct Wrapper<G: Send>(G);
12+
| ^^^^ required by this bound in `Wrapper`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)