Skip to content

Commit d055d6a

Browse files
authored
Rollup merge of #105247 - cjgillot:issue-102682, r=compiler-errors
Use parent function WfCheckingContext to check RPITIT. WF-check for RPITIT was done in the opaque type's param-env, so it could not benefit from assumed wf types from the function's parameters. cc `@compiler-errors` since you chose that param-env in fd2766e Fixes #102682 Fixes #104908 Fixes #102552 Fixes #104529
2 parents f3eba21 + 12473d3 commit d055d6a

9 files changed

+63
-75
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ fn check_fn_or_method<'tcx>(
15441544
check_where_clauses(wfcx, span, def_id);
15451545

15461546
check_return_position_impl_trait_in_trait_bounds(
1547-
tcx,
1547+
wfcx,
15481548
def_id,
15491549
sig.output(),
15501550
hir_decl.output.span(),
@@ -1580,13 +1580,14 @@ fn check_fn_or_method<'tcx>(
15801580

15811581
/// Basically `check_associated_type_bounds`, but separated for now and should be
15821582
/// deduplicated when RPITITs get lowered into real associated items.
1583-
#[tracing::instrument(level = "trace", skip(tcx))]
1583+
#[tracing::instrument(level = "trace", skip(wfcx))]
15841584
fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
1585-
tcx: TyCtxt<'tcx>,
1585+
wfcx: &WfCheckingCtxt<'_, 'tcx>,
15861586
fn_def_id: LocalDefId,
15871587
fn_output: Ty<'tcx>,
15881588
span: Span,
15891589
) {
1590+
let tcx = wfcx.tcx();
15901591
if let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id())
15911592
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
15921593
{
@@ -1596,22 +1597,20 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15961597
&& tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
15971598
&& tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id()
15981599
{
1599-
// Create a new context, since we want the opaque's ParamEnv and not the parent's.
16001600
let span = tcx.def_span(proj.item_def_id);
1601-
enter_wf_checking_ctxt(tcx, span, proj.item_def_id.expect_local(), |wfcx| {
1602-
let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id);
1603-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1604-
let normalized_bound = wfcx.normalize(span, None, bound);
1605-
traits::wf::predicate_obligations(
1606-
wfcx.infcx,
1607-
wfcx.param_env,
1608-
wfcx.body_id,
1609-
normalized_bound,
1610-
bound_span,
1611-
)
1612-
});
1613-
wfcx.register_obligations(wf_obligations);
1601+
let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id);
1602+
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1603+
let bound = ty::EarlyBinder(bound).subst(tcx, proj.substs);
1604+
let normalized_bound = wfcx.normalize(span, None, bound);
1605+
traits::wf::predicate_obligations(
1606+
wfcx.infcx,
1607+
wfcx.param_env,
1608+
wfcx.body_id,
1609+
normalized_bound,
1610+
bound_span,
1611+
)
16141612
});
1613+
wfcx.register_obligations(wf_obligations);
16151614
}
16161615
}
16171616
}

src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error[E0311]: the parameter type `U` may not live long enough
44
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
55
| ^^^^^^^
66
|
7-
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
7+
note: the parameter type `U` must be valid for the anonymous lifetime defined here...
88
--> $DIR/async-generics-and-bounds.rs:12:18
99
|
1010
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
11-
| ^
11+
| ^^^^^
1212
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
1313
--> $DIR/async-generics-and-bounds.rs:12:28
1414
|
@@ -21,11 +21,11 @@ error[E0311]: the parameter type `T` may not live long enough
2121
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
2222
| ^^^^^^^
2323
|
24-
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
24+
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
2525
--> $DIR/async-generics-and-bounds.rs:12:18
2626
|
2727
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
28-
| ^
28+
| ^^^^^
2929
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
3030
--> $DIR/async-generics-and-bounds.rs:12:28
3131
|

src/test/ui/async-await/in-trait/async-generics.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error[E0311]: the parameter type `U` may not live long enough
44
LL | async fn foo(&self) -> &(T, U);
55
| ^^^^^^^
66
|
7-
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
7+
note: the parameter type `U` must be valid for the anonymous lifetime defined here...
88
--> $DIR/async-generics.rs:9:18
99
|
1010
LL | async fn foo(&self) -> &(T, U);
11-
| ^
11+
| ^^^^^
1212
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
1313
--> $DIR/async-generics.rs:9:28
1414
|
@@ -21,11 +21,11 @@ error[E0311]: the parameter type `T` may not live long enough
2121
LL | async fn foo(&self) -> &(T, U);
2222
| ^^^^^^^
2323
|
24-
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
24+
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
2525
--> $DIR/async-generics.rs:9:18
2626
|
2727
LL | async fn foo(&self) -> &(T, U);
28-
| ^
28+
| ^^^^^
2929
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
3030
--> $DIR/async-generics.rs:9:28
3131
|

src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-fail
2-
// known-bug: #102682
1+
// check-pass
32
// edition: 2021
43

54
#![feature(async_fn_in_trait)]

src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.stderr

-23
This file was deleted.

src/test/ui/async-await/in-trait/async-lifetimes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-fail
2-
// known-bug: #102682
1+
// check-pass
32
// edition: 2021
43

54
#![feature(async_fn_in_trait)]

src/test/ui/async-await/in-trait/async-lifetimes.stderr

-23
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
trait TcpStack {
8+
type Connection<'a>: Sized where Self: 'a;
9+
fn connect<'a>(&'a self) -> Self::Connection<'a>;
10+
async fn async_connect<'a>(&'a self) -> Self::Connection<'a>;
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
#![feature(return_position_impl_trait_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
use std::fmt::Debug;
8+
9+
trait Foo<Item> {
10+
fn foo<'a>(&'a self) -> impl Debug
11+
where
12+
Item: 'a;
13+
}
14+
15+
impl<Item, D: Debug + Clone> Foo<Item> for D {
16+
fn foo<'a>(&'a self) -> impl Debug
17+
where
18+
Item: 'a,
19+
{
20+
self.clone()
21+
}
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)