Auto merge of #86866 - nikomatsakis:issue-84841, r=oli-obk

Hack: Ignore inference variables in certain queries

Fixes #84841
Fixes #86753

Some queries are not built to accept types with inference variables, which can lead to ICEs. These queries probably ought to be converted to canonical form, but as a quick workaround, we can return conservative results in the case that inference variables are found.

We should file a follow-up issue (and update the FIXMEs...) to do the proper refactoring.

cc `@arora-aman`

r? `@oli-obk`
This commit is contained in:
bors 2021-07-04 17:39:37 +00:00
commit 23c652dfe3
13 changed files with 168 additions and 58 deletions

View file

@ -0,0 +1,16 @@
// edition:2018
fn main() {
}
async fn foo() {
// Adding an .await here avoids the ICE
test()?;
//~^ ERROR the `?` operator can only be applied to values that implement `Try`
//~| ERROR the `?` operator can only be used in an async function that returns
}
// Removing the const generic parameter here avoids the ICE
async fn test<const N: usize>() {
}

View file

@ -0,0 +1,28 @@
error[E0277]: the `?` operator can only be applied to values that implement `Try`
--> $DIR/issue-84841.rs:9:5
|
LL | test()?;
| ^^^^^^^ the `?` operator cannot be applied to type `impl Future`
|
= help: the trait `Try` is not implemented for `impl Future`
= note: required by `branch`
error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> $DIR/issue-84841.rs:9:11
|
LL | async fn foo() {
| ________________-
LL | | // Adding an .await here avoids the ICE
LL | | test()?;
| | ^ cannot use the `?` operator in an async function that returns `()`
LL | |
LL | |
LL | | }
| |_- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
= note: required by `from_residual`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,34 @@
// edition:2018
// check-pass
#![warn(rust_2021_compatibility)]
use std::future::Future;
struct Runtime;
impl Runtime {
pub fn block_on<F: Future>(&self, _future: F) -> F::Output {
unimplemented!()
}
}
pub fn http<F, Fut>(_func: F)
where
F: Fn() -> Fut,
Fut: Future<Output = ()>,
{
let rt = Runtime {};
let srv = rt.block_on(async move { serve(move || async move { unimplemented!() }) });
let _ = || rt.block_on(async { srv });
}
pub struct Server<S> {
_marker: std::marker::PhantomData<S>,
}
pub fn serve<S>(_new_service: S) -> Server<S> {
unimplemented!()
}
fn main() { }