diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index a7ffd8a9aea14..e608ad05b17da 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -925,6 +925,9 @@ body.blur > :not(#help) {
padding: 0 20px 20px 17px;;
}
+.item-info .stab {
+ display: table;
+}
.stab {
border-width: 1px;
border-style: solid;
diff --git a/src/test/rustdoc-gui/item-info-width.goml b/src/test/rustdoc-gui/item-info-width.goml
new file mode 100644
index 0000000000000..44b79e60912c6
--- /dev/null
+++ b/src/test/rustdoc-gui/item-info-width.goml
@@ -0,0 +1,7 @@
+// This test ensures that the item information don't take 100% of the width if unnecessary.
+goto: file://|DOC_PATH|/lib2/struct.Foo.html
+// We set a fixed size so there is no chance of "random" resize.
+size: (1100, 800)
+// We check that ".item-info" is bigger than its content.
+assert-css: (".item-info", {"width": "807px"})
+assert-css: (".item-info .stab", {"width": "343px"})
diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs
index 0466909479b67..cd00348cad3d1 100644
--- a/src/test/rustdoc-gui/src/lib2/lib.rs
+++ b/src/test/rustdoc-gui/src/lib2/lib.rs
@@ -1,5 +1,7 @@
// ignore-tidy-linelength
+#![feature(doc_cfg)]
+
pub mod module {
pub mod sub_module {
pub mod sub_sub_module {
@@ -14,6 +16,7 @@ pub fn foobar() {}
pub type Alias = u32;
+#[doc(cfg(feature = "foo-method"))]
pub struct Foo {
pub x: Alias,
}