Rollup merge of #101245 - GuillaumeGomez:remove-unneeded-where-whitespace, r=notriddle
Remove unneeded where whitespace
It fixes these two bugs:


It's a relic from a very old time (this commit: bfd01b7f40
).
You can test the result [here](https://rustdoc.crud.net/imperio/remove-unneeded-where-whitespace/lib2/struct.WhereWhitespace.html).
cc `````````@jsha`````````
r? `````````@notriddle`````````
This commit is contained in:
commit
21c8447d78
28 changed files with 114 additions and 67 deletions
|
@ -349,7 +349,6 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
let where_preds = comma_sep(where_predicates, false);
|
let where_preds = comma_sep(where_predicates, false);
|
||||||
let clause = if f.alternate() {
|
let clause = if f.alternate() {
|
||||||
if ending == Ending::Newline {
|
if ending == Ending::Newline {
|
||||||
// add a space so stripping <br> tags and breaking spaces still renders properly
|
|
||||||
format!(" where{where_preds},")
|
format!(" where{where_preds},")
|
||||||
} else {
|
} else {
|
||||||
format!(" where{where_preds}")
|
format!(" where{where_preds}")
|
||||||
|
@ -364,11 +363,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
if ending == Ending::Newline {
|
if ending == Ending::Newline {
|
||||||
let mut clause = " ".repeat(indent.saturating_sub(1));
|
let mut clause = " ".repeat(indent.saturating_sub(1));
|
||||||
// add a space so stripping <br> tags and breaking spaces still renders properly
|
write!(clause, "<span class=\"where fmt-newline\">where{where_preds},</span>")?;
|
||||||
write!(
|
|
||||||
clause,
|
|
||||||
" <span class=\"where fmt-newline\">where{where_preds}, </span>"
|
|
||||||
)?;
|
|
||||||
clause
|
clause
|
||||||
} else {
|
} else {
|
||||||
// insert a <br> tag after a single space but before multiple spaces at the start
|
// insert a <br> tag after a single space but before multiple spaces at the start
|
||||||
|
|
|
@ -1737,8 +1737,8 @@ pub(crate) fn render_impl_summary(
|
||||||
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
|
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
|
||||||
aliases: &[String],
|
aliases: &[String],
|
||||||
) {
|
) {
|
||||||
let id =
|
let inner_impl = i.inner_impl();
|
||||||
cx.derive_id(get_id_for_impl(&i.inner_impl().for_, i.inner_impl().trait_.as_ref(), cx));
|
let id = cx.derive_id(get_id_for_impl(&inner_impl.for_, inner_impl.trait_.as_ref(), cx));
|
||||||
let aliases = if aliases.is_empty() {
|
let aliases = if aliases.is_empty() {
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1750,9 +1750,9 @@ pub(crate) fn render_impl_summary(
|
||||||
write!(w, "<h3 class=\"code-header in-band\">");
|
write!(w, "<h3 class=\"code-header in-band\">");
|
||||||
|
|
||||||
if let Some(use_absolute) = use_absolute {
|
if let Some(use_absolute) = use_absolute {
|
||||||
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
|
write!(w, "{}", inner_impl.print(use_absolute, cx));
|
||||||
if show_def_docs {
|
if show_def_docs {
|
||||||
for it in &i.inner_impl().items {
|
for it in &inner_impl.items {
|
||||||
if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind {
|
if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind {
|
||||||
w.write_str("<span class=\"where fmt-newline\"> ");
|
w.write_str("<span class=\"where fmt-newline\"> ");
|
||||||
assoc_type(
|
assoc_type(
|
||||||
|
@ -1770,11 +1770,11 @@ pub(crate) fn render_impl_summary(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write!(w, "{}", i.inner_impl().print(false, cx));
|
write!(w, "{}", inner_impl.print(false, cx));
|
||||||
}
|
}
|
||||||
write!(w, "</h3>");
|
write!(w, "</h3>");
|
||||||
|
|
||||||
let is_trait = i.inner_impl().trait_.is_some();
|
let is_trait = inner_impl.trait_.is_some();
|
||||||
if is_trait {
|
if is_trait {
|
||||||
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
|
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
|
||||||
write!(w, "<span class=\"item-info\">{}</span>", portability);
|
write!(w, "<span class=\"item-info\">{}</span>", portability);
|
||||||
|
|
|
@ -143,3 +143,30 @@ pub struct LongItemInfo2;
|
||||||
/// Some docs.
|
/// Some docs.
|
||||||
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
|
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
|
||||||
impl SimpleTrait for LongItemInfo2 {}
|
impl SimpleTrait for LongItemInfo2 {}
|
||||||
|
|
||||||
|
pub struct WhereWhitespace<T>;
|
||||||
|
|
||||||
|
impl<T> WhereWhitespace<T> {
|
||||||
|
pub fn new<F>(f: F) -> Self
|
||||||
|
where
|
||||||
|
F: FnMut() -> i32,
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<K, T> Whitespace<&K> for WhereWhitespace<T>
|
||||||
|
where
|
||||||
|
K: std::fmt::Debug,
|
||||||
|
{
|
||||||
|
type Output = WhereWhitespace<T>;
|
||||||
|
fn index(&self, _key: &K) -> &Self::Output {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Whitespace<Idx>
|
||||||
|
where
|
||||||
|
Idx: ?Sized,
|
||||||
|
{
|
||||||
|
type Output;
|
||||||
|
fn index(&self, index: Idx) -> &Self::Output;
|
||||||
|
}
|
||||||
|
|
27
src/test/rustdoc-gui/where-whitespace.goml
Normal file
27
src/test/rustdoc-gui/where-whitespace.goml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// This test ensures that the where conditions are correctly displayed.
|
||||||
|
goto: file://|DOC_PATH|/lib2/trait.Whitespace.html
|
||||||
|
show-text: true
|
||||||
|
// First, we check in the trait definition if the where clause is "on its own" (not on the same
|
||||||
|
// line than "pub trait Whitespace<Idx>").
|
||||||
|
compare-elements-position-false: (".item-decl code", ".where.fmt-newline", ("y"))
|
||||||
|
// And that the code following it isn't on the same line either.
|
||||||
|
compare-elements-position-false: (".item-decl .fnname", ".where.fmt-newline", ("y"))
|
||||||
|
|
||||||
|
goto: file://|DOC_PATH|/lib2/struct.WhereWhitespace.html
|
||||||
|
// We make the screen a bit wider to ensure that the trait impl is on one line.
|
||||||
|
size: (915, 915)
|
||||||
|
|
||||||
|
compare-elements-position-false: ("#method\.new .fnname", "#method\.new .where.fmt-newline", ("y"))
|
||||||
|
// We ensure that both the trait name and the struct name are on the same line in
|
||||||
|
// "impl<K, T> Whitespace<&K> for WhereWhitespace<T>".
|
||||||
|
compare-elements-position: (
|
||||||
|
"#trait-implementations-list .impl h3 .trait",
|
||||||
|
"#trait-implementations-list .impl h3 .struct",
|
||||||
|
("y"),
|
||||||
|
)
|
||||||
|
// And we now check that the where condition isn't on the same line.
|
||||||
|
compare-elements-position-false: (
|
||||||
|
"#trait-implementations-list .impl h3 .trait",
|
||||||
|
"#trait-implementations-list .impl h3 .where.fmt-newline",
|
||||||
|
("y"),
|
||||||
|
)
|
|
@ -1,7 +1,5 @@
|
||||||
pub trait ScopeHandle<'scope> {}
|
pub trait ScopeHandle<'scope> {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @has issue_54705/struct.ScopeFutureContents.html
|
// @has issue_54705/struct.ScopeFutureContents.html
|
||||||
// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
|
// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
|
||||||
// "impl<'scope, S> Send for ScopeFutureContents<'scope, S>where S: Sync"
|
// "impl<'scope, S> Send for ScopeFutureContents<'scope, S>where S: Sync"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue