forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#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 rust-lang#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 rust-lang#121796
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |