Check Sizedness of return type in WF
This commit is contained in:
parent
f2c4ccd852
commit
23ab0f2cdc
42 changed files with 564 additions and 507 deletions
|
@ -1061,6 +1061,7 @@ fn check_associated_item(
|
|||
let ty = tcx.type_of(item.def_id).instantiate_identity();
|
||||
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
|
||||
wfcx.register_wf_obligation(span, loc, ty.into());
|
||||
check_sized_if_body(wfcx, item.def_id.expect_local(), ty, Some(span));
|
||||
Ok(())
|
||||
}
|
||||
ty::AssocKind::Fn => {
|
||||
|
@ -1185,7 +1186,7 @@ fn check_type_defn<'tcx>(
|
|||
),
|
||||
wfcx.param_env,
|
||||
ty,
|
||||
tcx.require_lang_item(LangItem::Sized, None),
|
||||
tcx.require_lang_item(LangItem::Sized, Some(hir_ty.span)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1312,7 +1313,7 @@ fn check_item_type(
|
|||
),
|
||||
wfcx.param_env,
|
||||
item_ty,
|
||||
tcx.require_lang_item(LangItem::Sized, None),
|
||||
tcx.require_lang_item(LangItem::Sized, Some(ty_span)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1642,6 +1643,31 @@ fn check_fn_or_method<'tcx>(
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If the function has a body, additionally require that the return type is sized.
|
||||
check_sized_if_body(wfcx, def_id, sig.output(), match hir_decl.output {
|
||||
hir::FnRetTy::Return(ty) => Some(ty.span),
|
||||
hir::FnRetTy::DefaultReturn(_) => None,
|
||||
});
|
||||
}
|
||||
|
||||
fn check_sized_if_body<'tcx>(
|
||||
wfcx: &WfCheckingCtxt<'_, 'tcx>,
|
||||
def_id: LocalDefId,
|
||||
ty: Ty<'tcx>,
|
||||
maybe_span: Option<Span>,
|
||||
) {
|
||||
let tcx = wfcx.tcx();
|
||||
if let Some(body) = tcx.hir().maybe_body_owned_by(def_id) {
|
||||
let span = maybe_span.unwrap_or(body.value.span);
|
||||
|
||||
wfcx.register_bound(
|
||||
ObligationCause::new(span, def_id, traits::ObligationCauseCode::SizedReturnType),
|
||||
wfcx.param_env,
|
||||
ty,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(span)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue