Skip to content

Commit f586ac9

Browse files
committed
Adjust Ids of path segments in visibility modifiers
Fixes rust-lang#55376
1 parent bcb05a0 commit f586ac9

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/librustc/hir/lowering.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3022,8 +3022,14 @@ impl<'a> LoweringContext<'a> {
30223022
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
30233023
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
30243024
let id = this.next_id();
3025+
let mut path = path.clone();
3026+
for seg in path.segments.iter_mut() {
3027+
if seg.id.is_some() {
3028+
seg.id = Some(this.next_id().node_id);
3029+
}
3030+
}
30253031
hir::VisibilityKind::Restricted {
3026-
path: path.clone(),
3032+
path,
30273033
id: id.node_id,
30283034
hir_id: id.hir_id,
30293035
}

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
217217
};
218218

219219
bug!("inconsistent DepNode for `{}`: \
220-
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}) {}",
220+
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
221221
node_str,
222222
self.definitions
223223
.def_path(self.current_dep_node_owner)

src/test/run-pass/issue-55376.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that paths in `pub(...)` don't fail HIR verification.
12+
13+
#![allow(unused_imports)]
14+
#![allow(dead_code)]
15+
16+
pub(self) use self::my_mod::Foo;
17+
18+
mod my_mod {
19+
pub(super) use self::Foo as Bar;
20+
pub(in super::my_mod) use self::Foo as Baz;
21+
22+
pub struct Foo;
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)