Skip to content

Commit affa038

Browse files
committed
clean up, push silencing logic to more relevant places
1 parent d9ab4ff commit affa038

File tree

2 files changed

+49
-41
lines changed

2 files changed

+49
-41
lines changed

src/librustc_typeck/check/expr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
498498
expr.span,
499499
infer::LateBoundRegionConversionTime::FnCall,
500500
&fn_sig.output()).0;
501-
if !fn_sig.output().references_error() {
502-
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
503-
}
501+
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
504502
}
505503

506504
// We always require that the type provided as the value for

src/librustc_typeck/check/mod.rs

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,7 @@ fn check_fn<'a, 'tcx>(
10971097
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);
10981098

10991099
let declared_ret_ty = fn_sig.output();
1100-
if !declared_ret_ty.references_error() {
1101-
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
1102-
}
1100+
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
11031101
let revealed_ret_ty = fcx.instantiate_opaque_types_from_value(
11041102
fn_id,
11051103
&declared_ret_ty,
@@ -2700,30 +2698,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27002698
traits::ObligationCause::new(span, self.body_id, code));
27012699
}
27022700

2703-
pub fn require_type_is_sized(&self,
2704-
ty: Ty<'tcx>,
2705-
span: Span,
2706-
code: traits::ObligationCauseCode<'tcx>)
2707-
{
2708-
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
2709-
self.require_type_meets(ty, span, code, lang_item);
2701+
pub fn require_type_is_sized(
2702+
&self,
2703+
ty: Ty<'tcx>,
2704+
span: Span,
2705+
code: traits::ObligationCauseCode<'tcx>,
2706+
) {
2707+
if !ty.references_error() {
2708+
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
2709+
self.require_type_meets(ty, span, code, lang_item);
2710+
}
27102711
}
27112712

2712-
pub fn require_type_is_sized_deferred(&self,
2713-
ty: Ty<'tcx>,
2714-
span: Span,
2715-
code: traits::ObligationCauseCode<'tcx>)
2716-
{
2717-
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
2713+
pub fn require_type_is_sized_deferred(
2714+
&self,
2715+
ty: Ty<'tcx>,
2716+
span: Span,
2717+
code: traits::ObligationCauseCode<'tcx>,
2718+
) {
2719+
if !ty.references_error() {
2720+
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
2721+
}
27182722
}
27192723

2720-
pub fn register_bound(&self,
2721-
ty: Ty<'tcx>,
2722-
def_id: DefId,
2723-
cause: traits::ObligationCause<'tcx>)
2724-
{
2725-
self.fulfillment_cx.borrow_mut()
2726-
.register_bound(self, self.param_env, ty, def_id, cause);
2724+
pub fn register_bound(
2725+
&self,
2726+
ty: Ty<'tcx>,
2727+
def_id: DefId,
2728+
cause: traits::ObligationCause<'tcx>,
2729+
) {
2730+
if !ty.references_error() {
2731+
self.fulfillment_cx.borrow_mut()
2732+
.register_bound(self, self.param_env, ty, def_id, cause);
2733+
}
27272734
}
27282735

27292736
pub fn to_ty(&self, ast_t: &hir::Ty) -> Ty<'tcx> {
@@ -2782,22 +2789,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27822789

27832790
/// Registers an obligation for checking later, during regionck, that the type `ty` must
27842791
/// outlive the region `r`.
2785-
pub fn register_wf_obligation(&self,
2786-
ty: Ty<'tcx>,
2787-
span: Span,
2788-
code: traits::ObligationCauseCode<'tcx>)
2789-
{
2792+
pub fn register_wf_obligation(
2793+
&self,
2794+
ty: Ty<'tcx>,
2795+
span: Span,
2796+
code: traits::ObligationCauseCode<'tcx>,
2797+
) {
27902798
// WF obligations never themselves fail, so no real need to give a detailed cause:
27912799
let cause = traits::ObligationCause::new(span, self.body_id, code);
2792-
self.register_predicate(traits::Obligation::new(cause,
2793-
self.param_env,
2794-
ty::Predicate::WellFormed(ty)));
2800+
self.register_predicate(
2801+
traits::Obligation::new(cause, self.param_env, ty::Predicate::WellFormed(ty)),
2802+
);
27952803
}
27962804

27972805
/// Registers obligations that all types appearing in `substs` are well-formed.
27982806
pub fn add_wf_bounds(&self, substs: SubstsRef<'tcx>, expr: &hir::Expr) {
27992807
for ty in substs.types() {
2800-
self.register_wf_obligation(ty, expr.span, traits::MiscObligation);
2808+
if !ty.references_error() {
2809+
self.register_wf_obligation(ty, expr.span, traits::MiscObligation);
2810+
}
28012811
}
28022812
}
28032813

@@ -2836,12 +2846,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28362846
// FIXME(arielb1): use this instead of field.ty everywhere
28372847
// Only for fields! Returns <none> for methods>
28382848
// Indifferent to privacy flags
2839-
pub fn field_ty(&self,
2840-
span: Span,
2841-
field: &'tcx ty::FieldDef,
2842-
substs: SubstsRef<'tcx>)
2843-
-> Ty<'tcx>
2844-
{
2849+
pub fn field_ty(
2850+
&self,
2851+
span: Span,
2852+
field: &'tcx ty::FieldDef,
2853+
substs: SubstsRef<'tcx>,
2854+
) -> Ty<'tcx> {
28452855
self.normalize_associated_types_in(span, &field.ty(self.tcx, substs))
28462856
}
28472857

0 commit comments

Comments
 (0)