Skip to content

Commit

Permalink
[wip] require return types are sized on project
Browse files Browse the repository at this point in the history
This is a crude and not 100% complete fix, a described in
https://zulip-archive.rust-lang.org/144729wgtraits/32496PR83915.html
  • Loading branch information
nikomatsakis committed Apr 20, 2021
1 parent 6265286 commit e5615dc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
18 changes: 17 additions & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,23 @@ fn confirm_callable_candidate<'cx, 'tcx>(
ty: ret_type,
});

confirm_param_env_candidate(selcx, obligation, predicate, false)
let Progress { ty, mut obligations } =
confirm_param_env_candidate(selcx, obligation, predicate, false);
if !ty.references_error() {
let sized_trait = tcx.lang_items().sized_trait().unwrap(); // FIXME--unwrap
let sized_predicate = ty::Binder::dummy(ty::TraitRef {
def_id: sized_trait,
substs: tcx.mk_substs_trait(ty, &[]),
})
.without_const()
.to_predicate(tcx);
let cause = obligation.cause.clone();
let depth = obligation.recursion_depth;
let param_env = obligation.param_env;
let obligation = Obligation::with_depth(cause, depth + 1, param_env, sized_predicate);
obligations.push(obligation);
}
Progress { ty, obligations }
}

fn confirm_param_env_candidate<'cx, 'tcx>(
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/fn/issue-82633-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn weird_situation<F: FnOnce() -> str>() {
println!("if this is reachable, there’s a function type with unsized Output type `str`");
}

fn main() {
weird_situation::<fn() -> str>()
}
18 changes: 18 additions & 0 deletions src/test/ui/fn/issue-82633.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(unboxed_closures)]

trait A {
fn a()
where
Self: Sized;
}

fn foo<F: FnOnce<()>>()
where
F::Output: A,
{
F::Output::a()
}

fn main() {
foo::<fn() -> dyn A>()
}

0 comments on commit e5615dc

Please sign in to comment.