clean up, push silencing logic to more relevant places
This commit is contained in:
parent
d9ab4ff9a3
commit
affa038c29
2 changed files with 49 additions and 41 deletions
|
@ -498,10 +498,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr.span,
|
||||
infer::LateBoundRegionConversionTime::FnCall,
|
||||
&fn_sig.output()).0;
|
||||
if !fn_sig.output().references_error() {
|
||||
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
// We always require that the type provided as the value for
|
||||
// a type parameter outlives the moment of instantiation.
|
||||
|
|
|
@ -1097,9 +1097,7 @@ fn check_fn<'a, 'tcx>(
|
|||
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);
|
||||
|
||||
let declared_ret_ty = fn_sig.output();
|
||||
if !declared_ret_ty.references_error() {
|
||||
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
|
||||
}
|
||||
let revealed_ret_ty = fcx.instantiate_opaque_types_from_value(
|
||||
fn_id,
|
||||
&declared_ret_ty,
|
||||
|
@ -2700,31 +2698,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
traits::ObligationCause::new(span, self.body_id, code));
|
||||
}
|
||||
|
||||
pub fn require_type_is_sized(&self,
|
||||
pub fn require_type_is_sized(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
code: traits::ObligationCauseCode<'tcx>)
|
||||
{
|
||||
code: traits::ObligationCauseCode<'tcx>,
|
||||
) {
|
||||
if !ty.references_error() {
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||
self.require_type_meets(ty, span, code, lang_item);
|
||||
}
|
||||
|
||||
pub fn require_type_is_sized_deferred(&self,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
code: traits::ObligationCauseCode<'tcx>)
|
||||
{
|
||||
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
|
||||
}
|
||||
|
||||
pub fn register_bound(&self,
|
||||
pub fn require_type_is_sized_deferred(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
code: traits::ObligationCauseCode<'tcx>,
|
||||
) {
|
||||
if !ty.references_error() {
|
||||
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_bound(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
def_id: DefId,
|
||||
cause: traits::ObligationCause<'tcx>)
|
||||
{
|
||||
cause: traits::ObligationCause<'tcx>,
|
||||
) {
|
||||
if !ty.references_error() {
|
||||
self.fulfillment_cx.borrow_mut()
|
||||
.register_bound(self, self.param_env, ty, def_id, cause);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_ty(&self, ast_t: &hir::Ty) -> Ty<'tcx> {
|
||||
let t = AstConv::ast_ty_to_ty(self, ast_t);
|
||||
|
@ -2782,24 +2789,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
/// Registers an obligation for checking later, during regionck, that the type `ty` must
|
||||
/// outlive the region `r`.
|
||||
pub fn register_wf_obligation(&self,
|
||||
pub fn register_wf_obligation(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
code: traits::ObligationCauseCode<'tcx>)
|
||||
{
|
||||
code: traits::ObligationCauseCode<'tcx>,
|
||||
) {
|
||||
// WF obligations never themselves fail, so no real need to give a detailed cause:
|
||||
let cause = traits::ObligationCause::new(span, self.body_id, code);
|
||||
self.register_predicate(traits::Obligation::new(cause,
|
||||
self.param_env,
|
||||
ty::Predicate::WellFormed(ty)));
|
||||
self.register_predicate(
|
||||
traits::Obligation::new(cause, self.param_env, ty::Predicate::WellFormed(ty)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Registers obligations that all types appearing in `substs` are well-formed.
|
||||
pub fn add_wf_bounds(&self, substs: SubstsRef<'tcx>, expr: &hir::Expr) {
|
||||
for ty in substs.types() {
|
||||
if !ty.references_error() {
|
||||
self.register_wf_obligation(ty, expr.span, traits::MiscObligation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a fully substituted set of bounds (`generic_bounds`), and the values with which each
|
||||
/// type/region parameter was instantiated (`substs`), creates and registers suitable
|
||||
|
@ -2836,12 +2846,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// FIXME(arielb1): use this instead of field.ty everywhere
|
||||
// Only for fields! Returns <none> for methods>
|
||||
// Indifferent to privacy flags
|
||||
pub fn field_ty(&self,
|
||||
pub fn field_ty(
|
||||
&self,
|
||||
span: Span,
|
||||
field: &'tcx ty::FieldDef,
|
||||
substs: SubstsRef<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
substs: SubstsRef<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
self.normalize_associated_types_in(span, &field.ty(self.tcx, substs))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue