From f586ac9ef9266f6e257c3ec41e126336a543025f Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 29 Oct 2018 21:06:27 +1300 Subject: [PATCH] Adjust Ids of path segments in visibility modifiers Fixes #55376 --- src/librustc/hir/lowering.rs | 8 +++++++- src/librustc/hir/map/collector.rs | 2 +- src/test/run-pass/issue-55376.rs | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/issue-55376.rs diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 9795c0cba6154..c3c65816b2615 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3022,8 +3022,14 @@ impl<'a> LoweringContext<'a> { hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => { let id = this.next_id(); + let mut path = path.clone(); + for seg in path.segments.iter_mut() { + if seg.id.is_some() { + seg.id = Some(this.next_id().node_id); + } + } hir::VisibilityKind::Restricted { - path: path.clone(), + path, id: id.node_id, hir_id: id.hir_id, } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 8c701d9e4188f..4fbcd83adb555 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -217,7 +217,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { }; bug!("inconsistent DepNode for `{}`: \ - current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}) {}", + current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}", node_str, self.definitions .def_path(self.current_dep_node_owner) diff --git a/src/test/run-pass/issue-55376.rs b/src/test/run-pass/issue-55376.rs new file mode 100644 index 0000000000000..9c7256fd26fed --- /dev/null +++ b/src/test/run-pass/issue-55376.rs @@ -0,0 +1,25 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Tests that paths in `pub(...)` don't fail HIR verification. + +#![allow(unused_imports)] +#![allow(dead_code)] + +pub(self) use self::my_mod::Foo; + +mod my_mod { + pub(super) use self::Foo as Bar; + pub(in super::my_mod) use self::Foo as Baz; + + pub struct Foo; +} + +fn main() {}