Skip to content

Commit e5615dc

Browse files
committed
[wip] require return types are sized on project
This is a crude and not 100% complete fix, a described in https://zulip-archive.rust-lang.org/144729wgtraits/32496PR83915.html
1 parent 6265286 commit e5615dc

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,23 @@ fn confirm_callable_candidate<'cx, 'tcx>(
13811381
ty: ret_type,
13821382
});
13831383

1384-
confirm_param_env_candidate(selcx, obligation, predicate, false)
1384+
let Progress { ty, mut obligations } =
1385+
confirm_param_env_candidate(selcx, obligation, predicate, false);
1386+
if !ty.references_error() {
1387+
let sized_trait = tcx.lang_items().sized_trait().unwrap(); // FIXME--unwrap
1388+
let sized_predicate = ty::Binder::dummy(ty::TraitRef {
1389+
def_id: sized_trait,
1390+
substs: tcx.mk_substs_trait(ty, &[]),
1391+
})
1392+
.without_const()
1393+
.to_predicate(tcx);
1394+
let cause = obligation.cause.clone();
1395+
let depth = obligation.recursion_depth;
1396+
let param_env = obligation.param_env;
1397+
let obligation = Obligation::with_depth(cause, depth + 1, param_env, sized_predicate);
1398+
obligations.push(obligation);
1399+
}
1400+
Progress { ty, obligations }
13851401
}
13861402

13871403
fn confirm_param_env_candidate<'cx, 'tcx>(

src/test/ui/fn/issue-82633-2.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn weird_situation<F: FnOnce() -> str>() {
2+
println!("if this is reachable, there’s a function type with unsized Output type `str`");
3+
}
4+
5+
fn main() {
6+
weird_situation::<fn() -> str>()
7+
}

src/test/ui/fn/issue-82633.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(unboxed_closures)]
2+
3+
trait A {
4+
fn a()
5+
where
6+
Self: Sized;
7+
}
8+
9+
fn foo<F: FnOnce<()>>()
10+
where
11+
F::Output: A,
12+
{
13+
F::Output::a()
14+
}
15+
16+
fn main() {
17+
foo::<fn() -> dyn A>()
18+
}

0 commit comments

Comments
 (0)