Skip to content

Commit

Permalink
Strip placeholders from hidden types before remapping generic paramet…
Browse files Browse the repository at this point in the history
…er in the hidden type to the generic parameters of the definition of the opaque
  • Loading branch information
oli-obk committed Mar 19, 2024
1 parent 8579a18 commit 1f3e1cf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)
.unwrap_or(infcx.tcx.lifetimes.re_erased),
ty::RePlaceholder(_) => ty::Region::new_error_with_message(
infcx.tcx,
concrete_type.span,
"hidden type contains placeholders, we don't support higher kinded opaques yet",
),
_ => region,
});
debug!(?universal_concrete_type);
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/type-alias-impl-trait/hkl_forbidden4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! This test used to ICE because, while an error was emitted,
//! we still tried to remap generic params used in the hidden type
//! to the ones of the opaque type definition.

//@ edition: 2021

#![feature(type_alias_impl_trait)]
use std::future::Future;

type FutNothing<'a> = impl 'a + Future<Output = ()>;
//~^ ERROR: unconstrained opaque type

async fn operation(_: &mut ()) -> () {
//~^ ERROR: concrete type differs from previous
call(operation).await
//~^ ERROR: concrete type differs from previous
}

async fn call<F>(_f: F)
where
for<'any> F: FnMut(&'any mut ()) -> FutNothing<'any>,
{
//~^ ERROR: expected generic lifetime parameter, found `'any`
}

fn main() {}
51 changes: 51 additions & 0 deletions tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error: unconstrained opaque type
--> $DIR/hkl_forbidden4.rs:10:23
|
LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `FutNothing` must be used in combination with a concrete type within the same module

error: concrete type differs from previous defining opaque type use
--> $DIR/hkl_forbidden4.rs:13:1
|
LL | async fn operation(_: &mut ()) -> () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 17:2}`
|
note: previous use here
--> $DIR/hkl_forbidden4.rs:15:5
|
LL | call(operation).await
| ^^^^^^^^^^^^^^^

error: concrete type differs from previous defining opaque type use
--> $DIR/hkl_forbidden4.rs:15:5
|
LL | call(operation).await
| ^^^^^^^^^^^^^^^ expected `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 17:2}`, got `FutNothing<'_>`
|
note: previous use here
--> $DIR/hkl_forbidden4.rs:13:38
|
LL | async fn operation(_: &mut ()) -> () {
| ______________________________________^
LL | |
LL | | call(operation).await
LL | |
LL | | }
| |_^

error[E0792]: expected generic lifetime parameter, found `'any`
--> $DIR/hkl_forbidden4.rs:22:1
|
LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
| -- this generic parameter must be used with a generic lifetime parameter
...
LL | / {
LL | |
LL | | }
| |_^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0792`.

0 comments on commit 1f3e1cf

Please sign in to comment.