Skip to content

Commit b5d740d

Browse files
Gate things properly
1 parent f904c20 commit b5d740d

12 files changed

+121
-14
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
160160
let mut next_outlives_predicates = vec![];
161161
for (pred, constraint_category) in outlives_predicates {
162162
// Constraint is implied by a coroutine's well-formedness.
163-
if higher_ranked_assumptions.contains(&pred) {
163+
if self.infcx.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
164+
&& higher_ranked_assumptions.contains(&pred)
165+
{
164166
continue;
165167
}
166168

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ impl<'tcx> InferCtxt<'tcx> {
6969

7070
// Filter out any region-region outlives assumptions that are implied by
7171
// coroutine well-formedness.
72-
storage.data.constraints.retain(|(constraint, _)| match *constraint {
73-
Constraint::RegSubReg(r1, r2) => !outlives_env
74-
.higher_ranked_assumptions()
75-
.contains(&ty::OutlivesPredicate(r2.into(), r1)),
76-
_ => true,
77-
});
72+
if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions {
73+
storage.data.constraints.retain(|(constraint, _)| match *constraint {
74+
Constraint::RegSubReg(r1, r2) => !outlives_env
75+
.higher_ranked_assumptions()
76+
.contains(&ty::OutlivesPredicate(r2.into(), r1)),
77+
_ => true,
78+
});
79+
}
7880

7981
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
8082

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ impl<'tcx> InferCtxt<'tcx> {
234234
let (sup_type, sub_region) =
235235
(sup_type, sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
236236

237-
if outlives_env
238-
.higher_ranked_assumptions()
239-
.contains(&ty::OutlivesPredicate(sup_type.into(), sub_region))
237+
if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
238+
&& outlives_env
239+
.higher_ranked_assumptions()
240+
.contains(&ty::OutlivesPredicate(sup_type.into(), sub_region))
240241
{
241242
continue;
242243
}

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,8 @@ options! {
22562256
environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
22572257
has_thread_local: Option<bool> = (None, parse_opt_bool, [TRACKED],
22582258
"explicitly enable the `cfg(target_thread_local)` directive"),
2259+
higher_ranked_assumptions: bool = (false, parse_bool, [TRACKED],
2260+
"allow deducing higher-ranked outlives assumptions from coroutines when proving auto traits"),
22592261
hint_mostly_unused: bool = (false, parse_bool, [TRACKED],
22602262
"hint that most of this crate will go unused, to minimize work for uncalled functions"),
22612263
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/drop-tracking-unresolved-typeck-results.rs:102:5
3+
|
4+
LL | / send(async {
5+
LL | | Next(&Buffered(Map(Empty(PhantomData), ready::<&()>), FuturesOrdered(PhantomData), 0)).await
6+
LL | | });
7+
| |______^ implementation of `FnOnce` is not general enough
8+
|
9+
= note: `fn(&'0 ()) -> std::future::Ready<&'0 ()> {std::future::ready::<&'0 ()>}` must implement `FnOnce<(&'1 (),)>`, for any two lifetimes `'0` and `'1`...
10+
= note: ...but it actually implements `FnOnce<(&(),)>`
11+
12+
error: implementation of `FnOnce` is not general enough
13+
--> $DIR/drop-tracking-unresolved-typeck-results.rs:102:5
14+
|
15+
LL | / send(async {
16+
LL | | Next(&Buffered(Map(Empty(PhantomData), ready::<&()>), FuturesOrdered(PhantomData), 0)).await
17+
LL | | });
18+
| |______^ implementation of `FnOnce` is not general enough
19+
|
20+
= note: `fn(&'0 ()) -> std::future::Ready<&'0 ()> {std::future::ready::<&'0 ()>}` must implement `FnOnce<(&'1 (),)>`, for any two lifetimes `'0` and `'1`...
21+
= note: ...but it actually implements `FnOnce<(&(),)>`
22+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
23+
24+
error: aborting due to 2 previous errors
25+

tests/ui/async-await/drop-tracking-unresolved-typeck-results.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//@ incremental
22
//@ edition: 2021
3-
//@ check-pass
3+
//@ revisions: assumptions no_assumptions
4+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
5+
//@[assumptions] check-pass
6+
//@[no_assumptions] known-bug: #110338
47

58
use std::future::*;
69
use std::marker::PhantomData;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: implementation of `Send` is not general enough
2+
--> $DIR/issue-110963-early.rs:17:5
3+
|
4+
LL | / spawn(async move {
5+
LL | | let mut hc = hc;
6+
LL | | if !hc.check().await {
7+
LL | | log_health_check_failure().await;
8+
LL | | }
9+
LL | | });
10+
| |______^ implementation of `Send` is not general enough
11+
|
12+
= note: `Send` would have to be implemented for the type `impl Future<Output = bool> { <HC as HealthCheck>::check<'0>(..) }`, for any two lifetimes `'0` and `'1`...
13+
= note: ...but `Send` is actually implemented for the type `impl Future<Output = bool> { <HC as HealthCheck>::check<'2>(..) }`, for some specific lifetime `'2`
14+
15+
error: implementation of `Send` is not general enough
16+
--> $DIR/issue-110963-early.rs:17:5
17+
|
18+
LL | / spawn(async move {
19+
LL | | let mut hc = hc;
20+
LL | | if !hc.check().await {
21+
LL | | log_health_check_failure().await;
22+
LL | | }
23+
LL | | });
24+
| |______^ implementation of `Send` is not general enough
25+
|
26+
= note: `Send` would have to be implemented for the type `impl Future<Output = bool> { <HC as HealthCheck>::check<'0>(..) }`, for any two lifetimes `'0` and `'1`...
27+
= note: ...but `Send` is actually implemented for the type `impl Future<Output = bool> { <HC as HealthCheck>::check<'2>(..) }`, for some specific lifetime `'2`
28+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29+
30+
error: aborting due to 2 previous errors
31+

tests/ui/async-await/return-type-notation/issue-110963-early.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//@ edition: 2021
2-
//@ check-pass
2+
//@ revisions: assumptions no_assumptions
3+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
4+
//@[assumptions] check-pass
5+
//@[no_assumptions] known-bug: #110338
36

47
#![feature(return_type_notation)]
58

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: lifetime bound not satisfied
2+
--> $DIR/higher-ranked-coroutine-param-outlives-2.rs:14:5
3+
|
4+
LL | / async { // a coroutine checked for autotrait impl `Send`
5+
LL | | let x = None::<I::Future<'_, '_>>; // a type referencing GAT
6+
LL | | async {}.await; // a yield point
7+
LL | | }
8+
| |_____^
9+
|
10+
= note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
11+
12+
error: lifetime bound not satisfied
13+
--> $DIR/higher-ranked-coroutine-param-outlives-2.rs:21:5
14+
|
15+
LL | / async { // a coroutine checked for autotrait impl `Send`
16+
LL | | let x = None::<I::Future<'a, 'b>>; // a type referencing GAT
17+
LL | | async {}.await; // a yield point
18+
LL | | }
19+
| |_____^
20+
|
21+
= note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
22+
23+
error: aborting due to 2 previous errors
24+

tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
//@ check-pass
21
//@ edition: 2021
2+
//@ revisions: assumptions no_assumptions
3+
//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
4+
//@[assumptions] check-pass
5+
//@[no_assumptions] known-bug: #110338
36

47
pub trait FutureIterator {
58
type Future<'s, 'cx>: Send

0 commit comments

Comments
 (0)