Skip to content

Commit 7d78764

Browse files
committed
revert previous two commits
1 parent d06f509 commit 7d78764

9 files changed

+32
-141
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+6-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_infer::infer::region_constraints::GenericKind;
77
use rustc_infer::infer::InferCtxt;
88
use rustc_middle::mir::ConstraintCategory;
99
use rustc_middle::traits::query::OutlivesBound;
10-
use rustc_middle::ty::{self, RegionVid, ToPredicate, Ty};
10+
use rustc_middle::ty::{self, RegionVid, Ty};
1111
use rustc_span::{Span, DUMMY_SP};
1212
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1313
use std::rc::Rc;
@@ -232,21 +232,14 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
232232
let mut normalized_inputs_and_output =
233233
Vec::with_capacity(self.universal_regions.unnormalized_input_tys.len() + 1);
234234
let mut constraints = vec![];
235-
for (i, ty) in unnormalized_input_output_tys.enumerate() {
235+
for ty in unnormalized_input_output_tys {
236236
debug!("build: input_or_output={:?}", ty);
237-
238-
let use_implied_bounds = i < self.universal_regions.unnormalized_input_tys.len()
239-
|| self.universal_regions.defining_ty.is_fn_def();
240-
241237
// We add implied bounds from both the unnormalized and normalized ty.
242238
// See issue #87748
243-
if use_implied_bounds {
244-
let constraints_unnorm = self.add_implied_bounds(ty);
245-
if let Some(c) = constraints_unnorm {
246-
constraints.push(c)
247-
}
239+
let constraints_unnorm = self.add_implied_bounds(ty);
240+
if let Some(c) = constraints_unnorm {
241+
constraints.push(c)
248242
}
249-
250243
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } = self
251244
.param_env
252245
.and(type_op::normalize::Normalize::new(ty))
@@ -272,7 +265,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
272265
// }
273266
// ```
274267
// Both &Self::Bar and &() are WF
275-
if use_implied_bounds && ty != norm_ty {
268+
if ty != norm_ty {
276269
let constraints_norm = self.add_implied_bounds(norm_ty);
277270
if let Some(c) = constraints_norm {
278271
constraints.push(c)
@@ -282,22 +275,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
282275
normalized_inputs_and_output.push(norm_ty);
283276
}
284277

285-
let TypeOpOutput { constraints: constraints_wf, .. } = self
286-
.param_env
287-
.and(type_op::ProvePredicate::new(
288-
ty::ClauseKind::WellFormed((*normalized_inputs_and_output.last().unwrap()).into())
289-
.to_predicate(self.infcx.tcx),
290-
))
291-
.fully_perform(self.infcx, span)
292-
.unwrap_or_else(|_: rustc_span::ErrorGuaranteed| TypeOpOutput {
293-
output: (),
294-
constraints: None,
295-
error_info: None,
296-
});
297-
if let Some(c) = constraints_wf {
298-
constraints.push(c)
299-
}
300-
301278
for c in constraints {
302279
self.push_region_constraints(c, span);
303280
}

compiler/rustc_trait_selection/src/traits/wf.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,23 @@ 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();
684686
}
685687

686-
ty::Closure(did, args) | ty::Generator(did, args, ..) => {
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) => {
687701
// Only check the upvar types for WF, not the rest
688702
// of the types within. This is needed because we
689703
// capture the signature and it may not be WF
@@ -705,15 +719,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
705719
// shorthand for something like `where(T: 'a) {
706720
// fn(&'a T) }`, as discussed in #25860.
707721
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-
};
714722
// FIXME(eddyb) add the type to `walker` instead of recursing.
715-
self.compute(upvars.into());
716-
723+
self.compute(args.as_closure().tupled_upvars_ty().into());
717724
// Note that we cannot skip the generic types
718725
// types. Normally, within the fn
719726
// body where they are created, the generics will

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

-17
This file was deleted.

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
error[E0310]: the parameter type `T` may not live long enough
2-
--> $DIR/generator-wf-check.rs:25:8
2+
--> $DIR/generator-wf-check.rs:24:5
33
|
4-
LL | wf(async {
5-
| ________^
4+
LL | / wf(async {
65
LL | |
76
LL | | None::<Static<T>>
87
LL | | });
9-
| |_____^ ...so that the type `T` will meet its required lifetime bounds
8+
| |______^ ...so that the type `T` will meet its required lifetime bounds
109
|
1110
help: consider adding an explicit lifetime bound...
1211
|

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
// edition: 2021
55
// revisions: output output_wf witness witness_wf
6-
//[output] check-fail
6+
//[output] check-pass
77
//[output_wf] check-fail
88
//[witness] check-fail
99
//[witness_wf] check-fail
@@ -15,7 +15,6 @@ fn wf<T>(_: T) {}
1515
#[cfg(output)]
1616
fn test_output<T>() {
1717
async {
18-
//[output]~^ ERROR `T` may not live long enough
1918
None::<Static<T>>
2019
};
2120
}

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

+2-2
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:34:22
2+
--> $DIR/generator-wf-check.rs:33: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:37:9
13+
--> $DIR/generator-wf-check.rs:36: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

+2-2
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:45:22
2+
--> $DIR/generator-wf-check.rs:44: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:48:9
13+
--> $DIR/generator-wf-check.rs:47:9
1414
|
1515
LL | drop(witness);
1616
| ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

tests/ui/borrowck/erase-error-in-mir-drop-tracking.rs

-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ where
1818
{
1919
async move { c.connect().await }
2020
//~^ ERROR `C` does not live long enough
21-
//~| ERROR `C` may not live long enough
22-
//~| ERROR `C` may not live long enough
23-
//~| ERROR `C` may not live long enough
24-
//~| ERROR `C` may not live long enough
25-
//~| ERROR `C` may not live long enough
26-
//~| ERROR `C` may not live long enough
27-
2821
}
2922

3023
fn main() {}

tests/ui/borrowck/erase-error-in-mir-drop-tracking.stderr

+2-69
Original file line numberDiff line numberDiff line change
@@ -19,73 +19,6 @@ error: `C` does not live long enough
1919
LL | async move { c.connect().await }
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2121

22-
error[E0310]: the parameter type `C` may not live long enough
23-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:5
24-
|
25-
LL | async move { c.connect().await }
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `C` will meet its required lifetime bounds
27-
|
28-
help: consider adding an explicit lifetime bound...
29-
|
30-
LL | C: Client + Send + Sync + 'static,
31-
| +++++++++
32-
33-
error[E0310]: the parameter type `C` may not live long enough
34-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:5
35-
|
36-
LL | async move { c.connect().await }
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `C` will meet its required lifetime bounds
38-
|
39-
help: consider adding an explicit lifetime bound...
40-
|
41-
LL | C: Client + Send + Sync + 'static,
42-
| +++++++++
43-
44-
error[E0310]: the parameter type `C` may not live long enough
45-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:18
46-
|
47-
LL | async move { c.connect().await }
48-
| ^^^^^^^^^^^ ...so that the type `C` will meet its required lifetime bounds
49-
|
50-
help: consider adding an explicit lifetime bound...
51-
|
52-
LL | C: Client + Send + Sync + 'static,
53-
| +++++++++
54-
55-
error[E0310]: the parameter type `C` may not live long enough
56-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:18
57-
|
58-
LL | async move { c.connect().await }
59-
| ^^^^^^^^^^^ ...so that the type `C` will meet its required lifetime bounds
60-
|
61-
help: consider adding an explicit lifetime bound...
62-
|
63-
LL | C: Client + Send + Sync + 'static,
64-
| +++++++++
65-
66-
error[E0310]: the parameter type `C` may not live long enough
67-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:30
68-
|
69-
LL | async move { c.connect().await }
70-
| ^^^^^ ...so that the type `C` will meet its required lifetime bounds
71-
|
72-
help: consider adding an explicit lifetime bound...
73-
|
74-
LL | C: Client + Send + Sync + 'static,
75-
| +++++++++
76-
77-
error[E0310]: the parameter type `C` may not live long enough
78-
--> $DIR/erase-error-in-mir-drop-tracking.rs:19:30
79-
|
80-
LL | async move { c.connect().await }
81-
| ^^^^^ ...so that the type `C` will meet its required lifetime bounds
82-
|
83-
help: consider adding an explicit lifetime bound...
84-
|
85-
LL | C: Client + Send + Sync + 'static,
86-
| +++++++++
87-
88-
error: aborting due to 8 previous errors
22+
error: aborting due to 2 previous errors
8923

90-
Some errors have detailed explanations: E0261, E0310.
91-
For more information about an error, try `rustc --explain E0261`.
24+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)