Skip to content

Commit b876232

Browse files
authored
Rollup merge of #108746 - compiler-errors:rpitit-dont-project-default-w-no-valu, r=cjgillot
Don't project to RPITIT that has no default value Replicates this behavior, but for RPITIT projection logic (which currently is separate) https://github.com/rust-lang/rust/blob/b1719530f44e3c8ec903f76020a52bd8764d5d10/compiler/rustc_trait_selection/src/traits/project.rs#L2105-L2115 Fixes #108738
2 parents ced9cd1 + 7634c59 commit b876232

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

+2-2
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

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

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() {}
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)