Skip to content

Commit 0241c29

Browse files
committed
Put a DefId in AggregateKind.
1 parent f312650 commit 0241c29

File tree

10 files changed

+33
-17
lines changed

10 files changed

+33
-17
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26452645
operands,
26462646
) = rvalue
26472647
{
2648+
let def_id = def_id.expect_local();
26482649
for operand in operands {
26492650
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
26502651
continue;
@@ -2667,7 +2668,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26672668
// into a place then we should annotate the closure in
26682669
// case it ends up being assigned into the return place.
26692670
annotated_closure =
2670-
self.annotate_fn_sig(*def_id, substs.as_closure().sig());
2671+
self.annotate_fn_sig(def_id, substs.as_closure().sig());
26712672
debug!(
26722673
"annotate_argument_and_return_for_borrow: \
26732674
annotated_closure={:?} assigned_from_local={:?} \

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
817817
&& let AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) = **kind
818818
{
819819
debug!("move_spans: def_id={:?} places={:?}", def_id, places);
820+
let def_id = def_id.expect_local();
820821
if let Some((args_span, generator_kind, capture_kind_span, path_span)) =
821822
self.closure_span(def_id, moved_place, places)
822823
{
@@ -945,6 +946,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
945946
box AggregateKind::Generator(def_id, _, _) => (def_id, true),
946947
_ => continue,
947948
};
949+
let def_id = def_id.expect_local();
948950

949951
debug!(
950952
"borrow_spans: def_id={:?} is_generator={:?} places={:?}",

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12781278
// in order to populate our used_mut set.
12791279
match **aggregate_kind {
12801280
AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => {
1281+
let def_id = def_id.expect_local();
12811282
let BorrowCheckResult { used_mut_upvars, .. } =
12821283
self.infcx.tcx.mir_borrowck(def_id);
12831284
debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25362536
// clauses on the struct.
25372537
AggregateKind::Closure(def_id, substs)
25382538
| AggregateKind::Generator(def_id, substs, _) => {
2539-
(def_id.to_def_id(), self.prove_closure_bounds(tcx, def_id, substs, location))
2539+
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), substs, location))
25402540
}
25412541

25422542
AggregateKind::Array(_) | AggregateKind::Tuple => {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
453453

454454
Rvalue::Aggregate(kind, ..) => {
455455
if let AggregateKind::Generator(def_id, ..) = kind.as_ref()
456-
&& let Some(generator_kind @ hir::GeneratorKind::Async(..)) = self.tcx.generator_kind(def_id.to_def_id())
456+
&& let Some(generator_kind @ hir::GeneratorKind::Async(..)) = self.tcx.generator_kind(def_id)
457457
{
458458
self.check_op(ops::Generator(generator_kind));
459459
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,10 +2098,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
20982098
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
20992099
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
21002100
let substs = tcx.lift(substs).unwrap();
2101-
format!(
2102-
"[closure@{}]",
2103-
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
2104-
)
2101+
format!("[closure@{}]", tcx.def_path_str_with_substs(def_id, substs),)
21052102
} else {
21062103
let span = tcx.def_span(def_id);
21072104
format!(
@@ -2112,11 +2109,17 @@ impl<'tcx> Debug for Rvalue<'tcx> {
21122109
let mut struct_fmt = fmt.debug_struct(&name);
21132110

21142111
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
2115-
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
2112+
if let Some(def_id) = def_id.as_local()
2113+
&& let Some(upvars) = tcx.upvars_mentioned(def_id)
2114+
{
21162115
for (&var_id, place) in iter::zip(upvars.keys(), places) {
21172116
let var_name = tcx.hir().name(var_id);
21182117
struct_fmt.field(var_name.as_str(), place);
21192118
}
2119+
} else {
2120+
for (index, place) in places.iter().enumerate() {
2121+
struct_fmt.field(&format!("{index}"), place);
2122+
}
21202123
}
21212124

21222125
struct_fmt.finish()
@@ -2127,11 +2130,17 @@ impl<'tcx> Debug for Rvalue<'tcx> {
21272130
let mut struct_fmt = fmt.debug_struct(&name);
21282131

21292132
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
2130-
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
2133+
if let Some(def_id) = def_id.as_local()
2134+
&& let Some(upvars) = tcx.upvars_mentioned(def_id)
2135+
{
21312136
for (&var_id, place) in iter::zip(upvars.keys(), places) {
21322137
let var_name = tcx.hir().name(var_id);
21332138
struct_fmt.field(var_name.as_str(), place);
21342139
}
2140+
} else {
2141+
for (index, place) in places.iter().enumerate() {
2142+
struct_fmt.field(&format!("{index}"), place);
2143+
}
21352144
}
21362145

21372146
struct_fmt.finish()

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,8 @@ pub enum AggregateKind<'tcx> {
12031203
/// active field index would identity the field `c`
12041204
Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
12051205

1206-
// Note: We can use LocalDefId since closures and generators a deaggregated
1207-
// before codegen.
1208-
Closure(LocalDefId, SubstsRef<'tcx>),
1209-
Generator(LocalDefId, SubstsRef<'tcx>, hir::Movability),
1206+
Closure(DefId, SubstsRef<'tcx>),
1207+
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
12101208
}
12111209

12121210
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]

compiler/rustc_middle/src/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ impl<'tcx> Rvalue<'tcx> {
205205
AggregateKind::Adt(did, _, substs, _, _) => {
206206
tcx.bound_type_of(did).subst(tcx, substs)
207207
}
208-
AggregateKind::Closure(did, substs) => tcx.mk_closure(did.to_def_id(), substs),
208+
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
209209
AggregateKind::Generator(did, substs, movability) => {
210-
tcx.mk_generator(did.to_def_id(), substs, movability)
210+
tcx.mk_generator(did, substs, movability)
211211
}
212212
},
213213
Rvalue::ShallowInitBox(_, ty) => tcx.mk_box(ty),

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
439439
// We implicitly set the discriminant to 0. See
440440
// librustc_mir/transform/deaggregator.rs for details.
441441
let movability = movability.unwrap();
442-
Box::new(AggregateKind::Generator(closure_id, substs, movability))
442+
Box::new(AggregateKind::Generator(
443+
closure_id.to_def_id(),
444+
substs,
445+
movability,
446+
))
443447
}
444448
UpvarSubsts::Closure(substs) => {
445-
Box::new(AggregateKind::Closure(closure_id, substs))
449+
Box::new(AggregateKind::Closure(closure_id.to_def_id(), substs))
446450
}
447451
};
448452
block.and(Rvalue::Aggregate(result, operands))

compiler/rustc_mir_transform/src/check_unsafety.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
126126
}
127127
}
128128
&AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => {
129+
let def_id = def_id.expect_local();
129130
let UnsafetyCheckResult { violations, used_unsafe_blocks, .. } =
130131
self.tcx.unsafety_check_result(def_id);
131132
self.register_violations(violations, used_unsafe_blocks.iter().copied());

0 commit comments

Comments
 (0)