Skip to content

Commit 9ea587e

Browse files
committedMar 6, 2025
Revert "Rollup merge of rust-lang#136274 - compiler-errors:sized-wf, r=lcnr"
This reverts commit a8ecb79, reversing changes made to 40c4e05.
1 parent 61e1603 commit 9ea587e

File tree

61 files changed

+430
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+430
-521
lines changed
 

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-33
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ fn check_associated_item(
11101110
let ty = tcx.type_of(item.def_id).instantiate_identity();
11111111
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
11121112
wfcx.register_wf_obligation(span, loc, ty.into());
1113-
check_sized_if_body(wfcx, item.def_id.expect_local(), ty, Some(span));
11141113
Ok(())
11151114
}
11161115
ty::AssocKind::Fn => {
@@ -1235,7 +1234,7 @@ fn check_type_defn<'tcx>(
12351234
),
12361235
wfcx.param_env,
12371236
ty,
1238-
tcx.require_lang_item(LangItem::Sized, Some(hir_ty.span)),
1237+
tcx.require_lang_item(LangItem::Sized, None),
12391238
);
12401239
}
12411240

@@ -1360,7 +1359,7 @@ fn check_item_type(
13601359
),
13611360
wfcx.param_env,
13621361
item_ty,
1363-
tcx.require_lang_item(LangItem::Sized, Some(ty_span)),
1362+
tcx.require_lang_item(LangItem::Sized, None),
13641363
);
13651364
}
13661365

@@ -1690,36 +1689,6 @@ fn check_fn_or_method<'tcx>(
16901689
);
16911690
}
16921691
}
1693-
1694-
// If the function has a body, additionally require that the return type is sized.
1695-
check_sized_if_body(
1696-
wfcx,
1697-
def_id,
1698-
sig.output(),
1699-
match hir_decl.output {
1700-
hir::FnRetTy::Return(ty) => Some(ty.span),
1701-
hir::FnRetTy::DefaultReturn(_) => None,
1702-
},
1703-
);
1704-
}
1705-
1706-
fn check_sized_if_body<'tcx>(
1707-
wfcx: &WfCheckingCtxt<'_, 'tcx>,
1708-
def_id: LocalDefId,
1709-
ty: Ty<'tcx>,
1710-
maybe_span: Option<Span>,
1711-
) {
1712-
let tcx = wfcx.tcx();
1713-
if let Some(body) = tcx.hir().maybe_body_owned_by(def_id) {
1714-
let span = maybe_span.unwrap_or(body.value.span);
1715-
1716-
wfcx.register_bound(
1717-
ObligationCause::new(span, def_id, traits::ObligationCauseCode::SizedReturnType),
1718-
wfcx.param_env,
1719-
ty,
1720-
tcx.require_lang_item(LangItem::Sized, Some(span)),
1721-
);
1722-
}
17231692
}
17241693

17251694
/// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.

‎compiler/rustc_hir_typeck/src/check.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,22 @@ pub(super) fn check_fn<'a, 'tcx>(
117117

118118
fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
119119

120-
// We checked the root's ret ty during wfcheck, but not the child.
121-
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
122-
let return_or_body_span = match decl.output {
123-
hir::FnRetTy::DefaultReturn(_) => body.value.span,
124-
hir::FnRetTy::Return(ty) => ty.span,
125-
};
120+
let return_or_body_span = match decl.output {
121+
hir::FnRetTy::DefaultReturn(_) => body.value.span,
122+
hir::FnRetTy::Return(ty) => ty.span,
123+
};
126124

125+
fcx.require_type_is_sized(
126+
declared_ret_ty,
127+
return_or_body_span,
128+
ObligationCauseCode::SizedReturnType,
129+
);
130+
// We checked the root's signature during wfcheck, but not the child.
131+
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
127132
fcx.require_type_is_sized(
128133
declared_ret_ty,
129134
return_or_body_span,
130-
ObligationCauseCode::SizedReturnType,
135+
ObligationCauseCode::WellFormed(None),
131136
);
132137
}
133138

0 commit comments

Comments
 (0)