Skip to content

Commit

Permalink
Don't register predicates for RPITIT items in built-in trait object i…
Browse files Browse the repository at this point in the history
…mpl confirmation
  • Loading branch information
compiler-errors committed Nov 19, 2024
1 parent 30ac7b9 commit e7fdb2e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 16 deletions.
14 changes: 12 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() && !tcx.features().generic_associated_types_extended() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
let ty::PseudoCanonicalInput { typing_env, value: (sig, extra_args) } = query;

let cx = LayoutCx::new(tcx, param_env);
let cx = LayoutCx::new(tcx, typing_env);
fn_abi_new_uncached(
&cx,
tcx.instantiate_bound_regions_with_erased(sig),
Expand Down
13 changes: 0 additions & 13 deletions tests/crashes/131538.rs

This file was deleted.

30 changes: 30 additions & 0 deletions tests/ui/async-await/dyn/gat-extended-bad-afit.no.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-extended-bad-afit.rs:14:14
|
LL | trait HealthCheck {
| ----------- this trait cannot be made into an object...
LL | async fn check<const N: usize>(&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`.
24 changes: 24 additions & 0 deletions tests/ui/async-await/dyn/gat-extended-bad-afit.rs
Original file line number Diff line number Diff line change
@@ -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<const N: usize>(&self);
}

fn do_health_check_par()
where
dyn HealthCheck: HealthCheck,
//~^ ERROR the trait `HealthCheck` cannot be made into an object
{
}

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/async-await/dyn/gat-extended-bad-afit.yes.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-extended-bad-afit.rs:14:14
|
LL | trait HealthCheck {
| ----------- this trait cannot be made into an object...
LL | async fn check<const N: usize>(&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`.

0 comments on commit e7fdb2e

Please sign in to comment.