Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2a28b699
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,发现更多精彩内容 >>
提交
2a28b699
编写于
2月 28, 2016
作者:
M
mitaa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor rustdocs attribute handling
上级
8f6e09a9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
85 addition
and
136 deletion
+85
-136
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+3
-17
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+54
-57
src/librustdoc/html/render.rs
src/librustdoc/html/render.rs
+9
-38
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+17
-22
src/librustdoc/passes.rs
src/librustdoc/passes.rs
+2
-2
未找到文件。
src/librustdoc/clean/inline.rs
浏览文件 @
2a28b699
...
...
@@ -26,7 +26,7 @@
use
core
::
DocContext
;
use
doctree
;
use
clean
;
use
clean
::{
self
,
Attributes
}
;
use
super
::{
Clean
,
ToSource
};
...
...
@@ -253,7 +253,7 @@ fn populate_impls(cx: &DocContext, tcx: &TyCtxt,
cstore
::
DlImpl
(
did
)
=>
build_impl
(
cx
,
tcx
,
did
,
impls
),
cstore
::
DlDef
(
Def
::
Mod
(
did
))
=>
{
// Don't recurse if this is a #[doc(hidden)] module
if
load_attrs
(
cx
,
tcx
,
did
)
.
iter
()
.any
(|
a
|
is_doc_hidden
(
a
)
)
{
if
load_attrs
(
cx
,
tcx
,
did
)
.
list_def
(
"doc"
)
.has_word
(
"hidden"
)
{
return
;
}
...
...
@@ -282,7 +282,7 @@ pub fn build_impl(cx: &DocContext,
if
let
Some
(
ref
t
)
=
associated_trait
{
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline
let
trait_attrs
=
load_attrs
(
cx
,
tcx
,
t
.def_id
);
if
trait_attrs
.
iter
()
.any
(|
a
|
is_doc_hidden
(
a
)
)
{
if
trait_attrs
.
list_def
(
"doc"
)
.has_word
(
"hidden"
)
{
return
}
}
...
...
@@ -422,20 +422,6 @@ pub fn build_impl(cx: &DocContext,
});
}
fn
is_doc_hidden
(
a
:
&
clean
::
Attribute
)
->
bool
{
match
*
a
{
clean
::
List
(
ref
name
,
ref
inner
)
if
*
name
==
"doc"
=>
{
inner
.iter
()
.any
(|
a
|
{
match
*
a
{
clean
::
Word
(
ref
s
)
=>
*
s
==
"hidden"
,
_
=>
false
,
}
})
}
_
=>
false
}
}
fn
build_module
(
cx
:
&
DocContext
,
tcx
:
&
TyCtxt
,
did
:
DefId
)
->
clean
::
Module
{
let
mut
items
=
Vec
::
new
();
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
2a28b699
...
...
@@ -258,7 +258,7 @@ pub struct Item {
pub
source
:
Span
,
/// Not everything has a name. E.g., impls
pub
name
:
Option
<
String
>
,
pub
attrs
:
Vec
<
Attribute
>
,
pub
attrs
:
Vec
<
Attribute
>
,
pub
inner
:
ItemEnum
,
pub
visibility
:
Option
<
Visibility
>
,
pub
def_id
:
DefId
,
...
...
@@ -267,49 +267,10 @@ pub struct Item {
}
impl
Item
{
/// Finds the `doc` attribute as a List and returns the list of attributes
/// nested inside.
pub
fn
doc_list
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
[
Attribute
]
>
{
for
attr
in
&
self
.attrs
{
match
*
attr
{
List
(
ref
x
,
ref
list
)
if
"doc"
==
*
x
=>
{
return
Some
(
list
);
}
_
=>
{}
}
}
return
None
;
}
/// Finds the `doc` attribute as a NameValue and returns the corresponding
/// value found.
pub
fn
doc_value
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
str
>
{
for
attr
in
&
self
.attrs
{
match
*
attr
{
NameValue
(
ref
x
,
ref
v
)
if
"doc"
==
*
x
=>
{
return
Some
(
v
);
}
_
=>
{}
}
}
return
None
;
}
pub
fn
is_hidden_from_doc
(
&
self
)
->
bool
{
match
self
.doc_list
()
{
Some
(
l
)
=>
{
for
innerattr
in
l
{
match
*
innerattr
{
Word
(
ref
s
)
if
"hidden"
==
*
s
=>
{
return
true
}
_
=>
(),
}
}
},
None
=>
()
}
return
false
;
self
.attrs
.value
(
"doc"
)
}
pub
fn
is_mod
(
&
self
)
->
bool
{
...
...
@@ -438,10 +399,54 @@ fn clean(&self, cx: &DocContext) -> Item {
}
}
pub
trait
Attributes
{
fn
has_word
(
&
self
,
&
str
)
->
bool
;
fn
value
<
'a
>
(
&
'a
self
,
&
str
)
->
Option
<&
'a
str
>
;
fn
list_def
<
'a
>
(
&
'a
self
,
&
str
)
->
&
'a
[
Attribute
];
}
impl
Attributes
for
[
Attribute
]
{
/// Returns whether the attribute list contains a specific `Word`
fn
has_word
(
&
self
,
word
:
&
str
)
->
bool
{
for
attr
in
self
{
if
let
Word
(
ref
w
)
=
*
attr
{
if
word
==
*
w
{
return
true
;
}
}
}
false
}
/// Finds an attribute as NameValue and returns the corresponding value found.
fn
value
<
'a
>
(
&
'a
self
,
name
:
&
str
)
->
Option
<&
'a
str
>
{
for
attr
in
self
{
if
let
NameValue
(
ref
x
,
ref
v
)
=
*
attr
{
if
name
==
*
x
{
return
Some
(
v
);
}
}
}
None
}
/// Finds an attribute as List and returns the list of attributes nested inside.
fn
list_def
<
'a
>
(
&
'a
self
,
name
:
&
str
)
->
&
'a
[
Attribute
]
{
for
attr
in
self
{
if
let
List
(
ref
x
,
ref
list
)
=
*
attr
{
if
name
==
*
x
{
return
&
list
[
..
];
}
}
}
&
[]
}
}
#[derive(Clone,
RustcEncodable,
RustcDecodable,
PartialEq,
Debug)]
pub
enum
Attribute
{
Word
(
String
),
List
(
String
,
Vec
<
Attribute
>
),
List
(
String
,
Vec
<
Attribute
>
),
NameValue
(
String
,
String
)
}
...
...
@@ -1513,24 +1518,16 @@ fn from_str(s: &str) -> Option<PrimitiveType> {
}
fn
find
(
attrs
:
&
[
Attribute
])
->
Option
<
PrimitiveType
>
{
for
attr
in
attrs
{
let
list
=
match
*
attr
{
List
(
ref
k
,
ref
l
)
if
*
k
==
"doc"
=>
l
,
_
=>
continue
,
};
for
sub_attr
in
list
{
let
value
=
match
*
sub_attr
{
NameValue
(
ref
k
,
ref
v
)
if
*
k
==
"primitive"
=>
v
,
_
=>
continue
,
};
match
PrimitiveType
::
from_str
(
value
)
{
Some
(
p
)
=>
return
Some
(
p
),
None
=>
{}
for
attr
in
attrs
.list_def
(
"doc"
)
{
if
let
NameValue
(
ref
k
,
ref
v
)
=
*
attr
{
if
"primitive"
==
*
k
{
if
let
ret
@
Some
(
..
)
=
PrimitiveType
::
from_str
(
v
)
{
return
ret
;
}
}
}
}
return
None
None
}
pub
fn
to_string
(
&
self
)
->
&
'static
str
{
...
...
src/librustdoc/html/render.rs
浏览文件 @
2a28b699
...
...
@@ -62,7 +62,7 @@
use
rustc
::
session
::
config
::
get_unstable_features_setting
;
use
rustc_front
::
hir
;
use
clean
::{
self
,
SelfTy
};
use
clean
::{
self
,
SelfTy
,
Attributes
};
use
doctree
;
use
fold
::
DocFolder
;
use
html
::
escape
::
Escape
;
...
...
@@ -432,8 +432,7 @@ pub fn run(mut krate: clean::Crate,
// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML
let
default
:
&
[
_
]
=
&
[];
if
let
Some
(
attrs
)
=
krate
.module
.as_ref
()
.map
(|
m
|
m
.doc_list
()
.unwrap_or
(
default
))
{
if
let
Some
(
attrs
)
=
krate
.module
.as_ref
()
.map
(|
m
|
m
.attrs
.list_def
(
"doc"
))
{
for
attr
in
attrs
{
match
*
attr
{
clean
::
NameValue
(
ref
x
,
ref
s
)
...
...
@@ -833,28 +832,13 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
// Failing that, see if there's an attribute specifying where to find this
// external crate
for
attr
in
&
e
.attrs
{
match
*
attr
{
clean
::
List
(
ref
x
,
ref
list
)
if
"doc"
==
*
x
=>
{
for
attr
in
list
{
match
*
attr
{
clean
::
NameValue
(
ref
x
,
ref
s
)
if
"html_root_url"
==
*
x
=>
{
if
s
.ends_with
(
"/"
)
{
return
Remote
(
s
.to_string
());
}
return
Remote
(
format!
(
"{}/"
,
s
));
}
_
=>
{}
}
}
}
_
=>
{}
e
.attrs
.list_def
(
"doc"
)
.value
(
"html_root_url"
)
.map
(|
url
|
{
let
mut
url
=
url
.to_owned
();
if
!
url
.ends_with
(
"/"
)
{
url
.push
(
'/'
)
}
}
// Well, at least we tried.
return
Unknown
;
Remote
(
url
)
})
.unwrap_or
(
Unknown
)
// Well, at least we tried.
}
impl
<
'a
>
DocFolder
for
SourceCollector
<
'a
>
{
...
...
@@ -1153,19 +1137,6 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// implementations elsewhere
let
ret
=
self
.fold_item_recur
(
item
)
.and_then
(|
item
|
{
if
let
clean
::
Item
{
attrs
,
inner
:
clean
::
ImplItem
(
i
),
..
}
=
item
{
// extract relevant documentation for this impl
let
dox
=
match
attrs
.into_iter
()
.find
(|
a
|
{
match
*
a
{
clean
::
NameValue
(
ref
x
,
_
)
if
"doc"
==
*
x
=>
{
true
}
_
=>
false
}
})
{
Some
(
clean
::
NameValue
(
_
,
dox
))
=>
Some
(
dox
),
Some
(
..
)
|
None
=>
None
,
};
// Figure out the id of this impl. This may map to a
// primitive rather than always to a struct/enum.
let
did
=
match
i
.for_
{
...
...
@@ -1189,7 +1160,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
if
let
Some
(
did
)
=
did
{
self
.impls
.entry
(
did
)
.or_insert
(
vec!
[])
.push
(
Impl
{
impl_
:
i
,
dox
:
dox
,
dox
:
attrs
.value
(
"doc"
)
.map
(|
s
|
s
.to_owned
())
,
stability
:
item
.stability
.clone
(),
});
}
...
...
src/librustdoc/lib.rs
浏览文件 @
2a28b699
...
...
@@ -94,6 +94,8 @@ pub mod html {
pub
mod
test
;
mod
flock
;
use
clean
::
Attributes
;
type
Pass
=
(
&
'static
str
,
// name
fn
(
clean
::
Crate
)
->
plugins
::
PluginResult
,
// fn
&
'static
str
);
// description
...
...
@@ -379,32 +381,25 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
// Process all of the crate attributes, extracting plugin metadata along
// with the passes which we are supposed to run.
match
krate
.module
.as_ref
()
.unwrap
()
.doc_list
()
{
Some
(
nested
)
=>
{
for
inner
in
nested
{
match
*
inner
{
clean
::
Word
(
ref
x
)
if
"no_default_passes"
==
*
x
=>
{
default_passes
=
false
;
}
clean
::
NameValue
(
ref
x
,
ref
value
)
if
"passes"
==
*
x
=>
{
for
pass
in
value
.split_whitespace
()
{
passes
.push
(
pass
.to_string
());
}
}
clean
::
NameValue
(
ref
x
,
ref
value
)
if
"plugins"
==
*
x
=>
{
for
p
in
value
.split_whitespace
()
{
plugins
.push
(
p
.to_string
());
}
}
_
=>
{}
for
attr
in
krate
.module
.as_ref
()
.unwrap
()
.attrs
.list_def
(
"doc"
)
{
match
*
attr
{
clean
::
Word
(
ref
w
)
if
"no_default_passes"
==
*
w
=>
{
default_passes
=
false
;
},
clean
::
NameValue
(
ref
name
,
ref
value
)
=>
{
let
sink
=
match
&
name
[
..
]
{
"passes"
=>
&
mut
passes
,
"plugins"
=>
&
mut
plugins
,
_
=>
continue
,
};
for
p
in
value
.split_whitespace
()
{
sink
.push
(
p
.to_string
());
}
}
_
=>
(),
}
None
=>
{}
}
if
default_passes
{
for
name
in
DEFAULT_PASSES
.iter
()
.rev
()
{
passes
.insert
(
0
,
name
.to_string
());
...
...
src/librustdoc/passes.rs
浏览文件 @
2a28b699
...
...
@@ -16,7 +16,7 @@
use
std
::
usize
;
use
rustc_front
::
hir
;
use
clean
;
use
clean
::{
self
,
Attributes
}
;
use
clean
::
Item
;
use
plugins
;
use
fold
;
...
...
@@ -33,7 +33,7 @@ struct Stripper<'a> {
}
impl
<
'a
>
fold
::
DocFolder
for
Stripper
<
'a
>
{
fn
fold_item
(
&
mut
self
,
i
:
Item
)
->
Option
<
Item
>
{
if
i
.
is_hidden_from_doc
(
)
{
if
i
.
attrs
.list_def
(
"doc"
)
.has_word
(
"hidden"
)
{
debug!
(
"found one in strip_hidden; removing"
);
self
.stripped
.insert
(
i
.def_id
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录