diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-06-02 13:07:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-02 13:07:12 +0900 |
| commit | 8a68fc6ff4f55a7a775a4339de4ca845a68ab43a (patch) | |
| tree | 1fc2b8016546771976168d08691ff2669e1de564 | |
| parent | ad4bc3323b9299d867697e9653dcea1b5e1ad283 (diff) | |
| parent | 77503578e1e727228ce47dd7847302936cf80a23 (diff) | |
| download | rust-8a68fc6ff4f55a7a775a4339de4ca845a68ab43a.tar.gz rust-8a68fc6ff4f55a7a775a4339de4ca845a68ab43a.zip | |
Rollup merge of #72775 - JohnTitor:await-sugg, r=estebank
Return early to avoid ICE Fixes #72766
| -rw-r--r-- | src/librustc_trait_selection/traits/error_reporting/suggestions.rs | 6 | ||||
| -rw-r--r-- | src/librustc_trait_selection/traits/mod.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-72766.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-72766.stderr | 15 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/utils/mod.rs | 5 |
5 files changed, 46 insertions, 7 deletions
diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index cfbea9ee0f1..e3846d8d73d 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -1909,6 +1909,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty()); + // Do not check on infer_types to avoid panic in evaluate_obligation. + if self_ty.has_infer_types() { + return; + } + let self_ty = self.tcx.erase_regions(&self_ty); + let impls_future = self.tcx.type_implements_trait(( future_trait, self_ty, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index b45de72ab02..958ba69a826 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -540,13 +540,6 @@ fn type_implements_trait<'tcx>( trait_def_id, ty, params, param_env ); - // Do not check on infer_types to avoid panic in evaluate_obligation. - if ty.has_infer_types() { - return false; - } - - let ty = tcx.erase_regions(&ty); - let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, params) }; let obligation = Obligation { diff --git a/src/test/ui/suggestions/issue-72766.rs b/src/test/ui/suggestions/issue-72766.rs new file mode 100644 index 00000000000..0448f071958 --- /dev/null +++ b/src/test/ui/suggestions/issue-72766.rs @@ -0,0 +1,20 @@ +// edition:2018 +// compile-flags: -Cincremental=tmp/issue-72766 + +pub struct SadGirl; + +impl SadGirl { + pub async fn call(&self) -> Result<(), ()> { + Ok(()) + } +} + +async fn async_main() -> Result<(), ()> { + // should be `.call().await?` + SadGirl {}.call()?; //~ ERROR: the `?` operator can only be applied to values + Ok(()) +} + +fn main() { + let _ = async_main(); +} diff --git a/src/test/ui/suggestions/issue-72766.stderr b/src/test/ui/suggestions/issue-72766.stderr new file mode 100644 index 00000000000..4290f3b4bf1 --- /dev/null +++ b/src/test/ui/suggestions/issue-72766.stderr @@ -0,0 +1,15 @@ +error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` + --> $DIR/issue-72766.rs:14:5 + | +LL | SadGirl {}.call()?; + | ^^^^^^^^^^^^^^^^^^ + | | + | the `?` operator cannot be applied to type `impl std::future::Future` + | help: consider using `.await` here: `SadGirl {}.call().await?` + | + = help: the trait `std::ops::Try` is not implemented for `impl std::future::Future` + = note: required by `std::ops::Try::into_result` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 6c1488664bf..6dd8fef7e82 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -323,6 +323,11 @@ pub fn implements_trait<'a, 'tcx>( trait_id: DefId, ty_params: &[GenericArg<'tcx>], ) -> bool { + // Do not check on infer_types to avoid panic in evaluate_obligation. + if ty.has_infer_types() { + return false; + } + let ty = cx.tcx.erase_regions(&ty); let ty_params = cx.tcx.mk_substs(ty_params.iter()); cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) } |
