Skip to content

Commit 489afcc

Browse files
committed
unify closures and generator handling in wf
1 parent 7a3d477 commit 489afcc

File tree

5 files changed

+14
-39
lines changed

5 files changed

+14
-39
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -681,23 +681,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
681681

682682
ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => {
683683
// Unspecified in RFC 1214.
684-
// They are always WF when the gnereator passes typeck/borrowck.
685-
walker.skip_current_subtree();
686684
}
687685

688-
ty::Generator(did, args, ..) => {
689-
// Walk ALL the types in the generator: this will
690-
// include the upvar types as well as the yield
691-
// type. Note that this is mildly distinct from
692-
// the closure case, where we have to be careful
693-
// about the signature of the closure. We don't
694-
// have the problem of implied bounds here since
695-
// generators don't take arguments.
696-
let obligations = self.nominal_obligations(did, args);
697-
self.out.extend(obligations);
698-
}
699-
700-
ty::Closure(did, args) => {
686+
ty::Closure(did, args) | ty::Generator(did, args, ..) => {
701687
// Only check the upvar types for WF, not the rest
702688
// of the types within. This is needed because we
703689
// capture the signature and it may not be WF
@@ -719,8 +705,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
719705
// shorthand for something like `where(T: 'a) {
720706
// fn(&'a T) }`, as discussed in #25860.
721707
walker.skip_current_subtree(); // subtree handled below
708+
709+
let upvars = match ty.kind() {
710+
ty::Closure(..) => args.as_closure().tupled_upvars_ty(),
711+
ty::Generator(..) => args.as_generator().tupled_upvars_ty(),
712+
_ => unreachable!(),
713+
};
722714
// FIXME(eddyb) add the type to `walker` instead of recursing.
723-
self.compute(args.as_closure().tupled_upvars_ty().into());
715+
self.compute(upvars.into());
716+
724717
// Note that we cannot skip the generic types
725718
// types. Normally, within the fn
726719
// body where they are created, the generics will

tests/ui/async-await/generator-wf-check.output_wf.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/async-await/generator-wf-check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// edition: 2021
55
// revisions: output output_wf witness witness_wf
66
//[output] check-pass
7-
//[output_wf] check-fail
7+
//[output_wf] check-pass
88
//[witness] check-fail
99
//[witness_wf] check-fail
1010

@@ -22,7 +22,6 @@ fn test_output<T>() {
2222
#[cfg(output_wf)]
2323
fn test_output_wf<T>() {
2424
wf(async {
25-
//[output_wf]~^ ERROR `T` may not live long enough
2625
None::<Static<T>>
2726
});
2827
}

tests/ui/async-await/generator-wf-check.witness.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0310]: the parameter type `T` may not live long enough
2-
--> $DIR/generator-wf-check.rs:33:22
2+
--> $DIR/generator-wf-check.rs:32:22
33
|
44
LL | let witness: Option<Static<T>> = None;
55
| ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
@@ -10,7 +10,7 @@ LL | fn test_witness<T: 'static>() {
1010
| +++++++++
1111

1212
error[E0310]: the parameter type `T` may not live long enough
13-
--> $DIR/generator-wf-check.rs:36:9
13+
--> $DIR/generator-wf-check.rs:35:9
1414
|
1515
LL | drop(witness);
1616
| ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

tests/ui/async-await/generator-wf-check.witness_wf.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0310]: the parameter type `T` may not live long enough
2-
--> $DIR/generator-wf-check.rs:44:22
2+
--> $DIR/generator-wf-check.rs:43:22
33
|
44
LL | let witness: Option<Static<T>> = None;
55
| ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
@@ -10,7 +10,7 @@ LL | fn test_witness_wf<T: 'static>() {
1010
| +++++++++
1111

1212
error[E0310]: the parameter type `T` may not live long enough
13-
--> $DIR/generator-wf-check.rs:47:9
13+
--> $DIR/generator-wf-check.rs:46:9
1414
|
1515
LL | drop(witness);
1616
| ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

0 commit comments

Comments
 (0)