Skip to content

Commit 591f99f

Browse files
Don't register predicates for RPITIT items in built-in trait object impl confirmation
1 parent de738f6 commit 591f99f

File tree

5 files changed

+101
-15
lines changed

5 files changed

+101
-15
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
629629

630630
// When `async_fn_in_dyn_trait` is enabled, we don't need to check the
631631
// RPITIT for compatibility, since it's not provided by the user.
632-
if tcx.features().async_fn_in_dyn_trait() && tcx.is_impl_trait_in_trait(assoc_type) {
633-
continue;
632+
if tcx.is_impl_trait_in_trait(assoc_type) {
633+
if tcx.features().async_fn_in_dyn_trait() {
634+
continue;
635+
} else {
636+
tcx.dcx().span_delayed_bug(
637+
obligation.cause.span,
638+
"RPITIT in trait object shouldn't have been considered",
639+
);
640+
return Err(SelectionError::TraitDynIncompatible(
641+
trait_predicate.trait_ref.def_id,
642+
));
643+
}
634644
}
635645

636646
if !defs.own_params.is_empty() && !tcx.features().generic_associated_types_extended() {

tests/crashes/131538.rs

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
warning: the feature `generic_associated_types_extended` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/gat-extended-bad-afit.rs:9:12
3+
|
4+
LL | #![feature(generic_associated_types_extended)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #95451 <https://github.com/rust-lang/rust/issues/95451> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0038]: the trait `HealthCheck` cannot be made into an object
11+
--> $DIR/gat-extended-bad-afit.rs:19:22
12+
|
13+
LL | dyn HealthCheck: HealthCheck,
14+
| ^^^^^^^^^^^ `HealthCheck` cannot be made into an object
15+
|
16+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
17+
--> $DIR/gat-extended-bad-afit.rs:14:14
18+
|
19+
LL | trait HealthCheck {
20+
| ----------- this trait cannot be made into an object...
21+
LL | async fn check<const N: usize>(&self);
22+
| ^^^^^
23+
| |
24+
| ...because method `check` is `async`
25+
| ...because method `check` has generic type parameters
26+
= help: consider moving `check` to another trait
27+
28+
error: aborting due to 1 previous error; 1 warning emitted
29+
30+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ edition: 2021
2+
//@ revisions: yes no
3+
4+
// Ice regression test for #131538
5+
// Make sure that we don't crash when the GATE feature gate is enabled.
6+
7+
#![cfg_attr(yes, feature(async_fn_in_dyn_trait))]
8+
//[yes]~^ WARN the feature `async_fn_in_dyn_trait` is incomplete
9+
#![feature(generic_associated_types_extended)]
10+
//~^ WARN the feature `generic_associated_types_extended` is incomplete
11+
#![feature(trivial_bounds)]
12+
13+
trait HealthCheck {
14+
async fn check<const N: usize>(&self);
15+
}
16+
17+
fn do_health_check_par()
18+
where
19+
dyn HealthCheck: HealthCheck,
20+
//~^ ERROR the trait `HealthCheck` cannot be made into an object
21+
{
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
warning: the feature `async_fn_in_dyn_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/gat-extended-bad-afit.rs:7:26
3+
|
4+
LL | #![cfg_attr(yes, feature(async_fn_in_dyn_trait))]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #133119 <https://github.com/rust-lang/rust/issues/133119> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: the feature `generic_associated_types_extended` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/gat-extended-bad-afit.rs:9:12
12+
|
13+
LL | #![feature(generic_associated_types_extended)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #95451 <https://github.com/rust-lang/rust/issues/95451> for more information
17+
18+
error[E0038]: the trait `HealthCheck` cannot be made into an object
19+
--> $DIR/gat-extended-bad-afit.rs:19:22
20+
|
21+
LL | dyn HealthCheck: HealthCheck,
22+
| ^^^^^^^^^^^ `HealthCheck` cannot be made into an object
23+
|
24+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
25+
--> $DIR/gat-extended-bad-afit.rs:14:14
26+
|
27+
LL | trait HealthCheck {
28+
| ----------- this trait cannot be made into an object...
29+
LL | async fn check<const N: usize>(&self);
30+
| ^^^^^ ...because method `check` has generic type parameters
31+
= help: consider moving `check` to another trait
32+
33+
error: aborting due to 1 previous error; 2 warnings emitted
34+
35+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)