Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c748551f
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c748551f
编写于
6月 19, 2022
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix invalid add of whitespace when there is where clause
上级
53792b9c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
14 deletion
+45
-14
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+4
-0
src/librustdoc/html/render/print_item.rs
src/librustdoc/html/render/print_item.rs
+41
-14
未找到文件。
src/librustdoc/html/format.rs
浏览文件 @
c748551f
...
...
@@ -146,6 +146,10 @@ pub(crate) fn is_for_html(&self) -> bool {
pub
(
crate
)
fn
reserve
(
&
mut
self
,
additional
:
usize
)
{
self
.buffer
.reserve
(
additional
)
}
pub
(
crate
)
fn
len
(
&
self
)
->
usize
{
self
.buffer
.len
()
}
}
fn
comma_sep
<
T
:
fmt
::
Display
>
(
...
...
src/librustdoc/html/render/print_item.rs
浏览文件 @
c748551f
...
...
@@ -62,6 +62,17 @@ struct ItemVars<'a> {
src_href
:
Option
<&
'a
str
>
,
}
/// Calls `print_where_clause` and returns `true` if a `where` clause was generated.
fn
print_where_clause_and_check
<
'a
,
'tcx
:
'a
>
(
buffer
:
&
mut
Buffer
,
gens
:
&
'a
clean
::
Generics
,
cx
:
&
'a
Context
<
'tcx
>
,
)
->
bool
{
let
len_before
=
buffer
.len
();
write!
(
buffer
,
"{}"
,
print_where_clause
(
gens
,
cx
,
0
,
true
));
len_before
!=
buffer
.len
()
}
pub
(
super
)
fn
print_item
(
cx
:
&
mut
Context
<
'_
>
,
item
:
&
clean
::
Item
,
...
...
@@ -1152,17 +1163,21 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
render_attributes_in_pre
(
w
,
it
,
""
);
write!
(
w
,
"{}enum {}{}
{}
"
,
"{}enum {}{}"
,
it
.visibility
.print_with_space
(
it
.item_id
,
cx
),
it
.name
.unwrap
(),
e
.generics
.print
(
cx
),
print_where_clause
(
&
e
.generics
,
cx
,
0
,
true
),
);
if
!
print_where_clause_and_check
(
w
,
&
e
.generics
,
cx
)
{
// If there wasn't a `where` clause, we add a whitespace.
w
.write_str
(
" "
);
}
let
variants_stripped
=
e
.has_stripped_entries
();
if
count_variants
==
0
&&
!
variants_stripped
{
w
.write_str
(
"
{}"
);
w
.write_str
(
"{}"
);
}
else
{
w
.write_str
(
"
{
\n
"
);
w
.write_str
(
"{
\n
"
);
let
toggle
=
should_hide_fields
(
count_variants
);
if
toggle
{
toggle_open
(
w
,
format_args!
(
"{} variants"
,
count_variants
));
...
...
@@ -1643,13 +1658,21 @@ fn render_union(
tab
:
&
str
,
cx
:
&
Context
<
'_
>
,
)
{
write!
(
w
,
"{}union {}"
,
it
.visibility
.print_with_space
(
it
.item_id
,
cx
),
it
.name
.unwrap
());
if
let
Some
(
g
)
=
g
{
write!
(
w
,
"{}"
,
g
.print
(
cx
));
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
true
));
write!
(
w
,
"{}union {}"
,
it
.visibility
.print_with_space
(
it
.item_id
,
cx
),
it
.name
.unwrap
(),);
let
where_displayed
=
g
.map
(|
g
|
{
write!
(
w
,
"{}"
,
g
.print
(
cx
));
print_where_clause_and_check
(
w
,
g
,
cx
)
})
.unwrap_or
(
false
);
// If there wasn't a `where` clause, we add a whitespace.
if
!
where_displayed
{
w
.write_str
(
" "
);
}
write!
(
w
,
"
{{
\n
{}"
,
tab
);
write!
(
w
,
"{{
\n
{}"
,
tab
);
let
count_fields
=
fields
.iter
()
.filter
(|
f
|
matches!
(
*
f
.kind
,
clean
::
StructFieldItem
(
..
)))
.count
();
let
toggle
=
should_hide_fields
(
count_fields
);
...
...
@@ -1701,10 +1724,14 @@ fn render_struct(
}
match
ty
{
CtorKind
::
Fictive
=>
{
if
let
Some
(
g
)
=
g
{
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
true
),)
let
where_diplayed
=
g
.map
(|
g
|
print_where_clause_and_check
(
w
,
g
,
cx
))
.unwrap_or
(
false
);
// If there wasn't a `where` clause, we add a whitespace.
if
!
where_diplayed
{
w
.write_str
(
" {"
);
}
else
{
w
.write_str
(
"{"
);
}
w
.write_str
(
" {"
);
let
count_fields
=
fields
.iter
()
.filter
(|
f
|
matches!
(
*
f
.kind
,
clean
::
StructFieldItem
(
..
)))
.count
();
let
has_visible_fields
=
count_fields
>
0
;
...
...
@@ -1759,7 +1786,7 @@ fn render_struct(
}
w
.write_str
(
")"
);
if
let
Some
(
g
)
=
g
{
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
false
)
,)
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
false
)
);
}
// We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
if
structhead
{
...
...
@@ -1769,7 +1796,7 @@ fn render_struct(
CtorKind
::
Const
=>
{
// Needed for PhantomData.
if
let
Some
(
g
)
=
g
{
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
false
)
,)
write!
(
w
,
"{}"
,
print_where_clause
(
g
,
cx
,
0
,
false
)
);
}
w
.write_str
(
";"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录