Skip to content

Commit 4307541

Browse files
committed
aligns the behavior to that prior to rust-lang#118311
1 parent 46a24ed commit 4307541

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
862862
}
863863
}
864864

865-
fn should_encode_attrs(def_kind: DefKind) -> bool {
865+
fn should_encode_attrs(def_kind: DefKind, is_coroutine: bool) -> bool {
866866
match def_kind {
867867
DefKind::Mod
868868
| DefKind::Struct
@@ -886,7 +886,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
886886
// closures from upstream crates, too. This is used by
887887
// https://github.com/model-checking/kani and is not a performance
888888
// or maintenance issue for us.
889-
DefKind::Closure => true,
889+
DefKind::Closure => !is_coroutine,
890890
DefKind::TyParam
891891
| DefKind::ConstParam
892892
| DefKind::Ctor(..)
@@ -1228,11 +1228,11 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
12281228
}
12291229
}
12301230

1231-
fn should_encode_constness(def_kind: DefKind) -> bool {
1231+
fn should_encode_constness(def_kind: DefKind, is_coroutine: bool) -> bool {
12321232
match def_kind {
1233+
DefKind::Closure => !is_coroutine,
12331234
DefKind::Fn
12341235
| DefKind::AssocFn
1235-
| DefKind::Closure
12361236
| DefKind::Impl { of_trait: true }
12371237
| DefKind::Variant
12381238
| DefKind::Ctor(..) => true,
@@ -1345,12 +1345,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13451345
for local_id in tcx.iter_local_def_id() {
13461346
let def_id = local_id.to_def_id();
13471347
let def_kind = tcx.def_kind(local_id);
1348+
let is_coroutine = def_kind == DefKind::Closure && tcx.is_coroutine(def_id);
13481349
self.tables.def_kind.set_some(def_id.index, def_kind);
13491350
if should_encode_span(def_kind) {
13501351
let def_span = tcx.def_span(local_id);
13511352
record!(self.tables.def_span[def_id] <- def_span);
13521353
}
1353-
if should_encode_attrs(def_kind) {
1354+
if should_encode_attrs(def_kind, is_coroutine) {
13541355
self.encode_attrs(local_id);
13551356
}
13561357
if should_encode_expn_that_defined(def_kind) {
@@ -1405,7 +1406,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14051406
if should_encode_type(tcx, local_id, def_kind) && !anon_const_without_hir {
14061407
record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
14071408
}
1408-
if should_encode_constness(def_kind) {
1409+
if should_encode_constness(def_kind, is_coroutine) {
14091410
self.tables.constness.set_some(def_id.index, self.tcx.constness(def_id));
14101411
}
14111412
if let DefKind::Fn | DefKind::AssocFn = def_kind {

compiler/rustc_middle/src/ty/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2467,10 +2467,16 @@ impl<'tcx> TyCtxt<'tcx> {
24672467

24682468
#[inline]
24692469
pub fn is_const_fn_raw(self, def_id: DefId) -> bool {
2470-
matches!(
2471-
self.def_kind(def_id),
2472-
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Closure
2473-
) && self.constness(def_id) == hir::Constness::Const
2470+
let def_kind = self.def_kind(def_id);
2471+
if def_kind == DefKind::Closure
2472+
&& !self.is_coroutine(def_id)
2473+
&& self.constness(def_id) == hir::Constness::Const
2474+
{
2475+
true
2476+
} else {
2477+
matches!(def_kind, DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..))
2478+
&& self.constness(def_id) == hir::Constness::Const
2479+
}
24742480
}
24752481

24762482
#[inline]

compiler/rustc_mir_build/src/build/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ fn construct_fn<'tcx>(
474474
};
475475

476476
let mut abi = fn_sig.abi;
477-
if let DefKind::Closure = tcx.def_kind(fn_def) {
477+
if let DefKind::Closure = tcx.def_kind(fn_def)
478+
&& !tcx.is_coroutine(fn_def.to_def_id())
479+
{
478480
// HACK(eddyb) Avoid having RustCall on closures,
479481
// as it adds unnecessary (and wrong) auto-tupling.
480482
abi = Abi::Rust;

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3232

3333
// This just reproduces the logic from Instance::requires_inline.
3434
match tcx.def_kind(def_id) {
35+
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => return false,
3536
DefKind::Ctor(..) | DefKind::Closure => return true,
3637
DefKind::Fn | DefKind::AssocFn => {}
3738
_ => return false,

compiler/rustc_mir_transform/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ fn mir_promoted(
323323
// Also this means promotion can rely on all const checks having been done.
324324

325325
let const_qualifs = match tcx.def_kind(def) {
326+
DefKind::Closure if tcx.is_coroutine(def.to_def_id()) => ConstQualifs::default(),
326327
DefKind::Fn | DefKind::AssocFn | DefKind::Closure
327328
if tcx.constness(def) == hir::Constness::Const
328329
|| tcx.is_const_default_method(def.to_def_id()) =>

0 commit comments

Comments
 (0)