diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index b3e5df4da0a9f..5c2c49d8f1c89 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -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>( diff --git a/src/test/ui/fn/issue-82633-2.rs b/src/test/ui/fn/issue-82633-2.rs new file mode 100644 index 0000000000000..68e04d1610b2b --- /dev/null +++ b/src/test/ui/fn/issue-82633-2.rs @@ -0,0 +1,7 @@ +fn weird_situation str>() { + println!("if this is reachable, there’s a function type with unsized Output type `str`"); +} + +fn main() { + weird_situation:: str>() +} diff --git a/src/test/ui/fn/issue-82633.rs b/src/test/ui/fn/issue-82633.rs new file mode 100644 index 0000000000000..dba48914d00fa --- /dev/null +++ b/src/test/ui/fn/issue-82633.rs @@ -0,0 +1,18 @@ +#![feature(unboxed_closures)] + +trait A { + fn a() + where + Self: Sized; +} + +fn foo>() +where + F::Output: A, +{ + F::Output::a() +} + +fn main() { + foo:: dyn A>() +}