From b9ccf35efea99cdaa0a5a6b9c33ee2e500e087d1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 21 Sep 2022 17:41:18 +0000 Subject: [PATCH 1/2] Only register Sized if not trivially sized --- .../src/traits/select/confirmation.rs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index e08f03a270c89..ca2d55b1fd84e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -638,15 +638,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { output_ty, &mut nested, ); - let tr = ty::Binder::dummy(ty::TraitRef::new( - self.tcx().require_lang_item(LangItem::Sized, None), - self.tcx().mk_substs_trait(output_ty, &[]), - )); - nested.push(Obligation::new( - cause, - obligation.param_env, - tr.to_poly_trait_predicate().to_predicate(self.tcx()), - )); + if !output_ty.is_trivially_sized(self.tcx()) { + let tr = ty::Binder::dummy(ty::TraitRef::new( + self.tcx().require_lang_item(LangItem::Sized, None), + self.tcx().mk_substs_trait(output_ty, &[]), + )); + nested.push(Obligation::new( + cause, + obligation.param_env, + tr.to_poly_trait_predicate().to_predicate(self.tcx()), + )); + } Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested }) } From 92531f8537a8e4fb1ae3dc6d3c4e61cda7cbe1f0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 21 Sep 2022 20:50:41 +0000 Subject: [PATCH 2/2] only confirm fn pointers --- .../rustc_trait_selection/src/traits/select/confirmation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index ca2d55b1fd84e..88849652bc78d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -638,7 +638,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { output_ty, &mut nested, ); - if !output_ty.is_trivially_sized(self.tcx()) { + if self_ty.is_fn_ptr() && !output_ty.is_trivially_sized(self.tcx()) { let tr = ty::Binder::dummy(ty::TraitRef::new( self.tcx().require_lang_item(LangItem::Sized, None), self.tcx().mk_substs_trait(output_ty, &[]),