Skip to content

Commit 0228c07

Browse files
canndrewcrlf0710
authored andcommitted
add generator_clone feature gate
1 parent 2c0bc94 commit 0228c07

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ declare_features! (
396396
(active, fn_align, "1.53.0", Some(82232), None),
397397
/// Allows defining generators.
398398
(active, generators, "1.21.0", Some(43122), None),
399+
/// Allows generators to be cloned.
400+
(active, generator_clone, "1.60.0", None, None),
399401
/// Infer generic args for both consts and types.
400402
(active, generic_arg_infer, "1.55.0", Some(85077), None),
401403
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ symbols! {
763763
gen_future,
764764
gen_kill,
765765
generator,
766+
generator_clone,
766767
generator_state,
767768
generators,
768769
generic_arg_infer,

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,35 +1938,43 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19381938
}
19391939

19401940
ty::Generator(_, substs, hir::Movability::Movable) => {
1941-
let resolved_upvars = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
1942-
let resolved_witness = self.infcx.shallow_resolve(substs.as_generator().witness());
1943-
if {
1944-
matches!(resolved_upvars.kind(), ty::Infer(ty::TyVar(_))) ||
1945-
matches!(resolved_witness.kind(), ty::Infer(ty::TyVar(_)))
1946-
} {
1947-
// Not yet resolved.
1948-
Ambiguous
1941+
if self.tcx().features().generator_clone {
1942+
let resolved_upvars = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
1943+
let resolved_witness = self.infcx.shallow_resolve(substs.as_generator().witness());
1944+
if {
1945+
matches!(resolved_upvars.kind(), ty::Infer(ty::TyVar(_))) ||
1946+
matches!(resolved_witness.kind(), ty::Infer(ty::TyVar(_)))
1947+
} {
1948+
// Not yet resolved.
1949+
Ambiguous
1950+
} else {
1951+
let mut all = substs.as_generator().upvar_tys().collect::<Vec<_>>();
1952+
all.push(substs.as_generator().witness());
1953+
Where(obligation.predicate.rebind(all))
1954+
}
19491955
} else {
1950-
let mut all = substs.as_generator().upvar_tys().collect::<Vec<_>>();
1951-
all.push(substs.as_generator().witness());
1952-
Where(obligation.predicate.rebind(all))
1956+
None
19531957
}
19541958
}
19551959

19561960
ty::GeneratorWitness(binder) => {
1957-
let tys = binder.no_bound_vars().unwrap();
1958-
let mut iter = tys.iter();
1959-
loop {
1960-
let ty = match iter.next() {
1961-
Some(ty) => ty,
1962-
Option::None => {
1963-
break Where(obligation.predicate.rebind(tys.to_vec()))
1964-
},
1965-
};
1966-
let resolved = self.infcx.shallow_resolve(ty);
1967-
if matches!(resolved.kind(), ty::Infer(ty::TyVar(_))) {
1968-
break Ambiguous;
1969-
}
1961+
match binder.no_bound_vars() {
1962+
Some(tys) => {
1963+
let mut iter = tys.iter();
1964+
loop {
1965+
let ty = match iter.next() {
1966+
Some(ty) => ty,
1967+
Option::None => {
1968+
break Where(obligation.predicate.rebind(tys.to_vec()))
1969+
},
1970+
};
1971+
let resolved = self.infcx.shallow_resolve(ty);
1972+
if matches!(resolved.kind(), ty::Infer(ty::TyVar(_))) {
1973+
break Ambiguous;
1974+
}
1975+
}
1976+
},
1977+
Option::None => None,
19701978
}
19711979
}
19721980

0 commit comments

Comments
 (0)