Skip to content

Commit

Permalink
Keep an obligation for both sized and unsized types
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbshaw committed Oct 22, 2018
1 parent 412ad9b commit 5b84550
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,33 +340,31 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
})
}

fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_id: ast::NodeId,
ty_span: Span,
allow_foreign_ty: bool) {
fn check_item_type<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_id: ast::NodeId,
ty_span: Span,
allow_foreign_ty: bool,
) {
debug!("check_item_type: {:?}", item_id);

for_id(tcx, item_id, ty_span).with_fcx(|fcx, _this| {
let ty = fcx.tcx.type_of(fcx.tcx.hir.local_def_id(item_id));
let item_ty = fcx.normalize_associated_types_in(ty_span, &ty);

let mut allow_unsized = false;
let mut forbid_unsized = true;
if allow_foreign_ty {
if let TyKind::Foreign(_) = tcx.struct_tail(item_ty).sty {
allow_unsized = true;
forbid_unsized = false;
}
}

if !allow_unsized {
fcx.register_wf_obligation(item_ty, ty_span, ObligationCauseCode::MiscObligation);
fcx.register_wf_obligation(item_ty, ty_span, ObligationCauseCode::MiscObligation);
if forbid_unsized {
fcx.register_bound(
item_ty,
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
traits::ObligationCause::new(
ty_span,
fcx.body_id,
traits::MiscObligation,
),
traits::ObligationCause::new(ty_span, fcx.body_id, traits::MiscObligation),
);
}

Expand Down

0 comments on commit 5b84550

Please sign in to comment.