Skip to content

Commit 9d178e5

Browse files
committed
rustdoc: fix overflow-wrap for table layouts
For all table layouts, set overflow-wrap: break-word.
1 parent 74fbbef commit 9d178e5

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
@@ -675,7 +675,6 @@ nav.sub {
675675
margin: .5em 0;
676676
width: calc(100% - 2px);
677677
overflow-x: auto;
678-
overflow-wrap: normal;
679678
display: block;
680679
}
681680

@@ -862,6 +861,31 @@ h2.small-section-header > .anchor {
862861

863862
.block a.current.crate { font-weight: 500; }
864863

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

2043-
.docblock table code {
2044-
overflow-wrap: normal;
2045-
}
2046-
20472067
.sub-container {
20482068
flex-direction: column;
20492069
}

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)