Skip to content

Commit 1f3e1cf

Browse files
committed
Strip placeholders from hidden types before remapping generic parameter in the hidden type to the generic parameters of the definition of the opaque
1 parent 8579a18 commit 1f3e1cf

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
136136
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
137137
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)
138138
.unwrap_or(infcx.tcx.lifetimes.re_erased),
139+
ty::RePlaceholder(_) => ty::Region::new_error_with_message(
140+
infcx.tcx,
141+
concrete_type.span,
142+
"hidden type contains placeholders, we don't support higher kinded opaques yet",
143+
),
139144
_ => region,
140145
});
141146
debug!(?universal_concrete_type);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! This test used to ICE because, while an error was emitted,
2+
//! we still tried to remap generic params used in the hidden type
3+
//! to the ones of the opaque type definition.
4+
5+
//@ edition: 2021
6+
7+
#![feature(type_alias_impl_trait)]
8+
use std::future::Future;
9+
10+
type FutNothing<'a> = impl 'a + Future<Output = ()>;
11+
//~^ ERROR: unconstrained opaque type
12+
13+
async fn operation(_: &mut ()) -> () {
14+
//~^ ERROR: concrete type differs from previous
15+
call(operation).await
16+
//~^ ERROR: concrete type differs from previous
17+
}
18+
19+
async fn call<F>(_f: F)
20+
where
21+
for<'any> F: FnMut(&'any mut ()) -> FutNothing<'any>,
22+
{
23+
//~^ ERROR: expected generic lifetime parameter, found `'any`
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error: unconstrained opaque type
2+
--> $DIR/hkl_forbidden4.rs:10:23
3+
|
4+
LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `FutNothing` must be used in combination with a concrete type within the same module
8+
9+
error: concrete type differs from previous defining opaque type use
10+
--> $DIR/hkl_forbidden4.rs:13:1
11+
|
12+
LL | async fn operation(_: &mut ()) -> () {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 17:2}`
14+
|
15+
note: previous use here
16+
--> $DIR/hkl_forbidden4.rs:15:5
17+
|
18+
LL | call(operation).await
19+
| ^^^^^^^^^^^^^^^
20+
21+
error: concrete type differs from previous defining opaque type use
22+
--> $DIR/hkl_forbidden4.rs:15:5
23+
|
24+
LL | call(operation).await
25+
| ^^^^^^^^^^^^^^^ expected `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 17:2}`, got `FutNothing<'_>`
26+
|
27+
note: previous use here
28+
--> $DIR/hkl_forbidden4.rs:13:38
29+
|
30+
LL | async fn operation(_: &mut ()) -> () {
31+
| ______________________________________^
32+
LL | |
33+
LL | | call(operation).await
34+
LL | |
35+
LL | | }
36+
| |_^
37+
38+
error[E0792]: expected generic lifetime parameter, found `'any`
39+
--> $DIR/hkl_forbidden4.rs:22:1
40+
|
41+
LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
42+
| -- this generic parameter must be used with a generic lifetime parameter
43+
...
44+
LL | / {
45+
LL | |
46+
LL | | }
47+
| |_^
48+
49+
error: aborting due to 4 previous errors
50+
51+
For more information about this error, try `rustc --explain E0792`.

0 commit comments

Comments
 (0)