Skip to content

Commit 8a68fc6

Browse files
authored
Rollup merge of #72775 - JohnTitor:await-sugg, r=estebank
Return early to avoid ICE Fixes #72766
2 parents ad4bc33 + 7750357 commit 8a68fc6

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19091909

19101910
let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty());
19111911

1912+
// Do not check on infer_types to avoid panic in evaluate_obligation.
1913+
if self_ty.has_infer_types() {
1914+
return;
1915+
}
1916+
let self_ty = self.tcx.erase_regions(&self_ty);
1917+
19121918
let impls_future = self.tcx.type_implements_trait((
19131919
future_trait,
19141920
self_ty,

src/librustc_trait_selection/traits/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,6 @@ fn type_implements_trait<'tcx>(
540540
trait_def_id, ty, params, param_env
541541
);
542542

543-
// Do not check on infer_types to avoid panic in evaluate_obligation.
544-
if ty.has_infer_types() {
545-
return false;
546-
}
547-
548-
let ty = tcx.erase_regions(&ty);
549-
550543
let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, params) };
551544

552545
let obligation = Obligation {
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition:2018
2+
// compile-flags: -Cincremental=tmp/issue-72766
3+
4+
pub struct SadGirl;
5+
6+
impl SadGirl {
7+
pub async fn call(&self) -> Result<(), ()> {
8+
Ok(())
9+
}
10+
}
11+
12+
async fn async_main() -> Result<(), ()> {
13+
// should be `.call().await?`
14+
SadGirl {}.call()?; //~ ERROR: the `?` operator can only be applied to values
15+
Ok(())
16+
}
17+
18+
fn main() {
19+
let _ = async_main();
20+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
2+
--> $DIR/issue-72766.rs:14:5
3+
|
4+
LL | SadGirl {}.call()?;
5+
| ^^^^^^^^^^^^^^^^^^
6+
| |
7+
| the `?` operator cannot be applied to type `impl std::future::Future`
8+
| help: consider using `.await` here: `SadGirl {}.call().await?`
9+
|
10+
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
11+
= note: required by `std::ops::Try::into_result`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

src/tools/clippy/clippy_lints/src/utils/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ pub fn implements_trait<'a, 'tcx>(
323323
trait_id: DefId,
324324
ty_params: &[GenericArg<'tcx>],
325325
) -> bool {
326+
// Do not check on infer_types to avoid panic in evaluate_obligation.
327+
if ty.has_infer_types() {
328+
return false;
329+
}
330+
let ty = cx.tcx.erase_regions(&ty);
326331
let ty_params = cx.tcx.mk_substs(ty_params.iter());
327332
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
328333
}

0 commit comments

Comments
 (0)