Skip to content

Commit 26e9357

Browse files
authored
Rollup merge of #93139 - jsha:fix-wrapped-names, r=Nemo157
rustdoc: fix overflow-wrap for table layouts For all table layouts, set overflow-wrap: break-word. Fixes #93135 Demo: https://rustdoc.crud.net/jsha/fix-wrapped-names/std/intrinsics/index.html#functions (Compare vs https://doc.rust-lang.org/nightly/std/intrinsics/index.html - you may have to make your browser narrower to see the effect) r? `@Nemo157`
2 parents 081d65f + 9d178e5 commit 26e9357

File tree

3 files changed

+54
-19
lines changed

3 files changed

+54
-19
lines changed

src/librustdoc/html/static/css/rustdoc.css

+25-5
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ nav.sub {
671671
margin: .5em 0;
672672
width: calc(100% - 2px);
673673
overflow-x: auto;
674-
overflow-wrap: normal;
675674
display: block;
676675
}
677676

@@ -858,6 +857,31 @@ h2.small-section-header > .anchor {
858857

859858
.block a.current.crate { font-weight: 500; }
860859

860+
/* In most contexts we use `overflow-wrap: anywhere` to ensure that we can wrap
861+
as much as needed on mobile (see
862+
src/test/rustdoc-gui/type-declaration-overflow.goml for an example of why
863+
this matters). The `anywhere` value means:
864+
865+
"Soft wrap opportunities introduced by the word break are considered when
866+
calculating min-content intrinsic sizes."
867+
868+
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap#values
869+
870+
For table layouts, that becomes a problem: the browser tries to make each
871+
column as narrow as possible, and `overflow-wrap: anywhere` means it can do
872+
so by breaking words - even if some other column could be shrunk without
873+
breaking words! This shows up, for instance, in the `Structs` / `Modules` /
874+
`Functions` (etcetera) sections of a module page, and when a docblock
875+
contains a table.
876+
877+
So, for table layouts, override the default with break-word, which does
878+
_not_ affect min-content intrinsic sizes.
879+
*/
880+
table,
881+
.item-table {
882+
overflow-wrap: break-word;
883+
}
884+
861885
.item-table {
862886
display: table;
863887
}
@@ -2058,10 +2082,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
20582082
overflow-wrap: anywhere;
20592083
}
20602084

2061-
.docblock table code {
2062-
overflow-wrap: normal;
2063-
}
2064-
20652085
.sub-container {
20662086
flex-direction: column;
20672087
}

src/test/rustdoc-gui/src/lib2/lib.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impl Trait for Foo {
3939
const Y: u32 = 0;
4040
}
4141

42-
4342
impl implementors::Whatever for Foo {
4443
type Foo = u32;
4544
}
@@ -58,8 +57,10 @@ pub mod sub_mod {
5857
pub mod long_trait {
5958
use std::ops::DerefMut;
6059

61-
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut<Target = u32>
62-
+ From<u128> + Send + Sync + AsRef<str> + 'static {}
60+
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem:
61+
DerefMut<Target = u32> + From<u128> + Send + Sync + AsRef<str> + 'static
62+
{
63+
}
6364
}
6465

6566
pub mod long_table {
@@ -88,18 +89,28 @@ pub mod summary_table {
8889
}
8990

9091
pub mod too_long {
91-
pub type ReallyLongTypeNameLongLongLong = Option<unsafe extern "C" fn(a: *const u8, b: *const u8) -> *const u8>;
92-
93-
pub const ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong: u32 = 0;
94-
95-
pub struct SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName {
96-
pub a: u32,
97-
}
92+
pub type ReallyLongTypeNameLongLongLong =
93+
Option<unsafe extern "C" fn(a: *const u8, b: *const u8) -> *const u8>;
94+
95+
pub const ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong: u32 = 0;
96+
97+
/// This also has a really long doccomment. Lorem ipsum dolor sit amet,
98+
/// consectetur adipiscing elit. Suspendisse id nibh malesuada, hendrerit
99+
/// massa vel, tincidunt est. Nulla interdum, sem ac efficitur ornare, arcu
100+
/// nunc dignissim nibh, at rutrum diam augue ac mauris. Fusce tincidunt et
101+
/// ligula sed viverra. Aenean sed facilisis dui, non volutpat felis. In
102+
/// vitae est dui. Donec felis nibh, blandit at nibh eu, tempor suscipit
103+
/// nisl. Vestibulum ornare porta libero, eu faucibus purus iaculis ut. Ut
104+
/// quis tincidunt nunc, in mollis purus. Nulla sed interdum quam. Nunc
105+
/// vitae cursus ex.
106+
pub struct SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName {
107+
pub a: u32,
108+
}
98109

99-
impl SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName {
100-
/// ```
101-
/// let x = SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName { a: 0 };
102-
/// ```
110+
impl SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName {
111+
/// ```
112+
/// let x = SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName { a: 0 };
113+
/// ```
103114
pub fn foo(&self) {}
104115
}
105116
}

src/test/rustdoc-gui/type-declation-overflow.goml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ assert-property: ("body", {"scrollWidth": "1100"})
77
// However, since there is overflow in the type declaration, its scroll width is bigger.
88
assert-property: (".item-decl pre", {"scrollWidth": "1324"})
99

10+
// In the table-ish view on the module index, the name should not be wrapped more than necessary.
11+
goto: file://|DOC_PATH|/lib2/too_long/index.html
12+
assert-property: (".item-table .struct", {"offsetWidth": "684"})
13+
1014
// We now make the same check on type declaration...
1115
goto: file://|DOC_PATH|/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html
1216
assert-property: ("body", {"scrollWidth": "1100"})

0 commit comments

Comments
 (0)