diff --git a/tests/rustdoc-html/doc-cfg/impl-foreign-type.rs b/tests/rustdoc-html/doc-cfg/impl-foreign-type.rs
new file mode 100644
index 000000000000..e4697c5b8dbe
--- /dev/null
+++ b/tests/rustdoc-html/doc-cfg/impl-foreign-type.rs
@@ -0,0 +1,15 @@
+// This test ensures that the `doc_cfg` feature works on foreign types impl.
+// Regression test for .
+
+// ignore-tidy-linelength
+
+#![feature(doc_cfg)]
+#![crate_name = "foo"]
+
+//@has 'foo/trait.Blob.html'
+//@has - '//*[@id="impl-Blob-for-Box%3CR%3E"]//*[@class="stab portability"]' 'Available on non-crate feature alloc only.'
+
+pub trait Blob {}
+
+#[cfg(not(feature = "alloc"))]
+impl Blob for std::boxed::Box {}