diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index cf76c888806b9..d458a847415aa 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -629,8 +629,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // When `async_fn_in_dyn_trait` is enabled, we don't need to check the // RPITIT for compatibility, since it's not provided by the user. - if tcx.features().async_fn_in_dyn_trait() && tcx.is_impl_trait_in_trait(assoc_type) { - continue; + if tcx.is_impl_trait_in_trait(assoc_type) { + if tcx.features().async_fn_in_dyn_trait() { + continue; + } else { + tcx.dcx().span_delayed_bug( + obligation.cause.span, + "RPITIT in trait object shouldn't have been considered", + ); + return Err(SelectionError::TraitDynIncompatible( + trait_predicate.trait_ref.def_id, + )); + } } if !defs.own_params.is_empty() { diff --git a/tests/ui/async-await/dyn/gat-extended-bad-afit.no.stderr b/tests/ui/async-await/dyn/gat-extended-bad-afit.no.stderr new file mode 100644 index 0000000000000..036955d06771a --- /dev/null +++ b/tests/ui/async-await/dyn/gat-extended-bad-afit.no.stderr @@ -0,0 +1,30 @@ +warning: the feature `generic_associated_types_extended` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-extended-bad-afit.rs:9:12 + | +LL | #![feature(generic_associated_types_extended)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #95451 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0038]: the trait `HealthCheck` cannot be made into an object + --> $DIR/gat-extended-bad-afit.rs:19:22 + | +LL | dyn HealthCheck: HealthCheck, + | ^^^^^^^^^^^ `HealthCheck` cannot be made into an object + | +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 + --> $DIR/gat-extended-bad-afit.rs:14:14 + | +LL | trait HealthCheck { + | ----------- this trait cannot be made into an object... +LL | async fn check(&self); + | ^^^^^ + | | + | ...because method `check` is `async` + | ...because method `check` has generic type parameters + = help: consider moving `check` to another trait + +error: aborting due to 1 previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/async-await/dyn/gat-extended-bad-afit.rs b/tests/ui/async-await/dyn/gat-extended-bad-afit.rs new file mode 100644 index 0000000000000..05b14efc312eb --- /dev/null +++ b/tests/ui/async-await/dyn/gat-extended-bad-afit.rs @@ -0,0 +1,24 @@ +//@ edition: 2021 +//@ revisions: yes no + +// Ice regression test for #131538 +// Make sure that we don't crash when the GATE feature gate is enabled. + +#![cfg_attr(yes, feature(async_fn_in_dyn_trait))] +//[yes]~^ WARN the feature `async_fn_in_dyn_trait` is incomplete +#![feature(generic_associated_types_extended)] +//~^ WARN the feature `generic_associated_types_extended` is incomplete +#![feature(trivial_bounds)] + +trait HealthCheck { + async fn check(&self); +} + +fn do_health_check_par() +where + dyn HealthCheck: HealthCheck, + //~^ ERROR the trait `HealthCheck` cannot be made into an object +{ +} + +fn main() {} diff --git a/tests/ui/async-await/dyn/gat-extended-bad-afit.yes.stderr b/tests/ui/async-await/dyn/gat-extended-bad-afit.yes.stderr new file mode 100644 index 0000000000000..7c59b5ae84eca --- /dev/null +++ b/tests/ui/async-await/dyn/gat-extended-bad-afit.yes.stderr @@ -0,0 +1,35 @@ +warning: the feature `async_fn_in_dyn_trait` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-extended-bad-afit.rs:7:26 + | +LL | #![cfg_attr(yes, feature(async_fn_in_dyn_trait))] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #133119 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: the feature `generic_associated_types_extended` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-extended-bad-afit.rs:9:12 + | +LL | #![feature(generic_associated_types_extended)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #95451 for more information + +error[E0038]: the trait `HealthCheck` cannot be made into an object + --> $DIR/gat-extended-bad-afit.rs:19:22 + | +LL | dyn HealthCheck: HealthCheck, + | ^^^^^^^^^^^ `HealthCheck` cannot be made into an object + | +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 + --> $DIR/gat-extended-bad-afit.rs:14:14 + | +LL | trait HealthCheck { + | ----------- this trait cannot be made into an object... +LL | async fn check(&self); + | ^^^^^ ...because method `check` has generic type parameters + = help: consider moving `check` to another trait + +error: aborting due to 1 previous error; 2 warnings emitted + +For more information about this error, try `rustc --explain E0038`.