Skip to content

Commit 40c972e

Browse files
authored
Rollup merge of #122733 - oli-obk:error_prop, r=compiler-errors
Strip placeholders from hidden types before remapping generic parameter When remapping generic parameters in the hidden type to the generic parameters of the definition of the opaque, we assume that placeholders cannot exist. Instead of just patching that site, I decided to handle it earlier, directly in `infer_opaque_types`, where we are already doing all the careful lifetime handling. fixes #122694 the reason that ICE now occurred was that we stopped treating `operation` as being in the defining scope, so the TAIT became part of the hidden type of the `async fn`'s opaque type instead of just bailing out as ambiguos I think ```rust use std::future::Future; mod foo { 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 ()) -> foo::FutNothing<'any>, { //~^ ERROR: expected generic lifetime parameter, found `'any` } ``` would have already had the same ICE before #121796
2 parents 8d12621 + 6623bdf commit 40c972e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
192192
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
193193
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)
194194
.unwrap_or(infcx.tcx.lifetimes.re_erased),
195+
ty::RePlaceholder(_) => ty::Region::new_error_with_message(
196+
infcx.tcx,
197+
concrete_type.span,
198+
"hidden type contains placeholders, we don't support higher kinded opaques yet",
199+
),
195200
_ => region,
196201
});
197202
debug!(?universal_concrete_type);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
17+
18+
async fn call<F>(_f: F)
19+
where
20+
for<'any> F: FnMut(&'any mut ()) -> FutNothing<'any>,
21+
{
22+
//~^ ERROR: expected generic lifetime parameter, found `'any`
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: 16:2}`
14+
|
15+
note: previous use here
16+
--> $DIR/hkl_forbidden4.rs:15:5
17+
|
18+
LL | call(operation).await
19+
| ^^^^^^^^^^^^^^^
20+
21+
error[E0792]: expected generic lifetime parameter, found `'any`
22+
--> $DIR/hkl_forbidden4.rs:21:1
23+
|
24+
LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
25+
| -- this generic parameter must be used with a generic lifetime parameter
26+
...
27+
LL | / {
28+
LL | |
29+
LL | | }
30+
| |_^
31+
32+
error: aborting due to 3 previous errors
33+
34+
For more information about this error, try `rustc --explain E0792`.

0 commit comments

Comments
 (0)