Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
08df8b81
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,发现更多精彩内容 >>
提交
08df8b81
编写于
1月 30, 2022
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #92711 - zredb:issue-90187-fix, r=notriddle
rustdoc: Remove `def_id_no_primitives` Fixes #90187.
上级
8c7f2bf4
5cc32e71
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
51 addition
and
49 deletion
+51
-49
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+1
-13
src/librustdoc/formats/cache.rs
src/librustdoc/formats/cache.rs
+1
-1
src/librustdoc/html/render/search_index.rs
src/librustdoc/html/render/search_index.rs
+34
-24
src/librustdoc/passes/collect_trait_impls.rs
src/librustdoc/passes/collect_trait_impls.rs
+8
-6
src/librustdoc/passes/strip_hidden.rs
src/librustdoc/passes/strip_hidden.rs
+2
-2
src/librustdoc/passes/strip_private.rs
src/librustdoc/passes/strip_private.rs
+1
-1
src/librustdoc/passes/stripper.rs
src/librustdoc/passes/stripper.rs
+4
-2
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
08df8b81
...
...
@@ -338,6 +338,7 @@ fn to_remote(url: impl ToString) -> ExternalLocation {
}
/// Indicates where an external crate can be found.
#[derive(Debug)]
crate
enum
ExternalLocation
{
/// Remote URL root of the external crate
Remote
(
String
),
...
...
@@ -1539,23 +1540,10 @@ fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s.
///
/// See [`Self::def_id_no_primitives`] for more.
///
/// [clean]: crate::clean
crate
fn
def_id
(
&
self
,
cache
:
&
Cache
)
->
Option
<
DefId
>
{
self
.inner_def_id
(
Some
(
cache
))
}
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
/// This will return [`None`] when called on a primitive [`clean::Type`].
/// Use [`Self::def_id`] if you want to include primitives.
///
/// [`clean`]: crate::clean
/// [`clean::Type`]: crate::clean::Type
// FIXME: get rid of this function and always use `def_id`
crate
fn
def_id_no_primitives
(
&
self
)
->
Option
<
DefId
>
{
self
.inner_def_id
(
None
)
}
}
/// A primitive (aka, builtin) type.
...
...
src/librustdoc/formats/cache.rs
浏览文件 @
08df8b81
...
...
@@ -303,7 +303,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
desc
,
parent
,
parent_idx
:
None
,
search_type
:
get_function_type_for_search
(
&
item
,
self
.tcx
),
search_type
:
get_function_type_for_search
(
&
item
,
self
.tcx
,
self
.cache
),
aliases
:
item
.attrs
.get_doc_aliases
(),
});
}
...
...
src/librustdoc/html/render/search_index.rs
浏览文件 @
08df8b81
...
...
@@ -3,7 +3,7 @@
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
symbol
::
Symbol
;
use
rustc_span
::
symbol
::
{
kw
,
Symbol
}
;
use
serde
::
ser
::{
Serialize
,
SerializeStruct
,
Serializer
};
use
crate
::
clean
;
...
...
@@ -33,7 +33,7 @@
desc
,
parent
:
Some
(
did
),
parent_idx
:
None
,
search_type
:
get_function_type_for_search
(
item
,
tcx
),
search_type
:
get_function_type_for_search
(
item
,
tcx
,
&
cache
),
aliases
:
item
.attrs
.get_doc_aliases
(),
});
}
...
...
@@ -188,11 +188,12 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
crate
fn
get_function_type_for_search
<
'tcx
>
(
item
:
&
clean
::
Item
,
tcx
:
TyCtxt
<
'tcx
>
,
cache
:
&
Cache
,
)
->
Option
<
IndexItemFunctionType
>
{
let
(
mut
inputs
,
mut
output
)
=
match
*
item
.kind
{
clean
::
FunctionItem
(
ref
f
)
=>
get_fn_inputs_and_outputs
(
f
,
tcx
),
clean
::
MethodItem
(
ref
m
,
_
)
=>
get_fn_inputs_and_outputs
(
m
,
tcx
),
clean
::
TyMethodItem
(
ref
m
)
=>
get_fn_inputs_and_outputs
(
m
,
tcx
),
clean
::
FunctionItem
(
ref
f
)
=>
get_fn_inputs_and_outputs
(
f
,
tcx
,
cache
),
clean
::
MethodItem
(
ref
m
,
_
)
=>
get_fn_inputs_and_outputs
(
m
,
tcx
,
cache
),
clean
::
TyMethodItem
(
ref
m
)
=>
get_fn_inputs_and_outputs
(
m
,
tcx
,
cache
),
_
=>
return
None
,
};
...
...
@@ -219,7 +220,8 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option<Symbol> {
let
path
=
&
bounds
[
0
]
.trait_
;
Some
(
path
.segments
.last
()
.unwrap
()
.name
)
}
clean
::
Generic
(
s
)
=>
Some
(
s
),
// We return an empty name because we don't care about the generic name itself.
clean
::
Generic
(
_
)
=>
Some
(
kw
::
Empty
),
clean
::
Primitive
(
ref
p
)
=>
Some
(
p
.as_sym
()),
clean
::
BorrowedRef
{
ref
type_
,
..
}
=>
get_index_type_name
(
type_
),
clean
::
BareFunction
(
_
)
...
...
@@ -240,24 +242,27 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option<Symbol> {
///
/// Important note: It goes through generics recursively. So if you have
/// `T: Option<Result<(), ()>>`, it'll go into `Option` and then into `Result`.
#[instrument(level
=
"trace"
,
skip(tcx,
res))]
#[instrument(level
=
"trace"
,
skip(tcx,
res
,
cache
))]
fn
add_generics_and_bounds_as_types
<
'tcx
>
(
generics
:
&
Generics
,
arg
:
&
Type
,
tcx
:
TyCtxt
<
'tcx
>
,
recurse
:
usize
,
res
:
&
mut
Vec
<
TypeWithKind
>
,
cache
:
&
Cache
,
)
{
fn
insert_ty
(
res
:
&
mut
Vec
<
TypeWithKind
>
,
tcx
:
TyCtxt
<
'_
>
,
ty
:
Type
,
mut
generics
:
Vec
<
TypeWithKind
>
,
cache
:
&
Cache
,
)
{
let
is_full_generic
=
ty
.is_full_generic
();
let
generics_empty
=
generics
.is_empty
();
if
is_full_generic
{
if
generics
.is_empty
()
{
if
generics
_empty
{
// This is a type parameter with no trait bounds (for example: `T` in
// `fn f<T>(p: T)`, so not useful for the rustdoc search because we would end up
// with an empty type with an empty name. Let's just discard it.
...
...
@@ -304,14 +309,14 @@ fn insert_ty(
}
}
let
mut
index_ty
=
get_index_type
(
&
ty
,
generics
);
if
index_ty
.name
.as_ref
()
.map
(|
s
|
s
.is_empty
())
.unwrap_or
(
true
)
{
if
index_ty
.name
.as_ref
()
.map
(|
s
|
s
.is_empty
()
&&
generics_empty
)
.unwrap_or
(
true
)
{
return
;
}
if
is_full_generic
{
// We remove the name of the full generic because we have no use for it.
index_ty
.name
=
Some
(
String
::
new
());
res
.push
(
TypeWithKind
::
from
((
index_ty
,
ItemType
::
Generic
)));
}
else
if
let
Some
(
kind
)
=
ty
.def_id
_no_primitives
(
)
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
}
else
if
let
Some
(
kind
)
=
ty
.def_id
(
cache
)
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
res
.push
(
TypeWithKind
::
from
((
index_ty
,
kind
)));
}
else
if
ty
.is_primitive
()
{
// This is a primitive, let's store it as such.
...
...
@@ -330,9 +335,7 @@ fn insert_ty(
if
let
Type
::
Generic
(
arg_s
)
=
*
arg
{
// First we check if the bounds are in a `where` predicate...
if
let
Some
(
where_pred
)
=
generics
.where_predicates
.iter
()
.find
(|
g
|
match
g
{
WherePredicate
::
BoundPredicate
{
ty
,
..
}
=>
{
ty
.def_id_no_primitives
()
==
arg
.def_id_no_primitives
()
}
WherePredicate
::
BoundPredicate
{
ty
,
..
}
=>
ty
.def_id
(
cache
)
==
arg
.def_id
(
cache
),
_
=>
false
,
})
{
let
mut
ty_generics
=
Vec
::
new
();
...
...
@@ -348,6 +351,7 @@ fn insert_ty(
tcx
,
recurse
+
1
,
&
mut
ty_generics
,
cache
,
)
}
_
=>
{}
...
...
@@ -355,7 +359,7 @@ fn insert_ty(
}
}
}
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
);
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
,
cache
);
}
// Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
if
let
Some
(
bound
)
=
generics
.params
.iter
()
.find
(|
g
|
g
.is_type
()
&&
g
.name
==
arg_s
)
{
...
...
@@ -369,10 +373,11 @@ fn insert_ty(
tcx
,
recurse
+
1
,
&
mut
ty_generics
,
cache
,
);
}
}
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
);
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
,
cache
);
}
}
else
{
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
...
...
@@ -383,10 +388,17 @@ fn insert_ty(
let
mut
ty_generics
=
Vec
::
new
();
if
let
Some
(
arg_generics
)
=
arg
.generics
()
{
for
gen
in
arg_generics
.iter
()
{
add_generics_and_bounds_as_types
(
generics
,
gen
,
tcx
,
recurse
+
1
,
&
mut
ty_generics
);
add_generics_and_bounds_as_types
(
generics
,
gen
,
tcx
,
recurse
+
1
,
&
mut
ty_generics
,
cache
,
);
}
}
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
);
insert_ty
(
res
,
tcx
,
arg
.clone
(),
ty_generics
,
cache
);
}
}
...
...
@@ -397,6 +409,7 @@ fn insert_ty(
fn
get_fn_inputs_and_outputs
<
'tcx
>
(
func
:
&
Function
,
tcx
:
TyCtxt
<
'tcx
>
,
cache
:
&
Cache
,
)
->
(
Vec
<
TypeWithKind
>
,
Vec
<
TypeWithKind
>
)
{
let
decl
=
&
func
.decl
;
let
generics
=
&
func
.generics
;
...
...
@@ -407,12 +420,11 @@ fn get_fn_inputs_and_outputs<'tcx>(
continue
;
}
let
mut
args
=
Vec
::
new
();
add_generics_and_bounds_as_types
(
generics
,
&
arg
.type_
,
tcx
,
0
,
&
mut
args
);
add_generics_and_bounds_as_types
(
generics
,
&
arg
.type_
,
tcx
,
0
,
&
mut
args
,
cache
);
if
!
args
.is_empty
()
{
all_types
.extend
(
args
);
}
else
{
if
let
Some
(
kind
)
=
arg
.type_
.def_id_no_primitives
()
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
if
let
Some
(
kind
)
=
arg
.type_
.def_id
(
cache
)
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
all_types
.push
(
TypeWithKind
::
from
((
get_index_type
(
&
arg
.type_
,
vec!
[]),
kind
)));
}
}
...
...
@@ -421,11 +433,9 @@ fn get_fn_inputs_and_outputs<'tcx>(
let
mut
ret_types
=
Vec
::
new
();
match
decl
.output
{
FnRetTy
::
Return
(
ref
return_type
)
=>
{
add_generics_and_bounds_as_types
(
generics
,
return_type
,
tcx
,
0
,
&
mut
ret_types
);
add_generics_and_bounds_as_types
(
generics
,
return_type
,
tcx
,
0
,
&
mut
ret_types
,
cache
);
if
ret_types
.is_empty
()
{
if
let
Some
(
kind
)
=
return_type
.def_id_no_primitives
()
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
if
let
Some
(
kind
)
=
return_type
.def_id
(
cache
)
.map
(|
did
|
tcx
.def_kind
(
did
)
.into
())
{
ret_types
.push
(
TypeWithKind
::
from
((
get_index_type
(
return_type
,
vec!
[]),
kind
)));
}
}
...
...
src/librustdoc/passes/collect_trait_impls.rs
浏览文件 @
08df8b81
...
...
@@ -4,6 +4,7 @@
use
super
::
Pass
;
use
crate
::
clean
::
*
;
use
crate
::
core
::
DocContext
;
use
crate
::
formats
::
cache
::
Cache
;
use
crate
::
visit
::
DocVisitor
;
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxHashSet
};
...
...
@@ -57,14 +58,14 @@
}
});
let
mut
cleaner
=
BadImplStripper
{
prims
,
items
:
crate_items
};
let
mut
cleaner
=
BadImplStripper
{
prims
,
items
:
crate_items
,
cache
:
&
cx
.cache
};
let
mut
type_did_to_deref_target
:
FxHashMap
<
DefId
,
&
Type
>
=
FxHashMap
::
default
();
// Follow all `Deref` targets of included items and recursively add them as valid
fn
add_deref_target
(
cx
:
&
DocContext
<
'_
>
,
map
:
&
FxHashMap
<
DefId
,
&
Type
>
,
cleaner
:
&
mut
BadImplStripper
,
cleaner
:
&
mut
BadImplStripper
<
'_
>
,
type_did
:
DefId
,
)
{
if
let
Some
(
target
)
=
map
.get
(
&
type_did
)
{
...
...
@@ -102,7 +103,7 @@ fn add_deref_target(
}
else
if
let
Some
(
did
)
=
target
.def_id
(
&
cx
.cache
)
{
cleaner
.items
.insert
(
did
.into
());
}
if
let
Some
(
for_did
)
=
for_
.def_id
_no_primitives
(
)
{
if
let
Some
(
for_did
)
=
for_
.def_id
(
&
cx
.cache
)
{
if
type_did_to_deref_target
.insert
(
for_did
,
target
)
.is_none
()
{
// Since only the `DefId` portion of the `Type` instances is known to be same for both the
// `Deref` target type and the impl for type positions, this map of types is keyed by
...
...
@@ -204,19 +205,20 @@ fn visit_item(&mut self, i: &Item) {
}
}
struct
BadImplStripper
{
struct
BadImplStripper
<
'a
>
{
prims
:
FxHashSet
<
PrimitiveType
>
,
items
:
FxHashSet
<
ItemId
>
,
cache
:
&
'a
Cache
,
}
impl
BadImplStripper
{
impl
<
'a
>
BadImplStripper
<
'a
>
{
fn
keep_impl
(
&
self
,
ty
:
&
Type
,
is_deref
:
bool
)
->
bool
{
if
let
Generic
(
_
)
=
ty
{
// keep impls made on generics
true
}
else
if
let
Some
(
prim
)
=
ty
.primitive_type
()
{
self
.prims
.contains
(
&
prim
)
}
else
if
let
Some
(
did
)
=
ty
.def_id
_no_primitives
(
)
{
}
else
if
let
Some
(
did
)
=
ty
.def_id
(
self
.cache
)
{
is_deref
||
self
.keep_impl_with_def_id
(
did
.into
())
}
else
{
false
...
...
src/librustdoc/passes/strip_hidden.rs
浏览文件 @
08df8b81
...
...
@@ -15,7 +15,7 @@
};
/// Strip items marked `#[doc(hidden)]`
crate
fn
strip_hidden
(
krate
:
clean
::
Crate
,
_
:
&
mut
DocContext
<
'_
>
)
->
clean
::
Crate
{
crate
fn
strip_hidden
(
krate
:
clean
::
Crate
,
cx
:
&
mut
DocContext
<
'_
>
)
->
clean
::
Crate
{
let
mut
retained
=
ItemIdSet
::
default
();
// strip all #[doc(hidden)] items
...
...
@@ -25,7 +25,7 @@
};
// strip all impls referencing stripped items
let
mut
stripper
=
ImplStripper
{
retained
:
&
retained
};
let
mut
stripper
=
ImplStripper
{
retained
:
&
retained
,
cache
:
&
cx
.cache
};
stripper
.fold_crate
(
krate
)
}
...
...
src/librustdoc/passes/strip_private.rs
浏览文件 @
08df8b81
...
...
@@ -29,6 +29,6 @@
}
// strip all impls referencing private items
let
mut
stripper
=
ImplStripper
{
retained
:
&
retained
};
let
mut
stripper
=
ImplStripper
{
retained
:
&
retained
,
cache
:
&
cx
.cache
};
stripper
.fold_crate
(
krate
)
}
src/librustdoc/passes/stripper.rs
浏览文件 @
08df8b81
...
...
@@ -5,6 +5,7 @@
use
crate
::
clean
::{
self
,
Item
,
ItemIdSet
};
use
crate
::
fold
::{
strip_item
,
DocFolder
};
use
crate
::
formats
::
cache
::
Cache
;
crate
struct
Stripper
<
'a
>
{
crate
retained
:
&
'a
mut
ItemIdSet
,
...
...
@@ -118,6 +119,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
/// This stripper discards all impls which reference stripped items
crate
struct
ImplStripper
<
'a
>
{
crate
retained
:
&
'a
ItemIdSet
,
crate
cache
:
&
'a
Cache
,
}
impl
<
'a
>
DocFolder
for
ImplStripper
<
'a
>
{
...
...
@@ -127,7 +129,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
if
imp
.trait_
.is_none
()
&&
imp
.items
.is_empty
()
{
return
None
;
}
if
let
Some
(
did
)
=
imp
.for_
.def_id
_no_primitives
(
)
{
if
let
Some
(
did
)
=
imp
.for_
.def_id
(
self
.cache
)
{
if
did
.is_local
()
&&
!
imp
.for_
.is_assoc_ty
()
&&
!
self
.retained
.contains
(
&
did
.into
())
{
debug!
(
"ImplStripper: impl item for stripped type; removing"
);
...
...
@@ -142,7 +144,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
}
if
let
Some
(
generics
)
=
imp
.trait_
.as_ref
()
.and_then
(|
t
|
t
.generics
())
{
for
typaram
in
generics
{
if
let
Some
(
did
)
=
typaram
.def_id
_no_primitives
(
)
{
if
let
Some
(
did
)
=
typaram
.def_id
(
self
.cache
)
{
if
did
.is_local
()
&&
!
self
.retained
.contains
(
&
did
.into
())
{
debug!
(
"ImplStripper: stripped item in trait's generics; removing impl"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录