Skip to content

Commit 6172aa8

Browse files
Filter out non-Self supertrait predicates in object type astconv
1 parent c8ebde4 commit 6172aa8

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13781378

13791379
let bound_predicate = obligation.predicate.kind();
13801380
match bound_predicate.skip_binder() {
1381-
ty::PredicateKind::Trait(pred) => {
1381+
ty::PredicateKind::Trait(pred) if pred.self_ty() == dummy_self => {
13821382
let pred = bound_predicate.rebind(pred);
13831383
associated_types.entry(span).or_default().extend(
13841384
tcx.associated_items(pred.def_id())
@@ -1387,7 +1387,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13871387
.map(|item| item.def_id),
13881388
);
13891389
}
1390-
ty::PredicateKind::Projection(pred) => {
1390+
ty::PredicateKind::Projection(pred)
1391+
if pred.projection_ty.self_ty() == dummy_self =>
1392+
{
13911393
let pred = bound_predicate.rebind(pred);
13921394
// A `Self` within the original bound will be substituted with a
13931395
// `trait_object_dummy_self`, so check for that.
@@ -1510,7 +1512,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15101512

15111513
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
15121514
bound.map_bound(|mut b| {
1513-
assert_eq!(b.projection_ty.self_ty(), dummy_self);
1515+
assert_eq!(
1516+
b.projection_ty.self_ty(),
1517+
dummy_self,
1518+
"projection doesn't have the dummy self as its `Self` type: {b:?}"
1519+
);
15141520

15151521
// Like for trait refs, verify that `dummy_self` did not leak inside default type
15161522
// parameters.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(trait_alias)]
2+
3+
use std::future::Future;
4+
5+
trait F<Fut: Future<Output = usize>> = Fn() -> Fut;
6+
7+
fn f<Fut>(a: dyn F<Fut>) {}
8+
//~^ ERROR the size for values of type `(dyn Fn() -> Fut + 'static)` cannot be known at compilation time
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the size for values of type `(dyn Fn() -> Fut + 'static)` cannot be known at compilation time
2+
--> $DIR/dont-elaborate-non-self.rs:7:11
3+
|
4+
LL | fn f<Fut>(a: dyn F<Fut>) {}
5+
| ^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `(dyn Fn() -> Fut + 'static)`
8+
= help: unsized fn params are gated as an unstable feature
9+
help: function arguments must have a statically known size, borrowed types always have a known size
10+
|
11+
LL | fn f<Fut>(a: &dyn F<Fut>) {}
12+
| +
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)