Skip to content

Commit 96aebe2

Browse files
authored
Unrolled build for rust-lang#132194
Rollup merge of rust-lang#132194 - compiler-errors:rpitit-super-wc, r=spastorino Collect item bounds for RPITITs from trait where clauses just like associated types We collect item bounds from trait where clauses for *associated types*, i.e. this: ```rust trait Foo where Self::Assoc: Send { type Assoc; } ``` Becomes this: ```rust trait Foo { type Assoc: Send; } ``` Today, with RPITITs/AFIT and return-type notation, we don't do that, i.e.: ```rust trait Foo where Self::method(..): Send { fn method() -> impl Sized; } fn is_send(_: impl Send) {} fn test<T: Foo>() { is_send(T::method()); } ``` ...which fails on nightly today. Turns out it's super easy to fix this, and we just need to use the `associated_type_bounds` lowering function in `explicit_item_bounds_with_filter`, which has that logic baked in.
2 parents c8a8c82 + 6ab87f8 commit 96aebe2

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,8 @@ pub(super) fn explicit_item_bounds_with_filter(
367367
// a projection self type.
368368
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
369369
let opaque_ty = tcx.hir_node_by_def_id(opaque_def_id.expect_local()).expect_opaque_ty();
370-
let item_ty = Ty::new_projection_from_args(
371-
tcx,
372-
def_id.to_def_id(),
373-
ty::GenericArgs::identity_for_item(tcx, def_id),
374-
);
375-
let bounds = opaque_type_bounds(
376-
tcx,
377-
opaque_def_id.expect_local(),
378-
opaque_ty.bounds,
379-
item_ty,
380-
opaque_ty.span,
381-
filter,
382-
);
383-
assert_only_contains_predicates_from(filter, bounds, item_ty);
370+
let bounds =
371+
associated_type_bounds(tcx, def_id, opaque_ty.bounds, opaque_ty.span, filter);
384372
return ty::EarlyBinder::bind(bounds);
385373
}
386374
Some(ty::ImplTraitInTraitData::Impl { .. }) => span_bug!(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Make sure that, like associated type where clauses on traits, we gather item
2+
// bounds for RPITITs from RTN where clauses.
3+
4+
//@ check-pass
5+
6+
#![feature(return_type_notation)]
7+
8+
trait Foo
9+
where
10+
Self::method(..): Send,
11+
{
12+
fn method() -> impl Sized;
13+
}
14+
15+
fn is_send(_: impl Send) {}
16+
17+
fn test<T: Foo>() {
18+
is_send(T::method());
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)