Skip to content

Commit 5b84550

Browse files
committed
Keep an obligation for both sized and unsized types
1 parent 412ad9b commit 5b84550

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Diff for: src/librustc_typeck/check/wfcheck.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -340,33 +340,31 @@ fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
340340
})
341341
}
342342

343-
fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
344-
item_id: ast::NodeId,
345-
ty_span: Span,
346-
allow_foreign_ty: bool) {
343+
fn check_item_type<'a, 'tcx>(
344+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
345+
item_id: ast::NodeId,
346+
ty_span: Span,
347+
allow_foreign_ty: bool,
348+
) {
347349
debug!("check_item_type: {:?}", item_id);
348350

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

353-
let mut allow_unsized = false;
355+
let mut forbid_unsized = true;
354356
if allow_foreign_ty {
355357
if let TyKind::Foreign(_) = tcx.struct_tail(item_ty).sty {
356-
allow_unsized = true;
358+
forbid_unsized = false;
357359
}
358360
}
359361

360-
if !allow_unsized {
361-
fcx.register_wf_obligation(item_ty, ty_span, ObligationCauseCode::MiscObligation);
362+
fcx.register_wf_obligation(item_ty, ty_span, ObligationCauseCode::MiscObligation);
363+
if forbid_unsized {
362364
fcx.register_bound(
363365
item_ty,
364366
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
365-
traits::ObligationCause::new(
366-
ty_span,
367-
fcx.body_id,
368-
traits::MiscObligation,
369-
),
367+
traits::ObligationCause::new(ty_span, fcx.body_id, traits::MiscObligation),
370368
);
371369
}
372370

0 commit comments

Comments
 (0)