about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-10-30 18:55:34 +0800
committerGitHub <noreply@github.com>2018-10-30 18:55:34 +0800
commit8b523640a15def5e4301546e840498dc59e39866 (patch)
tree6599f921f16562255d578b8825f591e817b1765d
parented37d80c30ca33ff9fb6ba70584037bcd94bae25 (diff)
parentf586ac9ef9266f6e257c3ec41e126336a543025f (diff)
downloadrust-8b523640a15def5e4301546e840498dc59e39866.tar.gz
rust-8b523640a15def5e4301546e840498dc59e39866.zip
Rollup merge of #55487 - nrc:path-fix, r=petrochenkov
Adjust Ids of path segments in visibility modifiers

Fixes #55376 (nightly regression)

r? @petrochenkov
-rw-r--r--src/librustc/hir/lowering.rs8
-rw-r--r--src/librustc/hir/map/collector.rs2
-rw-r--r--src/test/run-pass/issue-55376.rs25
3 files changed, 33 insertions, 2 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 9795c0cba61..c3c65816b26 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 8c701d9e418..4fbcd83adb5 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 00000000000..9c7256fd26f
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}