Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5fb27bca
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
5fb27bca
编写于
6月 20, 2021
作者:
D
Deadbeef
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for const_unstable before printing `const`
上级
9c495b30
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
44 deletion
+65
-44
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+17
-9
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/mod.rs
+17
-13
src/librustdoc/html/render/print_item.rs
src/librustdoc/html/render/print_item.rs
+27
-18
src/test/rustdoc/const-display.rs
src/test/rustdoc/const-display.rs
+4
-4
未找到文件。
src/librustdoc/html/format.rs
浏览文件 @
5fb27bca
...
...
@@ -9,6 +9,7 @@
use
std
::
fmt
;
use
std
::
iter
;
use
rustc_attr
::{
ConstStability
,
StabilityLevel
};
use
rustc_data_structures
::
captures
::
Captures
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_hir
as
hir
;
...
...
@@ -1253,15 +1254,6 @@ fn print_with_space(&self) -> &str {
}
}
impl
PrintWithSpace
for
hir
::
Constness
{
fn
print_with_space
(
&
self
)
->
&
str
{
match
self
{
hir
::
Constness
::
Const
=>
"const "
,
hir
::
Constness
::
NotConst
=>
""
,
}
}
}
impl
PrintWithSpace
for
hir
::
IsAsync
{
fn
print_with_space
(
&
self
)
->
&
str
{
match
self
{
...
...
@@ -1280,6 +1272,22 @@ fn print_with_space(&self) -> &str {
}
}
crate
fn
print_constness_with_space
(
c
:
&
hir
::
Constness
,
s
:
Option
<&
ConstStability
>
,
)
->
&
'static
str
{
match
(
c
,
s
)
{
// const stable or no stability attribute
(
hir
::
Constness
::
Const
,
Some
(
ConstStability
{
level
:
StabilityLevel
::
Stable
{
..
},
..
}),
)
|
(
hir
::
Constness
::
Const
,
None
)
=>
"const "
,
// const unstable or not const
(
hir
::
Constness
::
Const
,
_
)
|
(
hir
::
Constness
::
NotConst
,
_
)
=>
""
,
}
}
impl
clean
::
Import
{
crate
fn
print
<
'a
,
'tcx
:
'a
>
(
&
'a
self
,
...
...
src/librustdoc/html/render/mod.rs
浏览文件 @
5fb27bca
...
...
@@ -61,8 +61,8 @@
use
crate
::
formats
::{
AssocItemRender
,
Impl
,
RenderMode
};
use
crate
::
html
::
escape
::
Escape
;
use
crate
::
html
::
format
::{
href
,
print_abi_with_space
,
print_
default_space
,
print_generic_bounds
,
print_where_claus
e
,
Buffer
,
PrintWithSpace
,
href
,
print_abi_with_space
,
print_
constness_with_space
,
print_default_spac
e
,
print_generic_bounds
,
print_where_clause
,
Buffer
,
PrintWithSpace
,
};
use
crate
::
html
::
markdown
::{
Markdown
,
MarkdownHtml
,
MarkdownSummaryLine
};
...
...
@@ -833,16 +833,17 @@ fn render_stability_since_raw(
let
ver
=
ver
.filter
(|
inner
|
!
inner
.is_empty
());
match
(
ver
,
const_stability
)
{
// stable and const stable
(
Some
(
v
),
Some
(
ConstStability
{
level
:
StabilityLevel
::
Stable
{
since
},
..
}))
if
Some
(
since
.as_str
())
.as_deref
()
!=
containing_const_ver
=>
{
write!
(
w
,
"<span class=
\"
since
\"
title=
\"
Stable since Rust version {0}, const since {1}
\"
>{0} (const: {1})</span>"
,
v
,
since
.as_str
()
v
,
since
);
}
// stable and const unstable
(
Some
(
v
),
Some
(
ConstStability
{
level
:
StabilityLevel
::
Unstable
{
issue
,
..
},
feature
,
..
}),
...
...
@@ -863,6 +864,7 @@ fn render_stability_since_raw(
}
write!
(
w
,
")</span>"
);
}
// stable
(
Some
(
v
),
_
)
if
ver
!=
containing_ver
=>
{
write!
(
w
,
...
...
@@ -910,11 +912,13 @@ fn method(
}
};
let
vis
=
meth
.visibility
.print_with_space
(
meth
.def_id
,
cx
)
.to_string
();
let
constness
=
header
.constness
.print_with_space
();
let
constness
=
print_constness_with_space
(
&
header
.constness
,
meth
.const_stability
(
cx
.tcx
()));
let
asyncness
=
header
.asyncness
.print_with_space
();
let
unsafety
=
header
.unsafety
.print_with_space
();
let
defaultness
=
print_default_space
(
meth
.is_default
());
let
abi
=
print_abi_with_space
(
header
.abi
)
.to_string
();
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
let
generics_len
=
format!
(
"{:#}"
,
g
.print
(
cx
))
.len
();
let
mut
header_len
=
"fn "
.len
()
...
...
@@ -939,15 +943,15 @@ fn method(
w
.reserve
(
header_len
+
"<a href=
\"\"
class=
\"
fnname
\"
>{"
.len
()
+
"</a>"
.len
());
write!
(
w
,
"{
}{}{}{}{}{}{
}fn <a href=
\"
{href}
\"
class=
\"
fnname
\"
>{name}</a>
\
"{
indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi
}fn <a href=
\"
{href}
\"
class=
\"
fnname
\"
>{name}</a>
\
{generics}{decl}{notable_traits}{where_clause}"
,
indent_str
,
vis
,
constness
,
asyncness
,
unsafety
,
defaultness
,
abi
,
indent
=
indent
_str
,
vis
=
vis
,
constness
=
constness
,
asyncness
=
asyncness
,
unsafety
=
unsafety
,
defaultness
=
defaultness
,
abi
=
abi
,
href
=
href
,
name
=
name
,
generics
=
g
.print
(
cx
),
...
...
src/librustdoc/html/render/print_item.rs
浏览文件 @
5fb27bca
...
...
@@ -22,7 +22,9 @@
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
formats
::{
AssocItemRender
,
Impl
,
RenderMode
};
use
crate
::
html
::
escape
::
Escape
;
use
crate
::
html
::
format
::{
print_abi_with_space
,
print_where_clause
,
Buffer
,
PrintWithSpace
};
use
crate
::
html
::
format
::{
print_abi_with_space
,
print_constness_with_space
,
print_where_clause
,
Buffer
,
PrintWithSpace
,
};
use
crate
::
html
::
highlight
;
use
crate
::
html
::
layout
::
Page
;
use
crate
::
html
::
markdown
::
MarkdownSummaryLine
;
...
...
@@ -430,29 +432,36 @@ fn tag_html(class: &str, title: &str, contents: &str) -> String {
}
fn
item_function
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
f
:
&
clean
::
Function
)
{
let
header_len
=
format!
(
"{}{}{}{}{:#}fn {}{:#}"
,
it
.visibility
.print_with_space
(
it
.def_id
,
cx
),
f
.header.constness
.print_with_space
(),
f
.header.asyncness
.print_with_space
(),
f
.header.unsafety
.print_with_space
(),
print_abi_with_space
(
f
.header.abi
),
it
.name
.as_ref
()
.unwrap
(),
f
.generics
.print
(
cx
),
)
.len
();
let
vis
=
it
.visibility
.print_with_space
(
it
.def_id
,
cx
)
.to_string
();
let
constness
=
print_constness_with_space
(
&
f
.header.constness
,
it
.const_stability
(
cx
.tcx
()));
let
asyncness
=
f
.header.asyncness
.print_with_space
();
let
unsafety
=
f
.header.unsafety
.print_with_space
();
let
abi
=
print_abi_with_space
(
f
.header.abi
)
.to_string
();
let
name
=
it
.name
.as_ref
()
.unwrap
();
let
generics_len
=
format!
(
"{:#}"
,
f
.generics
.print
(
cx
))
.len
();
let
header_len
=
"fn "
.len
()
+
vis
.len
()
+
constness
.len
()
+
asyncness
.len
()
+
unsafety
.len
()
+
abi
.len
()
+
name
.as_str
()
.len
()
+
generics_len
;
w
.write_str
(
"<pre class=
\"
rust fn
\"
>"
);
render_attributes_in_pre
(
w
,
it
,
""
);
w
.reserve
(
header_len
);
write!
(
w
,
"{vis}{constness}{asyncness}{unsafety}{abi}fn
\
{name}{generics}{decl}{notable_traits}{where_clause}</pre>"
,
vis
=
it
.visibility
.print_with_space
(
it
.def_id
,
cx
)
,
constness
=
f
.header.constness
.print_with_space
()
,
asyncness
=
f
.header.asyncness
.print_with_space
()
,
unsafety
=
f
.header.unsafety
.print_with_space
()
,
abi
=
print_abi_with_space
(
f
.header.abi
)
,
name
=
it
.name
.as_ref
()
.unwrap
()
,
vis
=
vis
,
constness
=
constness
,
asyncness
=
asyncness
,
unsafety
=
unsafety
,
abi
=
abi
,
name
=
name
,
generics
=
f
.generics
.print
(
cx
),
where_clause
=
print_where_clause
(
&
f
.generics
,
cx
,
0
,
true
),
decl
=
f
.decl
.full_print
(
header_len
,
0
,
f
.header.asyncness
,
cx
),
...
...
src/test/rustdoc/const-display.rs
浏览文件 @
5fb27bca
...
...
@@ -7,11 +7,11 @@
#![feature(foo,
foo2)]
#![feature(staged_api)]
// @has 'foo/fn.foo.html' '//pre' 'pub
unsafe
fn foo() -> u32'
// @has 'foo/fn.foo.html' '//pre' 'pub fn foo() -> u32'
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
#[rustc_const_unstable(feature=
"foo"
,
issue
=
"none"
)]
pub
const
unsafe
fn
foo
()
->
u32
{
42
}
pub
const
fn
foo
()
->
u32
{
42
}
// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'
#[unstable(feature
=
"humans"
,
issue
=
"none"
)]
...
...
@@ -39,11 +39,11 @@ pub const fn bar2() -> u32 { 42 }
pub
struct
Foo
;
impl
Foo
{
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub
unsafe
fn gated() -> u32'
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub fn gated() -> u32'
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
#[rustc_const_unstable(feature=
"foo"
,
issue
=
"none"
)]
pub
const
unsafe
fn
gated
()
->
u32
{
42
}
pub
const
fn
gated
()
->
u32
{
42
}
// @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/code' 'pub const fn stable_impl() -> u32'
// @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录