about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
diff options
context:
space:
mode:
authorAndrew Cann <shum@canndrew.org>2022-03-13 14:41:44 +0800
committerCharles Lew <crlf0710@gmail.com>2022-09-11 14:04:12 +0800
commit0228c073e07bc36ab4dbb88ab7f3cbdf00832d59 (patch)
tree9237ad3cedb36706c204737ee902a2748a3a50d4 /compiler/rustc_trait_selection/src/traits
parent2c0bc9444eea8677a307c2440b2f206911d5bbbe (diff)
downloadrust-0228c073e07bc36ab4dbb88ab7f3cbdf00832d59.tar.gz
rust-0228c073e07bc36ab4dbb88ab7f3cbdf00832d59.zip
add generator_clone feature gate
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs56
1 files changed, 32 insertions, 24 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 592c6c8e055..0e7483847e3 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -1938,35 +1938,43 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             }
 
             ty::Generator(_, substs, hir::Movability::Movable) => {
-                let resolved_upvars = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
-                let resolved_witness = self.infcx.shallow_resolve(substs.as_generator().witness());
-                if {
-                    matches!(resolved_upvars.kind(), ty::Infer(ty::TyVar(_))) ||
-                    matches!(resolved_witness.kind(), ty::Infer(ty::TyVar(_)))
-                } {
-                    // Not yet resolved.
-                    Ambiguous
+                if self.tcx().features().generator_clone {
+                    let resolved_upvars = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
+                    let resolved_witness = self.infcx.shallow_resolve(substs.as_generator().witness());
+                    if {
+                        matches!(resolved_upvars.kind(), ty::Infer(ty::TyVar(_))) ||
+                        matches!(resolved_witness.kind(), ty::Infer(ty::TyVar(_)))
+                    } {
+                        // Not yet resolved.
+                        Ambiguous
+                    } else {
+                        let mut all = substs.as_generator().upvar_tys().collect::<Vec<_>>();
+                        all.push(substs.as_generator().witness());
+                        Where(obligation.predicate.rebind(all))
+                    }
                 } else {
-                    let mut all = substs.as_generator().upvar_tys().collect::<Vec<_>>();
-                    all.push(substs.as_generator().witness());
-                    Where(obligation.predicate.rebind(all))
+                    None
                 }
             }
 
             ty::GeneratorWitness(binder) => {
-                let tys = binder.no_bound_vars().unwrap();
-                let mut iter = tys.iter();
-                loop {
-                    let ty = match iter.next() {
-                        Some(ty) => ty,
-                        Option::None => {
-                            break Where(obligation.predicate.rebind(tys.to_vec()))
-                        },
-                    };
-                    let resolved = self.infcx.shallow_resolve(ty);
-                    if matches!(resolved.kind(), ty::Infer(ty::TyVar(_))) {
-                        break Ambiguous;
-                    }
+                match binder.no_bound_vars() {
+                    Some(tys) => {
+                        let mut iter = tys.iter();
+                        loop {
+                            let ty = match iter.next() {
+                                Some(ty) => ty,
+                                Option::None => {
+                                    break Where(obligation.predicate.rebind(tys.to_vec()))
+                                },
+                            };
+                            let resolved = self.infcx.shallow_resolve(ty);
+                            if matches!(resolved.kind(), ty::Infer(ty::TyVar(_))) {
+                                break Ambiguous;
+                            }
+                        }
+                    },
+                    Option::None => None,
                 }
             }