diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 327be40a58f2f..2b634334ed404 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2043,8 +2043,13 @@ impl Clean<Visibility> for hir::Visibility {
             hir::VisibilityKind::Crate(_) => Visibility::Crate,
             hir::VisibilityKind::Restricted { ref path, .. } => {
                 let path = path.clean(cx);
-                let did = register_res(cx, path.res);
-                Visibility::Restricted(did, path)
+                if let Res::Err = path.res {
+                    // Ugly fix to prevent ICE.
+                    Visibility::Inherited
+                } else {
+                    let did = register_res(cx, path.res);
+                    Visibility::Restricted(did, path)
+                }
             }
         }
     }
diff --git a/src/test/rustdoc-ui/impl-fn-macro-item-ice.rs b/src/test/rustdoc-ui/impl-fn-macro-item-ice.rs
new file mode 100644
index 0000000000000..63075acd31a47
--- /dev/null
+++ b/src/test/rustdoc-ui/impl-fn-macro-item-ice.rs
@@ -0,0 +1,15 @@
+// build-pass
+
+macro_rules! perftools_inline {
+    ($($item:tt)*) => (
+        $($item)*
+    );
+}
+mod state {
+    pub struct RawFloatState;
+    impl RawFloatState {
+        perftools_inline! {
+            pub(super) fn new() {}
+        }
+    }
+}