Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
acd4dc2d
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,发现更多精彩内容 >>
未验证
提交
acd4dc2d
编写于
6月 26, 2021
作者:
J
Justus K
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustdoc: Rename `expect_real` to `expect_def_id`, remove `Item::is_fake`
上级
43e1cdba
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
103 addition
and
105 deletion
+103
-105
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+18
-25
src/librustdoc/formats/cache.rs
src/librustdoc/formats/cache.rs
+6
-6
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+1
-1
src/librustdoc/html/render/context.rs
src/librustdoc/html/render/context.rs
+1
-1
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/mod.rs
+4
-4
src/librustdoc/html/render/print_item.rs
src/librustdoc/html/render/print_item.rs
+13
-13
src/librustdoc/json/mod.rs
src/librustdoc/json/mod.rs
+3
-3
src/librustdoc/passes/calculate_doc_coverage.rs
src/librustdoc/passes/calculate_doc_coverage.rs
+2
-2
src/librustdoc/passes/check_code_block_syntax.rs
src/librustdoc/passes/check_code_block_syntax.rs
+2
-2
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+40
-41
src/librustdoc/passes/collect_trait_impls.rs
src/librustdoc/passes/collect_trait_impls.rs
+7
-2
src/librustdoc/passes/doc_test_lints.rs
src/librustdoc/passes/doc_test_lints.rs
+5
-4
src/librustdoc/passes/stripper.rs
src/librustdoc/passes/stripper.rs
+1
-1
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
acd4dc2d
...
...
@@ -66,20 +66,22 @@ impl ItemId {
#[inline]
crate
fn
is_local
(
self
)
->
bool
{
match
self
{
ItemId
::
DefId
(
id
)
=>
id
.is_local
(),
_
=>
false
,
ItemId
::
Auto
{
for_
:
id
,
..
}
|
ItemId
::
Blanket
{
for_
:
id
,
..
}
|
ItemId
::
DefId
(
id
)
=>
id
.is_local
(),
ItemId
::
Primitive
(
krate
)
=>
krate
==
LOCAL_CRATE
,
}
}
#[inline]
#[track_caller]
crate
fn
expect_
real
(
self
)
->
rustc_hir
::
def_id
::
DefId
{
self
.as_
real
()
.unwrap_or_else
(||
panic!
(
"ItemId::expect_
real: `{:?}` isn't a real Item
Id"
,
self
))
crate
fn
expect_
def_id
(
self
)
->
DefId
{
self
.as_
def_id
()
.unwrap_or_else
(||
panic!
(
"ItemId::expect_
def_id: `{:?}` isn't a Def
Id"
,
self
))
}
#[inline]
crate
fn
as_
real
(
self
)
->
Option
<
DefId
>
{
crate
fn
as_
def_id
(
self
)
->
Option
<
DefId
>
{
match
self
{
ItemId
::
DefId
(
id
)
=>
Some
(
id
),
_
=>
None
,
...
...
@@ -89,9 +91,9 @@ impl ItemId {
#[inline]
crate
fn
krate
(
self
)
->
CrateNum
{
match
self
{
ItemId
::
DefId
(
id
)
=>
id
.krate
,
ItemId
::
Auto
{
trait_
,
..
}
=>
trait_
.krate
,
ItemId
::
Blanket
{
trait_
,
..
}
=>
trait_
.krate
,
ItemId
::
Auto
{
for_
:
id
,
..
}
|
ItemId
::
Blanket
{
for_
:
id
,
..
}
|
ItemId
::
DefId
(
id
)
=>
id
.krate
,
ItemId
::
Primitive
(
krate
)
=>
krate
,
}
}
...
...
@@ -100,9 +102,7 @@ impl ItemId {
crate
fn
index
(
self
)
->
Option
<
DefIndex
>
{
match
self
{
ItemId
::
DefId
(
id
)
=>
Some
(
id
.index
),
ItemId
::
Auto
{
trait_
,
..
}
=>
Some
(
trait_
.index
),
ItemId
::
Blanket
{
trait_
,
..
}
=>
Some
(
trait_
.index
),
ItemId
::
Primitive
(
..
)
=>
None
,
_
=>
None
,
}
}
}
...
...
@@ -354,19 +354,19 @@ fn to_remote(url: impl ToString) -> ExternalLocation {
impl
Item
{
crate
fn
stability
<
'tcx
>
(
&
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<&
'tcx
Stability
>
{
if
self
.is_fake
()
{
None
}
else
{
tcx
.lookup_stability
(
self
.def_id
.expect_real
())
}
self
.def_id
.as_def_id
()
.and_then
(|
did
|
tcx
.lookup_stability
(
did
))
}
crate
fn
const_stability
<
'tcx
>
(
&
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<&
'tcx
ConstStability
>
{
if
self
.is_fake
()
{
None
}
else
{
tcx
.lookup_const_stability
(
self
.def_id
.expect_real
())
}
self
.def_id
.as_def_id
()
.and_then
(|
did
|
tcx
.lookup_const_stability
(
did
))
}
crate
fn
deprecation
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Option
<
Deprecation
>
{
if
self
.is_fake
()
{
None
}
else
{
tcx
.lookup_deprecation
(
self
.def_id
.expect_real
())
}
self
.def_id
.as_def_id
()
.and_then
(|
did
|
tcx
.lookup_deprecation
(
did
))
}
crate
fn
inner_docs
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
bool
{
if
self
.is_fake
()
{
false
}
else
{
tcx
.get_attrs
(
self
.def_id
.expect_real
())
.inner_docs
()
}
self
.def_id
.as_def_id
()
.map
(|
did
|
tcx
.get_attrs
(
did
)
.inner_docs
())
.unwrap_or
(
false
)
}
crate
fn
span
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Span
{
...
...
@@ -378,10 +378,8 @@ impl Item {
kind
{
*
span
}
else
if
self
.is_fake
()
{
Span
::
dummy
()
}
else
{
rustc_span
(
self
.def_id
.expect_real
(),
tcx
)
self
.def_id
.as_def_id
()
.map
(|
did
|
rustc_span
(
did
,
tcx
))
.unwrap_or_else
(||
Span
::
dummy
()
)
}
}
...
...
@@ -546,7 +544,7 @@ pub fn from_def_id_and_attrs_and_parts(
}
crate
fn
is_crate
(
&
self
)
->
bool
{
self
.is_mod
()
&&
self
.def_id
.as_
real
()
.map_or
(
false
,
|
did
|
did
.index
==
CRATE_DEF_INDEX
)
self
.is_mod
()
&&
self
.def_id
.as_
def_id
()
.map_or
(
false
,
|
did
|
did
.index
==
CRATE_DEF_INDEX
)
}
crate
fn
is_mod
(
&
self
)
->
bool
{
self
.type_
()
==
ItemType
::
Module
...
...
@@ -657,11 +655,6 @@ pub fn from_def_id_and_attrs_and_parts(
_
=>
false
,
}
}
crate
fn
is_fake
(
&
self
)
->
bool
{
// FIXME: Find a better way to handle this
!
matches!
(
self
.def_id
,
ItemId
::
DefId
(
..
))
}
}
#[derive(Clone,
Debug)]
...
...
src/librustdoc/formats/cache.rs
浏览文件 @
acd4dc2d
...
...
@@ -215,7 +215,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// Propagate a trait method's documentation to all implementors of the
// trait.
if
let
clean
::
TraitItem
(
ref
t
)
=
*
item
.kind
{
self
.cache.traits
.entry
(
item
.def_id
.expect_
real
())
.or_insert_with
(||
{
self
.cache.traits
.entry
(
item
.def_id
.expect_
def_id
())
.or_insert_with
(||
{
clean
::
TraitWithExtraInfo
{
trait_
:
t
.clone
(),
is_notable
:
item
.attrs
.has_doc_flag
(
sym
::
notable_trait
),
...
...
@@ -348,11 +348,11 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're
// not a public item.
if
!
self
.cache.paths
.contains_key
(
&
item
.def_id
.expect_
real
())
||
self
.cache.access_levels
.is_public
(
item
.def_id
.expect_
real
())
if
!
self
.cache.paths
.contains_key
(
&
item
.def_id
.expect_
def_id
())
||
self
.cache.access_levels
.is_public
(
item
.def_id
.expect_
def_id
())
{
self
.cache.paths
.insert
(
item
.def_id
.expect_
real
(),
item
.def_id
.expect_
def_id
(),
(
self
.cache.stack
.clone
(),
item
.type_
()),
);
}
...
...
@@ -361,7 +361,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
clean
::
PrimitiveItem
(
..
)
=>
{
self
.cache
.paths
.insert
(
item
.def_id
.expect_
real
(),
(
self
.cache.stack
.clone
(),
item
.type_
()));
.insert
(
item
.def_id
.expect_
def_id
(),
(
self
.cache.stack
.clone
(),
item
.type_
()));
}
clean
::
ExternCrateItem
{
..
}
...
...
@@ -391,7 +391,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
|
clean
::
StructItem
(
..
)
|
clean
::
UnionItem
(
..
)
|
clean
::
VariantItem
(
..
)
=>
{
self
.cache.parent_stack
.push
(
item
.def_id
.expect_
real
());
self
.cache.parent_stack
.push
(
item
.def_id
.expect_
def_id
());
self
.cache.parent_is_trait_impl
=
false
;
true
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
acd4dc2d
...
...
@@ -1191,7 +1191,7 @@ impl clean::Visibility {
// FIXME(camelid): This may not work correctly if `item_did` is a module.
// However, rustdoc currently never displays a module's
// visibility, so it shouldn't matter.
let
parent_module
=
find_nearest_parent_module
(
cx
.tcx
(),
item_did
.expect_
real
());
let
parent_module
=
find_nearest_parent_module
(
cx
.tcx
(),
item_did
.expect_
def_id
());
if
vis_did
.index
==
CRATE_DEF_INDEX
{
"pub(crate) "
.to_owned
()
...
...
src/librustdoc/html/render/context.rs
浏览文件 @
acd4dc2d
...
...
@@ -230,7 +230,7 @@ fn render_item(&self, it: &clean::Item, is_module: bool) -> String {
&
self
.shared.style_files
,
)
}
else
{
if
let
Some
(
&
(
ref
names
,
ty
))
=
self
.cache.paths
.get
(
&
it
.def_id
.expect_
real
())
{
if
let
Some
(
&
(
ref
names
,
ty
))
=
self
.cache.paths
.get
(
&
it
.def_id
.expect_
def_id
())
{
let
mut
path
=
String
::
new
();
for
name
in
&
names
[
..
names
.len
()
-
1
]
{
path
.push_str
(
name
);
...
...
src/librustdoc/html/render/mod.rs
浏览文件 @
acd4dc2d
...
...
@@ -735,7 +735,7 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>)
AssocItemLink
::
Anchor
(
Some
(
ref
id
))
=>
format!
(
"#{}"
,
id
),
AssocItemLink
::
Anchor
(
None
)
=>
anchor
,
AssocItemLink
::
GotoSource
(
did
,
_
)
=>
{
href
(
did
.expect_
real
(),
cx
)
.map
(|
p
|
format!
(
"{}{}"
,
p
.0
,
anchor
))
.unwrap_or
(
anchor
)
href
(
did
.expect_
def_id
(),
cx
)
.map
(|
p
|
format!
(
"{}{}"
,
p
.0
,
anchor
))
.unwrap_or
(
anchor
)
}
}
}
...
...
@@ -867,7 +867,7 @@ fn method(
ItemType
::
TyMethod
};
href
(
did
.expect_
real
(),
cx
)
href
(
did
.expect_
def_id
(),
cx
)
.map
(|
p
|
format!
(
"{}#{}.{}"
,
p
.0
,
ty
,
name
))
.unwrap_or_else
(||
format!
(
"#{}.{}"
,
ty
,
name
))
}
...
...
@@ -1819,7 +1819,7 @@ fn small_url_encode(s: String) -> String {
}
fn
sidebar_assoc_items
(
cx
:
&
Context
<
'_
>
,
out
:
&
mut
Buffer
,
it
:
&
clean
::
Item
)
{
let
did
=
it
.def_id
.expect_
real
();
let
did
=
it
.def_id
.expect_
def_id
();
if
let
Some
(
v
)
=
cx
.cache.impls
.get
(
&
did
)
{
let
mut
used_links
=
FxHashSet
::
default
();
let
cache
=
cx
.cache
();
...
...
@@ -2109,7 +2109,7 @@ fn print_sidebar_section(
"</div>"
,
);
if
let
Some
(
implementors
)
=
cx
.cache.implementors
.get
(
&
it
.def_id
.expect_
real
())
{
if
let
Some
(
implementors
)
=
cx
.cache.implementors
.get
(
&
it
.def_id
.expect_
def_id
())
{
let
cache
=
cx
.cache
();
let
mut
res
=
implementors
.iter
()
...
...
src/librustdoc/html/render/print_item.rs
浏览文件 @
acd4dc2d
...
...
@@ -289,7 +289,7 @@ fn cmp(
w
,
"<div class=
\"
item-left
\"
><code>{}extern crate {} as {};"
,
myitem
.visibility
.print_with_space
(
myitem
.def_id
,
cx
),
anchor
(
myitem
.def_id
.expect_
real
(),
&*
src
.as_str
(),
cx
),
anchor
(
myitem
.def_id
.expect_
def_id
(),
&*
src
.as_str
(),
cx
),
myitem
.name
.as_ref
()
.unwrap
(),
),
None
=>
write!
(
...
...
@@ -297,7 +297,7 @@ fn cmp(
"<div class=
\"
item-left
\"
><code>{}extern crate {};"
,
myitem
.visibility
.print_with_space
(
myitem
.def_id
,
cx
),
anchor
(
myitem
.def_id
.expect_
real
(),
myitem
.def_id
.expect_
def_id
(),
&*
myitem
.name
.as_ref
()
.unwrap
()
.as_str
(),
cx
),
...
...
@@ -669,9 +669,9 @@ fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item
}
// If there are methods directly on this trait object, render them here.
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
real
(),
AssocItemRender
::
All
);
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
def_id
(),
AssocItemRender
::
All
);
if
let
Some
(
implementors
)
=
cx
.cache.implementors
.get
(
&
it
.def_id
.expect_
real
())
{
if
let
Some
(
implementors
)
=
cx
.cache.implementors
.get
(
&
it
.def_id
.expect_
def_id
())
{
// The DefId is for the first Type found with that name. The bool is
// if any Types with the same name but different DefId have been found.
let
mut
implementor_dups
:
FxHashMap
<
Symbol
,
(
DefId
,
bool
)
>
=
FxHashMap
::
default
();
...
...
@@ -787,7 +787,7 @@ fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item
path
=
if
it
.def_id
.is_local
()
{
cx
.current
.join
(
"/"
)
}
else
{
let
(
ref
path
,
_
)
=
cx
.cache.external_paths
[
&
it
.def_id
.expect_
real
()];
let
(
ref
path
,
_
)
=
cx
.cache.external_paths
[
&
it
.def_id
.expect_
def_id
()];
path
[
..
path
.len
()
-
1
]
.join
(
"/"
)
},
ty
=
it
.type_
(),
...
...
@@ -813,7 +813,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
// we need #14072 to make sense of the generics.
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
real
(),
AssocItemRender
::
All
)
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
def_id
(),
AssocItemRender
::
All
)
}
fn
item_opaque_ty
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
t
:
&
clean
::
OpaqueTy
)
{
...
...
@@ -834,7 +834,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
// we need #14072 to make sense of the generics.
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
real
(),
AssocItemRender
::
All
)
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
def_id
(),
AssocItemRender
::
All
)
}
fn
item_typedef
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
t
:
&
clean
::
Typedef
)
{
...
...
@@ -851,7 +851,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
document
(
w
,
cx
,
it
,
None
);
let
def_id
=
it
.def_id
.expect_
real
();
let
def_id
=
it
.def_id
.expect_
def_id
();
// Render any items associated directly to this alias, as otherwise they
// won't be visible anywhere in the docs. It would be nice to also show
// associated items from the aliased type (see discussion in #32077), but
...
...
@@ -903,7 +903,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
document
(
w
,
cx
,
field
,
Some
(
it
));
}
}
let
def_id
=
it
.def_id
.expect_
real
();
let
def_id
=
it
.def_id
.expect_
def_id
();
render_assoc_items
(
w
,
cx
,
it
,
def_id
,
AssocItemRender
::
All
);
document_type_layout
(
w
,
cx
,
def_id
);
}
...
...
@@ -1041,7 +1041,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
}
}
}
let
def_id
=
it
.def_id
.expect_
real
();
let
def_id
=
it
.def_id
.expect_
def_id
();
render_assoc_items
(
w
,
cx
,
it
,
def_id
,
AssocItemRender
::
All
);
document_type_layout
(
w
,
cx
,
def_id
);
}
...
...
@@ -1093,7 +1093,7 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean
fn
item_primitive
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
)
{
document
(
w
,
cx
,
it
,
None
);
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
real
(),
AssocItemRender
::
All
)
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
def_id
(),
AssocItemRender
::
All
)
}
fn
item_constant
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
c
:
&
clean
::
Constant
)
{
...
...
@@ -1182,7 +1182,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
}
}
}
let
def_id
=
it
.def_id
.expect_
real
();
let
def_id
=
it
.def_id
.expect_
def_id
();
render_assoc_items
(
w
,
cx
,
it
,
def_id
,
AssocItemRender
::
All
);
document_type_layout
(
w
,
cx
,
def_id
);
}
...
...
@@ -1213,7 +1213,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
document
(
w
,
cx
,
it
,
None
);
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
real
(),
AssocItemRender
::
All
)
render_assoc_items
(
w
,
cx
,
it
,
it
.def_id
.expect_
def_id
(),
AssocItemRender
::
All
)
}
fn
item_keyword
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
)
{
...
...
src/librustdoc/json/mod.rs
浏览文件 @
acd4dc2d
...
...
@@ -164,11 +164,11 @@ fn item(&mut self, item: clean::Item) -> Result<(), Error> {
let
id
=
item
.def_id
;
if
let
Some
(
mut
new_item
)
=
self
.convert_item
(
item
)
{
if
let
types
::
ItemEnum
::
Trait
(
ref
mut
t
)
=
new_item
.inner
{
t
.implementors
=
self
.get_trait_implementors
(
id
.expect_
real
())
t
.implementors
=
self
.get_trait_implementors
(
id
.expect_
def_id
())
}
else
if
let
types
::
ItemEnum
::
Struct
(
ref
mut
s
)
=
new_item
.inner
{
s
.impls
=
self
.get_impls
(
id
.expect_
real
())
s
.impls
=
self
.get_impls
(
id
.expect_
def_id
())
}
else
if
let
types
::
ItemEnum
::
Enum
(
ref
mut
e
)
=
new_item
.inner
{
e
.impls
=
self
.get_impls
(
id
.expect_
real
())
e
.impls
=
self
.get_impls
(
id
.expect_
def_id
())
}
let
removed
=
self
.index
.borrow_mut
()
.insert
(
from_item_id
(
id
),
new_item
.clone
());
...
...
src/librustdoc/passes/calculate_doc_coverage.rs
浏览文件 @
acd4dc2d
...
...
@@ -213,13 +213,13 @@ fn fold_item(&mut self, i: clean::Item) -> Option<clean::Item> {
let
filename
=
i
.span
(
self
.ctx.tcx
)
.filename
(
self
.ctx
.sess
());
let
has_doc_example
=
tests
.found_tests
!=
0
;
// The `expect_
real
()` should be okay because `local_def_id_to_hir_id`
// The `expect_
def_id
()` should be okay because `local_def_id_to_hir_id`
// would presumably panic if a fake `DefIndex` were passed.
let
hir_id
=
self
.ctx
.tcx
.hir
()
.local_def_id_to_hir_id
(
i
.def_id
.expect_
real
()
.expect_local
());
.local_def_id_to_hir_id
(
i
.def_id
.expect_
def_id
()
.expect_local
());
let
(
level
,
source
)
=
self
.ctx.tcx
.lint_level_at_node
(
MISSING_DOCS
,
hir_id
);
// `missing_docs` is allow-by-default, so don't treat this as ignoring the item
// unless the user had an explicit `allow`
...
...
src/librustdoc/passes/check_code_block_syntax.rs
浏览文件 @
acd4dc2d
...
...
@@ -53,7 +53,7 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
return
;
}
let
local_id
=
match
item
.def_id
.as_
real
()
.and_then
(|
x
|
x
.as_local
())
{
let
local_id
=
match
item
.def_id
.as_
def_id
()
.and_then
(|
x
|
x
.as_local
())
{
Some
(
id
)
=>
id
,
// We don't need to check the syntax for other crates so returning
// without doing anything should not be a problem.
...
...
@@ -137,7 +137,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
let
sp
=
item
.attr_span
(
self
.cx.tcx
);
let
extra
=
crate
::
html
::
markdown
::
ExtraInfo
::
new_did
(
self
.cx.tcx
,
item
.def_id
.expect_
real
(),
item
.def_id
.expect_
def_id
(),
sp
,
);
for
code_block
in
markdown
::
rust_code_blocks
(
&
dox
,
&
extra
)
{
...
...
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
acd4dc2d
...
...
@@ -830,49 +830,48 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
fn
fold_item
(
&
mut
self
,
item
:
Item
)
->
Option
<
Item
>
{
use
rustc_middle
::
ty
::
DefIdTree
;
let
parent_node
=
if
item
.is_fake
()
{
None
}
else
{
find_nearest_parent_module
(
self
.cx.tcx
,
item
.def_id
.expect_real
())
};
let
parent_node
=
item
.def_id
.as_def_id
()
.and_then
(|
did
|
find_nearest_parent_module
(
self
.cx.tcx
,
did
));
if
parent_node
.is_some
()
{
trace!
(
"got parent node for {:?} {:?}, id {:?}"
,
item
.type_
(),
item
.name
,
item
.def_id
);
}
// find item's parent to resolve `Self` in item's docs below
debug!
(
"looking for the `Self` type"
);
let
self_id
=
if
item
.is_fake
()
{
None
// Checking if the item is a field in an enum variant
}
else
if
(
matches!
(
self
.cx.tcx
.def_kind
(
item
.def_id
.expect_real
()),
DefKind
::
Field
)
&&
matches!
(
self
.cx.tcx
.def_kind
(
self
.cx.tcx
.parent
(
item
.def_id
.expect_real
())
.unwrap
()),
DefKind
::
Variant
))
{
self
.cx
.tcx
.parent
(
item
.def_id
.expect_real
())
.and_then
(|
item_id
|
self
.cx.tcx
.parent
(
item_id
))
}
else
if
matches!
(
self
.cx.tcx
.def_kind
(
item
.def_id
.expect_real
()),
DefKind
::
AssocConst
|
DefKind
::
AssocFn
|
DefKind
::
AssocTy
|
DefKind
::
Variant
|
DefKind
::
Field
)
{
self
.cx.tcx
.parent
(
item
.def_id
.expect_real
())
// HACK(jynelson): `clean` marks associated types as `TypedefItem`, not as `AssocTypeItem`.
// Fixing this breaks `fn render_deref_methods`.
// As a workaround, see if the parent of the item is an `impl`; if so this must be an associated item,
// regardless of what rustdoc wants to call it.
}
else
if
let
Some
(
parent
)
=
self
.cx.tcx
.parent
(
item
.def_id
.expect_real
())
{
let
parent_kind
=
self
.cx.tcx
.def_kind
(
parent
);
Some
(
if
parent_kind
==
DefKind
::
Impl
{
parent
}
else
{
item
.def_id
.expect_real
()
})
}
else
{
Some
(
item
.def_id
.expect_real
())
let
self_id
=
match
item
.def_id
.as_def_id
()
{
None
=>
None
,
Some
(
did
)
if
(
matches!
(
self
.cx.tcx
.def_kind
(
did
),
DefKind
::
Field
)
&&
matches!
(
self
.cx.tcx
.def_kind
(
self
.cx.tcx
.parent
(
did
)
.unwrap
()),
DefKind
::
Variant
))
=>
{
self
.cx.tcx
.parent
(
did
)
.and_then
(|
item_id
|
self
.cx.tcx
.parent
(
item_id
))
}
Some
(
did
)
if
matches!
(
self
.cx.tcx
.def_kind
(
did
),
DefKind
::
AssocConst
|
DefKind
::
AssocFn
|
DefKind
::
AssocTy
|
DefKind
::
Variant
|
DefKind
::
Field
)
=>
{
self
.cx.tcx
.parent
(
did
)
}
Some
(
did
)
=>
match
self
.cx.tcx
.parent
(
did
)
{
// HACK(jynelson): `clean` marks associated types as `TypedefItem`, not as `AssocTypeItem`.
// Fixing this breaks `fn render_deref_methods`.
// As a workaround, see if the parent of the item is an `impl`; if so this must be an associated item,
// regardless of what rustdoc wants to call it.
Some
(
parent
)
=>
{
let
parent_kind
=
self
.cx.tcx
.def_kind
(
parent
);
Some
(
if
parent_kind
==
DefKind
::
Impl
{
parent
}
else
{
did
})
}
None
=>
Some
(
did
),
},
};
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
...
...
@@ -897,7 +896,7 @@ fn fold_item(&mut self, item: Item) -> Option<Item> {
let
inner_docs
=
item
.inner_docs
(
self
.cx.tcx
);
if
item
.is_mod
()
&&
inner_docs
{
self
.mod_ids
.push
(
item
.def_id
.expect_
real
());
self
.mod_ids
.push
(
item
.def_id
.expect_
def_id
());
}
// We want to resolve in the lexical scope of the documentation.
...
...
@@ -924,7 +923,7 @@ fn fold_item(&mut self, item: Item) -> Option<Item> {
Some
(
if
item
.is_mod
()
{
if
!
inner_docs
{
self
.mod_ids
.push
(
item
.def_id
.expect_
real
());
self
.mod_ids
.push
(
item
.def_id
.expect_
def_id
());
}
let
ret
=
self
.fold_item_recur
(
item
);
...
...
@@ -1235,10 +1234,10 @@ fn resolve_link(
// item can be non-local e.g. when using #[doc(primitive = "pointer")]
if
let
Some
((
src_id
,
dst_id
))
=
id
.as_local
()
// The `expect_
real
()` should be okay because `local_def_id_to_hir_id`
// The `expect_
def_id
()` should be okay because `local_def_id_to_hir_id`
// would presumably panic if a fake `DefIndex` were passed.
.and_then
(|
dst_id
|
{
item
.def_id
.expect_
real
()
.as_local
()
.map
(|
src_id
|
(
src_id
,
dst_id
))
item
.def_id
.expect_
def_id
()
.as_local
()
.map
(|
src_id
|
(
src_id
,
dst_id
))
})
{
let
hir_src
=
self
.cx.tcx
.hir
()
.local_def_id_to_hir_id
(
src_id
);
...
...
src/librustdoc/passes/collect_trait_impls.rs
浏览文件 @
acd4dc2d
...
...
@@ -136,10 +136,15 @@ impl<'a, 'tcx> DocFolder for SyntheticImplCollector<'a, 'tcx> {
fn
fold_item
(
&
mut
self
,
i
:
Item
)
->
Option
<
Item
>
{
if
i
.is_struct
()
||
i
.is_enum
()
||
i
.is_union
()
{
// FIXME(eddyb) is this `doc(hidden)` check needed?
if
!
self
.cx.tcx
.get_attrs
(
i
.def_id
.expect_real
())
.lists
(
sym
::
doc
)
.has_word
(
sym
::
hidden
)
if
!
self
.cx
.tcx
.get_attrs
(
i
.def_id
.expect_def_id
())
.lists
(
sym
::
doc
)
.has_word
(
sym
::
hidden
)
{
self
.impls
.extend
(
get_auto_trait_and_blanket_impls
(
self
.cx
,
i
.def_id
.expect_
real
()));
.extend
(
get_auto_trait_and_blanket_impls
(
self
.cx
,
i
.def_id
.expect_
def_id
()));
}
}
...
...
src/librustdoc/passes/doc_test_lints.rs
浏览文件 @
acd4dc2d
...
...
@@ -53,7 +53,7 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
}
crate
fn
should_have_doc_example
(
cx
:
&
DocContext
<
'_
>
,
item
:
&
clean
::
Item
)
->
bool
{
if
!
cx
.cache.access_levels
.is_public
(
item
.def_id
.expect_
real
())
if
!
cx
.cache.access_levels
.is_public
(
item
.def_id
.expect_
def_id
())
||
matches!
(
*
item
.kind
,
clean
::
StructFieldItem
(
_
)
...
...
@@ -71,9 +71,9 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
{
return
false
;
}
// The `expect_
real
()` should be okay because `local_def_id_to_hir_id`
// The `expect_
def_id
()` should be okay because `local_def_id_to_hir_id`
// would presumably panic if a fake `DefIndex` were passed.
let
hir_id
=
cx
.tcx
.hir
()
.local_def_id_to_hir_id
(
item
.def_id
.expect_
real
()
.expect_local
());
let
hir_id
=
cx
.tcx
.hir
()
.local_def_id_to_hir_id
(
item
.def_id
.expect_
def_id
()
.expect_local
());
if
cx
.tcx
.hir
()
.attrs
(
hir_id
)
.lists
(
sym
::
doc
)
.has_word
(
sym
::
hidden
)
||
inherits_doc_hidden
(
cx
.tcx
,
hir_id
)
{
...
...
@@ -107,7 +107,8 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
|
lint
|
lint
.build
(
"missing code example in this documentation"
)
.emit
(),
);
}
}
else
if
tests
.found_tests
>
0
&&
!
cx
.cache.access_levels
.is_public
(
item
.def_id
.expect_real
())
}
else
if
tests
.found_tests
>
0
&&
!
cx
.cache.access_levels
.is_public
(
item
.def_id
.expect_def_id
())
{
cx
.tcx
.struct_span_lint_hir
(
crate
::
lint
::
PRIVATE_DOC_TESTS
,
...
...
src/librustdoc/passes/stripper.rs
浏览文件 @
acd4dc2d
...
...
@@ -42,7 +42,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
|
clean
::
TraitAliasItem
(
..
)
|
clean
::
ForeignTypeItem
=>
{
if
i
.def_id
.is_local
()
{
if
!
self
.access_levels
.is_exported
(
i
.def_id
.expect_
real
())
{
if
!
self
.access_levels
.is_exported
(
i
.def_id
.expect_
def_id
())
{
debug!
(
"Stripper: stripping {:?} {:?}"
,
i
.type_
(),
i
.name
);
return
None
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录