Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7b590893
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
7b590893
编写于
3月 10, 2021
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split clean::Constant enum into a struct and an enum
上级
ee509337
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
46 addition
and
46 deletion
+46
-46
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+4
-1
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+10
-6
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+30
-37
src/librustdoc/html/render/print_item.rs
src/librustdoc/html/render/print_item.rs
+1
-1
src/librustdoc/json/conversions.rs
src/librustdoc/json/conversions.rs
+1
-1
未找到文件。
src/librustdoc/clean/inline.rs
浏览文件 @
7b590893
...
@@ -500,7 +500,10 @@ fn build_module(
...
@@ -500,7 +500,10 @@ fn build_module(
}
}
fn
build_const
(
cx
:
&
mut
DocContext
<
'_
>
,
def_id
:
DefId
)
->
clean
::
Constant
{
fn
build_const
(
cx
:
&
mut
DocContext
<
'_
>
,
def_id
:
DefId
)
->
clean
::
Constant
{
clean
::
Constant
::
Extern
{
type_
:
cx
.tcx
.type_of
(
def_id
)
.clean
(
cx
),
def_id
}
clean
::
Constant
{
type_
:
cx
.tcx
.type_of
(
def_id
)
.clean
(
cx
),
kind
:
clean
::
ConstantKind
::
Extern
{
def_id
},
}
}
}
fn
build_static
(
cx
:
&
mut
DocContext
<
'_
>
,
did
:
DefId
,
mutable
:
bool
)
->
clean
::
Static
{
fn
build_static
(
cx
:
&
mut
DocContext
<
'_
>
,
did
:
DefId
,
mutable
:
bool
)
->
clean
::
Static
{
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
7b590893
...
@@ -393,12 +393,12 @@ fn clean(&self, _: &mut DocContext<'_>) -> Lifetime {
...
@@ -393,12 +393,12 @@ fn clean(&self, _: &mut DocContext<'_>) -> Lifetime {
impl
Clean
<
Constant
>
for
hir
::
ConstArg
{
impl
Clean
<
Constant
>
for
hir
::
ConstArg
{
fn
clean
(
&
self
,
cx
:
&
mut
DocContext
<
'_
>
)
->
Constant
{
fn
clean
(
&
self
,
cx
:
&
mut
DocContext
<
'_
>
)
->
Constant
{
Constant
::
Anonymous
{
Constant
{
type_
:
cx
type_
:
cx
.tcx
.tcx
.type_of
(
cx
.tcx
.hir
()
.body_owner_def_id
(
self
.value.body
)
.to_def_id
())
.type_of
(
cx
.tcx
.hir
()
.body_owner_def_id
(
self
.value.body
)
.to_def_id
())
.clean
(
cx
),
.clean
(
cx
),
body
:
self
.value.body
,
kind
:
ConstantKind
::
Anonymous
{
body
:
self
.value.body
}
,
}
}
}
}
}
}
...
@@ -1744,7 +1744,10 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Type {
...
@@ -1744,7 +1744,10 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Type {
impl
<
'tcx
>
Clean
<
Constant
>
for
ty
::
Const
<
'tcx
>
{
impl
<
'tcx
>
Clean
<
Constant
>
for
ty
::
Const
<
'tcx
>
{
fn
clean
(
&
self
,
cx
:
&
mut
DocContext
<
'_
>
)
->
Constant
{
fn
clean
(
&
self
,
cx
:
&
mut
DocContext
<
'_
>
)
->
Constant
{
// FIXME: instead of storing the stringified expression, store `self` directly instead.
// FIXME: instead of storing the stringified expression, store `self` directly instead.
Constant
::
TyConst
{
type_
:
self
.ty
.clean
(
cx
),
expr
:
self
.to_string
()
}
Constant
{
type_
:
self
.ty
.clean
(
cx
),
kind
:
ConstantKind
::
TyConst
{
expr
:
self
.to_string
()
},
}
}
}
}
}
...
@@ -1945,9 +1948,10 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Vec<Item> {
...
@@ -1945,9 +1948,10 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Vec<Item> {
ItemKind
::
Static
(
ty
,
mutability
,
body_id
)
=>
{
ItemKind
::
Static
(
ty
,
mutability
,
body_id
)
=>
{
StaticItem
(
Static
{
type_
:
ty
.clean
(
cx
),
mutability
,
expr
:
Some
(
body_id
)
})
StaticItem
(
Static
{
type_
:
ty
.clean
(
cx
),
mutability
,
expr
:
Some
(
body_id
)
})
}
}
ItemKind
::
Const
(
ty
,
body_id
)
=>
{
ItemKind
::
Const
(
ty
,
body_id
)
=>
ConstantItem
(
Constant
{
ConstantItem
(
Constant
::
Local
{
type_
:
ty
.clean
(
cx
),
body
:
body_id
,
def_id
})
type_
:
ty
.clean
(
cx
),
}
kind
:
ConstantKind
::
Local
{
body
:
body_id
,
def_id
},
}),
ItemKind
::
OpaqueTy
(
ref
ty
)
=>
OpaqueTyItem
(
OpaqueTy
{
ItemKind
::
OpaqueTy
(
ref
ty
)
=>
OpaqueTyItem
(
OpaqueTy
{
bounds
:
ty
.bounds
.clean
(
cx
),
bounds
:
ty
.bounds
.clean
(
cx
),
generics
:
ty
.generics
.clean
(
cx
),
generics
:
ty
.generics
.clean
(
cx
),
...
...
src/librustdoc/clean/types.rs
浏览文件 @
7b590893
...
@@ -1987,67 +1987,60 @@ fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
...
@@ -1987,67 +1987,60 @@ fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
}
}
#[derive(Clone,
PartialEq,
Eq,
Hash,
Debug)]
#[derive(Clone,
PartialEq,
Eq,
Hash,
Debug)]
crate
enum
Constant
{
crate
struct
Constant
{
crate
type_
:
Type
,
crate
kind
:
ConstantKind
,
}
#[derive(Clone,
PartialEq,
Eq,
Hash,
Debug)]
crate
enum
ConstantKind
{
/// This is the wrapper around `ty::Const` for a non-local constant. Because it doesn't have a
/// This is the wrapper around `ty::Const` for a non-local constant. Because it doesn't have a
/// `BodyId`, we need to handle it on its own.
/// `BodyId`, we need to handle it on its own.
TyConst
{
type_
:
Type
,
expr
:
String
},
///
/// A constant (expression) that’s not an item or associated item. These are usually found
/// Note that `ty::Const` includes generic parameters, and may not always be uniquely identified
/// by a DefId. So this field must be different from `Extern`.
TyConst
{
expr
:
String
},
/// A constant (expression) that's not an item or associated item. These are usually found
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
/// used to define explicit discriminant values for enum variants.
/// used to define explicit discriminant values for enum variants.
Anonymous
{
type_
:
Type
,
body
:
BodyId
},
Anonymous
{
body
:
BodyId
},
/// A constant from a different crate.
/// A constant from a different crate.
Extern
{
type_
:
Type
,
def_id
:
DefId
},
Extern
{
def_id
:
DefId
},
///
const FOO: u32 = ...;
///
`const FOO: u32 = ...;`
Local
{
type_
:
Type
,
def_id
:
DefId
,
body
:
BodyId
},
Local
{
def_id
:
DefId
,
body
:
BodyId
},
}
}
impl
Constant
{
impl
Constant
{
crate
fn
expr
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
String
{
crate
fn
expr
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
String
{
match
self
{
match
self
.kind
{
Self
::
TyConst
{
expr
,
..
}
=>
expr
.clone
(),
ConstantKind
::
TyConst
{
ref
expr
}
=>
expr
.clone
(),
Self
::
Extern
{
def_id
,
..
}
=>
print_inlined_const
(
tcx
,
*
def_id
),
ConstantKind
::
Extern
{
def_id
}
=>
print_inlined_const
(
tcx
,
def_id
),
Self
::
Local
{
body
,
..
}
|
Self
::
Anonymous
{
body
,
..
}
=>
print_const_expr
(
tcx
,
*
body
),
ConstantKind
::
Local
{
body
,
..
}
|
ConstantKind
::
Anonymous
{
body
}
=>
{
print_const_expr
(
tcx
,
body
)
}
}
}
}
}
crate
fn
value
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Option
<
String
>
{
crate
fn
value
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Option
<
String
>
{
match
self
{
match
self
.kind
{
Self
::
TyConst
{
..
}
|
Self
::
Anonymous
{
..
}
=>
None
,
ConstantKind
::
TyConst
{
..
}
|
ConstantKind
::
Anonymous
{
..
}
=>
None
,
Self
::
Extern
{
def_id
,
..
}
|
Self
::
Local
{
def_id
,
..
}
=>
{
ConstantKind
::
Extern
{
def_id
}
|
ConstantKind
::
Local
{
def_id
,
..
}
=>
{
print_evaluated_const
(
tcx
,
*
def_id
)
print_evaluated_const
(
tcx
,
def_id
)
}
}
}
}
}
}
crate
fn
is_literal
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
bool
{
crate
fn
is_literal
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
bool
{
match
self
{
match
self
.kind
{
Self
::
TyConst
{
..
}
=>
false
,
ConstantKind
::
TyConst
{
..
}
=>
false
,
Self
::
Extern
{
def_id
,
..
}
=>
def_id
.as_local
()
.map_or
(
false
,
|
def_id
|
{
ConstantKind
::
Extern
{
def_id
}
=>
def_id
.as_local
()
.map_or
(
false
,
|
def_id
|
{
is_literal_expr
(
tcx
,
tcx
.hir
()
.local_def_id_to_hir_id
(
def_id
))
is_literal_expr
(
tcx
,
tcx
.hir
()
.local_def_id_to_hir_id
(
def_id
))
}),
}),
Self
::
Local
{
body
,
..
}
|
Self
::
Anonymous
{
body
,
..
}
=>
{
ConstantKind
::
Local
{
body
,
..
}
|
ConstantKind
::
Anonymous
{
body
}
=>
{
is_literal_expr
(
tcx
,
body
.hir_id
)
is_literal_expr
(
tcx
,
body
.hir_id
)
}
}
}
}
}
}
crate
fn
type_
(
&
self
)
->
&
Type
{
match
*
self
{
Self
::
TyConst
{
ref
type_
,
..
}
|
Self
::
Extern
{
ref
type_
,
..
}
|
Self
::
Local
{
ref
type_
,
..
}
|
Self
::
Anonymous
{
ref
type_
,
..
}
=>
type_
,
}
}
crate
fn
to_type
(
self
)
->
Type
{
match
self
{
Self
::
TyConst
{
type_
,
..
}
|
Self
::
Extern
{
type_
,
..
}
|
Self
::
Local
{
type_
,
..
}
|
Self
::
Anonymous
{
type_
,
..
}
=>
type_
,
}
}
}
}
#[derive(Clone,
Debug)]
#[derive(Clone,
Debug)]
...
...
src/librustdoc/html/render/print_item.rs
浏览文件 @
7b590893
...
@@ -982,7 +982,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
...
@@ -982,7 +982,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
"{vis}const {name}: {typ}"
,
"{vis}const {name}: {typ}"
,
vis
=
it
.visibility
.print_with_space
(
cx
.tcx
(),
it
.def_id
,
cx
.cache
()),
vis
=
it
.visibility
.print_with_space
(
cx
.tcx
(),
it
.def_id
,
cx
.cache
()),
name
=
it
.name
.as_ref
()
.unwrap
(),
name
=
it
.name
.as_ref
()
.unwrap
(),
typ
=
c
.type_
()
.print
(
cx
.cache
(),
cx
.tcx
()),
typ
=
c
.type_
.print
(
cx
.cache
(),
cx
.tcx
()),
);
);
let
value
=
c
.value
(
cx
.tcx
());
let
value
=
c
.value
(
cx
.tcx
());
...
...
src/librustdoc/json/conversions.rs
浏览文件 @
7b590893
...
@@ -142,7 +142,7 @@ fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
...
@@ -142,7 +142,7 @@ fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
let
expr
=
constant
.expr
(
tcx
);
let
expr
=
constant
.expr
(
tcx
);
let
value
=
constant
.value
(
tcx
);
let
value
=
constant
.value
(
tcx
);
let
is_literal
=
constant
.is_literal
(
tcx
);
let
is_literal
=
constant
.is_literal
(
tcx
);
Constant
{
type_
:
constant
.t
o_type
()
.into_tcx
(
tcx
),
expr
,
value
,
is_literal
}
Constant
{
type_
:
constant
.t
ype_
.into_tcx
(
tcx
),
expr
,
value
,
is_literal
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录