Skip to content

Commit eedaba9

Browse files
committed
Don't generate a new NodeId for universal impl Trait
1 parent 4df69cb commit eedaba9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/librustc/hir/lowering.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ impl<'a> LoweringContext<'a> {
11391139
}
11401140
hir::TyTraitObject(bounds, lifetime_bound)
11411141
}
1142-
TyKind::ImplTrait(exist_ty_node_id, ref bounds) => {
1142+
TyKind::ImplTrait(def_node_id, ref bounds) => {
11431143
let span = t.span;
11441144
match itctx {
11451145
ImplTraitContext::Existential(fn_def_id, _, _) => {
@@ -1159,27 +1159,27 @@ impl<'a> LoweringContext<'a> {
11591159
.definitions()
11601160
.create_def_with_parent(
11611161
fn_def_id.index,
1162-
exist_ty_node_id,
1162+
def_node_id,
11631163
DefPathData::ExistentialImplTrait,
11641164
DefIndexAddressSpace::High,
11651165
Mark::root(),
11661166
exist_ty_span,
11671167
);
11681168

11691169
// the `t` is just for printing debug messages
1170-
self.allocate_hir_id_counter(exist_ty_node_id, t);
1170+
self.allocate_hir_id_counter(def_node_id, t);
11711171

1172-
let hir_bounds = self.with_hir_id_owner(exist_ty_node_id, |lctx| {
1172+
let hir_bounds = self.with_hir_id_owner(def_node_id, |lctx| {
11731173
lctx.lower_bounds(bounds, itctx)
11741174
});
11751175

11761176
let (path_params, params) = self.generics_from_impl_trait_bounds(
1177-
exist_ty_node_id,
1177+
def_node_id,
11781178
exist_ty_def_index,
11791179
&hir_bounds,
11801180
);
11811181

1182-
self.with_hir_id_owner(exist_ty_node_id, |lctx| {
1182+
self.with_hir_id_owner(def_node_id, |lctx| {
11831183
let exist_ty_item_kind = hir::ItemExistential(hir::ExistTy {
11841184
generics: hir::Generics {
11851185
params,
@@ -1192,7 +1192,7 @@ impl<'a> LoweringContext<'a> {
11921192
bounds: hir_bounds,
11931193
impl_trait_fn: Some(fn_def_id),
11941194
});
1195-
let exist_ty_id = lctx.lower_node_id(exist_ty_node_id);
1195+
let exist_ty_id = lctx.lower_node_id(def_node_id);
11961196
// Generate an `existential type Foo: Trait;` declaration
11971197
trace!("creating existential type with id {:#?}", exist_ty_id);
11981198
// Set the name to `impl Bound1 + Bound2`
@@ -1225,8 +1225,7 @@ impl<'a> LoweringContext<'a> {
12251225
})
12261226
}
12271227
ImplTraitContext::Universal(def_id, in_band_ty_params) => {
1228-
let def_node_id = self.next_id().node_id;
1229-
1228+
self.lower_node_id(def_node_id);
12301229
// Add a definition for the in-band TyParam
12311230
let def_index = self.resolver.definitions().create_def_with_parent(
12321231
def_id.index,

src/librustc/hir/map/collector.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,27 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
221221
// Make sure that the DepNode of some node coincides with the HirId
222222
// owner of that node.
223223
if cfg!(debug_assertions) {
224-
let hir_id_owner = self.definitions.node_to_hir_id(id).owner;
224+
let hir_id = self.definitions.node_to_hir_id(id);
225225

226-
if hir_id_owner != self.current_dep_node_owner {
226+
if hir_id.owner != self.current_dep_node_owner {
227227
let node_str = match self.definitions.opt_def_index(id) {
228228
Some(def_index) => {
229229
self.definitions.def_path(def_index).to_string_no_crate()
230230
}
231231
None => format!("{:?}", node)
232232
};
233233

234+
if hir_id == ::hir::DUMMY_HIR_ID {
235+
println!("Maybe you forgot to lower the node id {:?}?", id);
236+
}
237+
234238
bug!("inconsistent DepNode for `{}`: \
235239
current_dep_node_owner={}, hir_id.owner={}",
236240
node_str,
237241
self.definitions
238242
.def_path(self.current_dep_node_owner)
239243
.to_string_no_crate(),
240-
self.definitions.def_path(hir_id_owner).to_string_no_crate())
244+
self.definitions.def_path(hir_id.owner).to_string_no_crate())
241245
}
242246
}
243247

0 commit comments

Comments
 (0)