diff options
| author | Arpad Borsos <swatinem@swatinem.de> | 2022-11-30 19:34:19 +0100 |
|---|---|---|
| committer | Arpad Borsos <swatinem@swatinem.de> | 2022-11-30 19:53:59 +0100 |
| commit | b5ae4c9629f697034fb93f660202f354f13b74c3 (patch) | |
| tree | 069443398839868ea0cebdb13618e501257edd95 /compiler/rustc_trait_selection/src/traits | |
| parent | 8de4b138455add55bde6de5553a933a2ab79b71f (diff) | |
| download | rust-b5ae4c9629f697034fb93f660202f354f13b74c3.tar.gz rust-b5ae4c9629f697034fb93f660202f354f13b74c3.zip | |
Make sure async constructs do not `impl Generator`
Async lowering turns async functions and blocks into generators internally. Though these special kinds of generators should not `impl Generator` themselves. The other way around, normal generators should not `impl Future`.
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index fe5135661b5..e4b70f0d2ff 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -203,7 +203,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // type/region parameters. let self_ty = obligation.self_ty().skip_binder(); match self_ty.kind() { - ty::Generator(..) => { + // async constructs get lowered to a special kind of generator that + // should *not* `impl Generator`. + ty::Generator(did, ..) if !self.tcx().generator_is_async(*did) => { debug!(?self_ty, ?obligation, "assemble_generator_candidates",); candidates.vec.push(GeneratorCandidate); @@ -223,6 +225,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) { let self_ty = obligation.self_ty().skip_binder(); if let ty::Generator(did, ..) = self_ty.kind() { + // async constructs get lowered to a special kind of generator that + // should directly `impl Future`. if self.tcx().generator_is_async(*did) { debug!(?self_ty, ?obligation, "assemble_future_candidates",); |
