Skip to content

Commit 7634c59

Browse files
Don't project to RPITIT that has no default value
1 parent 276b75a commit 7634c59

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
344344
in_trait,
345345
..
346346
}) => {
347-
if in_trait {
348-
assert!(tcx.impl_defaultness(owner).has_value());
347+
if in_trait && !tcx.impl_defaultness(owner).has_value() {
348+
span_bug!(tcx.def_span(def_id), "tried to get type of this RPITIT with no definition");
349349
}
350350
find_opaque_ty_constraints_for_rpit(tcx, def_id, owner)
351351
}

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,8 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22002200
Err(guar) => return Progress::error(tcx, guar),
22012201
};
22022202
// We don't support specialization for RPITITs anyways... yet.
2203-
if !leaf_def.is_final() {
2203+
// Also don't try to project to an RPITIT that has no value
2204+
if !leaf_def.is_final() || !leaf_def.item.defaultness(tcx).has_value() {
22042205
return Progress { term: tcx.ty_error_misc().into(), obligations };
22052206
}
22062207

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(return_position_impl_trait_in_trait)]
2+
//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete
3+
4+
trait MyTrait {
5+
fn foo(&self) -> impl Sized;
6+
fn bar(&self) -> impl Sized;
7+
}
8+
9+
impl MyTrait for i32 {
10+
//~^ ERROR not all trait items implemented, missing: `foo`
11+
fn bar(&self) -> impl Sized {
12+
self.foo()
13+
}
14+
}
15+
16+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/dont-project-to-rpitit-with-no-value.rs:1:12
3+
|
4+
LL | #![feature(return_position_impl_trait_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0046]: not all trait items implemented, missing: `foo`
11+
--> $DIR/dont-project-to-rpitit-with-no-value.rs:9:1
12+
|
13+
LL | fn foo(&self) -> impl Sized;
14+
| ---------------------------- `foo` from trait
15+
...
16+
LL | impl MyTrait for i32 {
17+
| ^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
18+
19+
error: aborting due to previous error; 1 warning emitted
20+
21+
For more information about this error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)