Skip to content

Commit 9afcd77

Browse files
committed
don't pass extra state fo encode_struct_ctor
1 parent c716ad8 commit 9afcd77

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

src/librustc_metadata/encoder.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -452,38 +452,37 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
452452
}
453453
}
454454

455-
impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
456-
fn encode_info_for_struct_ctor(&mut self,
457-
name: Name,
458-
ctor_id: ast::NodeId,
459-
variant: ty::VariantDef<'tcx>,
460-
struct_id: NodeId) {
455+
impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
456+
fn encode_struct_ctor(&mut self,
457+
struct_def_id: DefId,
458+
struct_node_id: ast::NodeId,
459+
ctor_node_id: ast::NodeId) {
461460
let ecx = self.ecx();
462-
let ctor_def_id = ecx.tcx.map.local_def_id(ctor_id);
463-
464-
self.record(ctor_def_id, |this| {
465-
encode_def_id_and_key(ecx, this.rbml_w, ctor_def_id);
466-
encode_family(this.rbml_w, match variant.kind {
467-
ty::VariantKind::Struct => 'S',
468-
ty::VariantKind::Tuple => 's',
469-
ty::VariantKind::Unit => 'u',
470-
});
471-
this.encode_bounds_and_type_for_item(ctor_id);
472-
encode_name(this.rbml_w, name);
473-
this.encode_parent_item(ecx.tcx.map.local_def_id(struct_id));
461+
let def = ecx.tcx.lookup_adt_def(struct_def_id);
462+
let variant = def.struct_variant();
463+
let item = ecx.tcx.map.expect_item(struct_node_id);
464+
let ctor_def_id = ecx.tcx.map.local_def_id(ctor_node_id);
465+
encode_def_id_and_key(ecx, self.rbml_w, ctor_def_id);
466+
encode_family(self.rbml_w, match variant.kind {
467+
ty::VariantKind::Struct => 'S',
468+
ty::VariantKind::Tuple => 's',
469+
ty::VariantKind::Unit => 'u',
470+
});
471+
self.encode_bounds_and_type_for_item(ctor_node_id);
472+
encode_name(self.rbml_w, item.name);
473+
self.encode_parent_item(struct_def_id);
474474

475-
let stab = ecx.tcx.lookup_stability(ecx.tcx.map.local_def_id(ctor_id));
476-
let depr = ecx.tcx.lookup_deprecation(ecx.tcx.map.local_def_id(ctor_id));
477-
encode_stability(this.rbml_w, stab);
478-
encode_deprecation(this.rbml_w, depr);
475+
let stab = ecx.tcx.lookup_stability(ctor_def_id);
476+
let depr = ecx.tcx.lookup_deprecation(ctor_def_id);
477+
encode_stability(self.rbml_w, stab);
478+
encode_deprecation(self.rbml_w, depr);
479479

480-
// indicate that this is a tuple struct ctor, because
481-
// downstream users will normally want the tuple struct
482-
// definition, but without this there is no way for them
483-
// to tell that they actually have a ctor rather than a
484-
// normal function
485-
this.rbml_w.wr_tagged_bytes(tag_items_data_item_is_tuple_struct_ctor, &[]);
486-
});
480+
// indicate that this is a tuple struct ctor, because
481+
// downstream users will normally want the tuple struct
482+
// definition, but without this there is no way for them
483+
// to tell that they actually have a ctor rather than a
484+
// normal function
485+
self.rbml_w.wr_tagged_bytes(tag_items_data_item_is_tuple_struct_ctor, &[]);
487486
}
488487
}
489488

@@ -1073,7 +1072,7 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
10731072

10741073
fn encode_addl_struct_info(&mut self,
10751074
def_id: DefId,
1076-
struct_def_id: ast::NodeId,
1075+
struct_node_id: ast::NodeId,
10771076
item: &hir::Item) {
10781077
let ecx = self.ecx;
10791078
let def = ecx.tcx.lookup_adt_def(def_id);
@@ -1089,10 +1088,10 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
10891088
ty::VariantKind::Tuple | ty::VariantKind::Unit => {
10901089
// there is a value for structs like `struct
10911090
// Foo()` and `struct Foo`
1092-
self.encode_info_for_struct_ctor(item.name,
1093-
struct_def_id,
1094-
variant,
1095-
item.id);
1091+
let ctor_def_id = ecx.tcx.map.local_def_id(struct_node_id);
1092+
self.record(ctor_def_id, |this| this.encode_struct_ctor(def_id,
1093+
item.id,
1094+
struct_node_id));
10961095
}
10971096
}
10981097
}

0 commit comments

Comments
 (0)