Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
673c3fc2
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,发现更多精彩内容 >>
提交
673c3fc2
编写于
6月 12, 2019
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: disallow cloning HIR nodes.
上级
887feeea
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
476 addition
and
474 deletion
+476
-474
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+48
-55
src/librustc/hir/map/mod.rs
src/librustc/hir/map/mod.rs
+5
-5
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+85
-85
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+32
-29
src/librustc/traits/error_reporting.rs
src/librustc/traits/error_reporting.rs
+2
-2
src/librustc_mir/borrow_check/conflict_errors.rs
src/librustc_mir/borrow_check/conflict_errors.rs
+2
-2
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+13
-13
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+7
-7
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+11
-9
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+40
-53
src/librustdoc/doctree.rs
src/librustdoc/doctree.rs
+108
-94
src/librustdoc/visit_ast.rs
src/librustdoc/visit_ast.rs
+123
-120
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
673c3fc2
...
...
@@ -608,15 +608,7 @@ fn visit_item(&mut self, item: &'tcx Item) {
});
if
let
Some
(
hir_id
)
=
item_hir_id
{
let
item_generics
=
match
self
.lctx.items
.get
(
&
hir_id
)
.unwrap
()
.node
{
hir
::
ItemKind
::
Impl
(
_
,
_
,
_
,
ref
generics
,
..
)
|
hir
::
ItemKind
::
Trait
(
_
,
_
,
ref
generics
,
..
)
=>
{
generics
.params
.clone
()
}
_
=>
HirVec
::
new
(),
};
self
.lctx
.with_parent_impl_lifetime_defs
(
&
item_generics
,
|
this
|
{
self
.lctx
.with_parent_item_lifetime_defs
(
hir_id
,
|
this
|
{
let
this
=
&
mut
ItemLowerer
{
lctx
:
this
};
if
let
ItemKind
::
Impl
(
..
,
ref
opt_trait_ref
,
_
,
_
)
=
item
.node
{
this
.with_trait_impl_ref
(
opt_trait_ref
,
|
this
|
{
...
...
@@ -1054,14 +1046,22 @@ fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -
// This should only be used with generics that have already had their
// in-band lifetimes added. In practice, this means that this function is
// only used when lowering a child item of a trait or impl.
fn
with_parent_i
mpl
_lifetime_defs
<
T
,
F
>
(
&
mut
self
,
par
ams
:
&
HirVec
<
hir
::
GenericParam
>
,
fn
with_parent_i
tem
_lifetime_defs
<
T
,
F
>
(
&
mut
self
,
par
ent_hir_id
:
hir
::
HirId
,
f
:
F
)
->
T
where
F
:
FnOnce
(
&
mut
LoweringContext
<
'_
>
)
->
T
,
{
let
old_len
=
self
.in_scope_lifetimes
.len
();
let
lt_def_names
=
params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
let
parent_generics
=
match
self
.items
.get
(
&
parent_hir_id
)
.unwrap
()
.node
{
hir
::
ItemKind
::
Impl
(
_
,
_
,
_
,
ref
generics
,
..
)
|
hir
::
ItemKind
::
Trait
(
_
,
_
,
ref
generics
,
..
)
=>
{
&
generics
.params
[
..
]
}
_
=>
&
[],
};
let
lt_def_names
=
parent_generics
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
hir
::
GenericParamKind
::
Lifetime
{
..
}
=>
Some
(
param
.name
.ident
()
.modern
()),
_
=>
None
,
});
...
...
@@ -1113,8 +1113,7 @@ fn add_in_band_defs<F, T>(
lowered_generics
.params
=
lowered_generics
.params
.iter
()
.cloned
()
.into_iter
()
.chain
(
in_band_defs
)
.collect
();
...
...
@@ -3114,8 +3113,8 @@ fn lower_poly_trait_ref(
&
NodeMap
::
default
(),
itctx
.reborrow
(),
);
let
trait_ref
=
self
.with_
parent_impl
_lifetime_defs
(
&
bound_generic_params
,
let
trait_ref
=
self
.with_
in_scope
_lifetime_defs
(
&
p
.
bound_generic_params
,
|
this
|
this
.lower_trait_ref
(
&
p
.trait_ref
,
itctx
),
);
...
...
@@ -3602,8 +3601,7 @@ fn lower_use_tree(
// Essentially a single `use` which imports two names is desugared into
// two imports.
for
(
res
,
&
new_node_id
)
in
resolutions
.zip
([
id1
,
id2
]
.iter
())
{
let
vis
=
vis
.clone
();
let
ident
=
ident
.clone
();
let
ident
=
*
ident
;
let
mut
path
=
path
.clone
();
for
seg
in
&
mut
path
.segments
{
seg
.id
=
self
.sess
.next_node_id
();
...
...
@@ -3616,19 +3614,7 @@ fn lower_use_tree(
let
path
=
this
.lower_path_extra
(
res
,
&
path
,
ParamMode
::
Explicit
,
None
);
let
item
=
hir
::
ItemKind
::
Use
(
P
(
path
),
hir
::
UseKind
::
Single
);
let
vis_kind
=
match
vis
.node
{
hir
::
VisibilityKind
::
Public
=>
hir
::
VisibilityKind
::
Public
,
hir
::
VisibilityKind
::
Crate
(
sugar
)
=>
hir
::
VisibilityKind
::
Crate
(
sugar
),
hir
::
VisibilityKind
::
Inherited
=>
hir
::
VisibilityKind
::
Inherited
,
hir
::
VisibilityKind
::
Restricted
{
ref
path
,
hir_id
:
_
}
=>
{
let
path
=
this
.renumber_segment_ids
(
path
);
hir
::
VisibilityKind
::
Restricted
{
path
,
hir_id
:
this
.next_id
(),
}
}
};
let
vis
=
respan
(
vis
.span
,
vis_kind
);
let
vis
=
this
.rebuild_vis
(
&
vis
);
this
.insert_item
(
hir
::
Item
{
...
...
@@ -3692,8 +3678,6 @@ fn lower_use_tree(
for
&
(
ref
use_tree
,
id
)
in
trees
{
let
new_hir_id
=
self
.lower_node_id
(
id
);
let
mut
vis
=
vis
.clone
();
let
mut
ident
=
ident
.clone
();
let
mut
prefix
=
prefix
.clone
();
// Give the segments new node-ids since they are being cloned.
...
...
@@ -3707,6 +3691,9 @@ fn lower_use_tree(
// own its own names, we have to adjust the owner before
// lowering the rest of the import.
self
.with_hir_id_owner
(
id
,
|
this
|
{
let
mut
vis
=
this
.rebuild_vis
(
&
vis
);
let
mut
ident
=
*
ident
;
let
item
=
this
.lower_use_tree
(
use_tree
,
&
prefix
,
id
,
...
...
@@ -3714,20 +3701,6 @@ fn lower_use_tree(
&
mut
ident
,
attrs
);
let
vis_kind
=
match
vis
.node
{
hir
::
VisibilityKind
::
Public
=>
hir
::
VisibilityKind
::
Public
,
hir
::
VisibilityKind
::
Crate
(
sugar
)
=>
hir
::
VisibilityKind
::
Crate
(
sugar
),
hir
::
VisibilityKind
::
Inherited
=>
hir
::
VisibilityKind
::
Inherited
,
hir
::
VisibilityKind
::
Restricted
{
ref
path
,
hir_id
:
_
}
=>
{
let
path
=
this
.renumber_segment_ids
(
path
);
hir
::
VisibilityKind
::
Restricted
{
path
:
path
,
hir_id
:
this
.next_id
(),
}
}
};
let
vis
=
respan
(
vis
.span
,
vis_kind
);
this
.insert_item
(
hir
::
Item
{
hir_id
:
new_hir_id
,
...
...
@@ -3773,15 +3746,35 @@ fn lower_use_tree(
/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
/// many times in the HIR tree; for each occurrence, we need to assign distinct
/// `NodeId`s. (See, e.g., #56128.)
fn
renumber_segment_ids
(
&
mut
self
,
path
:
&
P
<
hir
::
Path
>
)
->
P
<
hir
::
Path
>
{
debug!
(
"renumber_segment_ids(path = {:?})"
,
path
);
let
mut
path
=
path
.clone
();
for
seg
in
path
.segments
.iter_mut
()
{
if
seg
.hir_id
.is_some
()
{
seg
.hir_id
=
Some
(
self
.next_id
());
}
fn
rebuild_use_path
(
&
mut
self
,
path
:
&
hir
::
Path
)
->
hir
::
Path
{
debug!
(
"rebuild_use_path(path = {:?})"
,
path
);
let
segments
=
path
.segments
.iter
()
.map
(|
seg
|
hir
::
PathSegment
{
ident
:
seg
.ident
,
hir_id
:
seg
.hir_id
.map
(|
_
|
self
.next_id
()),
res
:
seg
.res
,
args
:
None
,
infer_args
:
seg
.infer_args
,
})
.collect
();
hir
::
Path
{
span
:
path
.span
,
res
:
path
.res
,
segments
,
}
path
}
fn
rebuild_vis
(
&
mut
self
,
vis
:
&
hir
::
Visibility
)
->
hir
::
Visibility
{
let
vis_kind
=
match
vis
.node
{
hir
::
VisibilityKind
::
Public
=>
hir
::
VisibilityKind
::
Public
,
hir
::
VisibilityKind
::
Crate
(
sugar
)
=>
hir
::
VisibilityKind
::
Crate
(
sugar
),
hir
::
VisibilityKind
::
Inherited
=>
hir
::
VisibilityKind
::
Inherited
,
hir
::
VisibilityKind
::
Restricted
{
ref
path
,
hir_id
:
_
}
=>
{
hir
::
VisibilityKind
::
Restricted
{
path
:
P
(
self
.rebuild_use_path
(
path
)),
hir_id
:
self
.next_id
(),
}
}
};
respan
(
vis
.span
,
vis_kind
)
}
fn
lower_trait_item
(
&
mut
self
,
i
:
&
TraitItem
)
->
hir
::
TraitItem
{
...
...
src/librustc/hir/map/mod.rs
浏览文件 @
673c3fc2
...
...
@@ -51,11 +51,11 @@ fn parent_node(self) -> Option<HirId> {
}
}
fn
fn_decl
(
&
self
)
->
Option
<&
FnDecl
>
{
fn
fn_decl
(
&
self
)
->
Option
<&
'hir
FnDecl
>
{
match
self
.node
{
Node
::
Item
(
ref
item
)
=>
{
match
item
.node
{
ItemKind
::
Fn
(
ref
fn_decl
,
_
,
_
,
_
)
=>
Some
(
&
fn_decl
),
ItemKind
::
Fn
(
ref
fn_decl
,
_
,
_
,
_
)
=>
Some
(
fn_decl
),
_
=>
None
,
}
}
...
...
@@ -76,7 +76,7 @@ fn fn_decl(&self) -> Option<&FnDecl> {
Node
::
Expr
(
ref
expr
)
=>
{
match
expr
.node
{
ExprKind
::
Closure
(
_
,
ref
fn_decl
,
..
)
=>
Some
(
&
fn_decl
),
ExprKind
::
Closure
(
_
,
ref
fn_decl
,
..
)
=>
Some
(
fn_decl
),
_
=>
None
,
}
}
...
...
@@ -412,9 +412,9 @@ pub fn body(&self, id: BodyId) -> &'hir Body {
self
.forest.krate
.body
(
id
)
}
pub
fn
fn_decl_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
FnDecl
>
{
pub
fn
fn_decl_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
&
'hir
FnDecl
>
{
if
let
Some
(
entry
)
=
self
.find_entry
(
hir_id
)
{
entry
.fn_decl
()
.cloned
()
entry
.fn_decl
()
}
else
{
bug!
(
"no entry for hir_id `{}`"
,
hir_id
)
}
...
...
src/librustc/hir/mod.rs
浏览文件 @
673c3fc2
此差异已折叠。
点击以展开。
src/librustc/hir/print.rs
浏览文件 @
673c3fc2
...
...
@@ -625,10 +625,10 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
self
.word_space
(
"for ?"
)
?
;
self
.print_trait_ref
(
&
ptr
.trait_ref
)
?
;
}
else
{
real_bounds
.push
(
b
.clone
()
);
real_bounds
.push
(
b
);
}
}
self
.print_bounds
(
":"
,
&
real_bounds
[
..
]
)
?
;
self
.print_bounds
(
":"
,
real_bounds
)
?
;
self
.s
.word
(
";"
)
?
;
self
.end
()
?
;
// end the outer ibox
}
...
...
@@ -698,10 +698,10 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
self
.word_space
(
"for ?"
)
?
;
self
.print_trait_ref
(
&
ptr
.trait_ref
)
?
;
}
else
{
real_bounds
.push
(
b
.clone
()
);
real_bounds
.push
(
b
);
}
}
self
.print_bounds
(
":"
,
&
real_bounds
[
..
]
)
?
;
self
.print_bounds
(
":"
,
real_bounds
)
?
;
self
.print_where_clause
(
&
generics
.where_clause
)
?
;
self
.s
.word
(
" "
)
?
;
self
.bopen
()
?
;
...
...
@@ -724,11 +724,11 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
self
.word_space
(
"for ?"
)
?
;
self
.print_trait_ref
(
&
ptr
.trait_ref
)
?
;
}
else
{
real_bounds
.push
(
b
.clone
()
);
real_bounds
.push
(
b
);
}
}
self
.nbsp
()
?
;
self
.print_bounds
(
"="
,
&
real_bounds
[
..
]
)
?
;
self
.print_bounds
(
"="
,
real_bounds
)
?
;
self
.print_where_clause
(
&
generics
.where_clause
)
?
;
self
.s
.word
(
";"
)
?
;
}
...
...
@@ -1998,31 +1998,34 @@ pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureClause) -> io
}
}
pub
fn
print_bounds
(
&
mut
self
,
prefix
:
&
'static
str
,
bounds
:
&
[
hir
::
GenericBound
])
->
io
::
Result
<
()
>
{
if
!
bounds
.is_empty
()
{
self
.s
.word
(
prefix
)
?
;
let
mut
first
=
true
;
for
bound
in
bounds
{
if
!
(
first
&&
prefix
.is_empty
())
{
self
.nbsp
()
?
;
}
if
first
{
first
=
false
;
}
else
{
self
.word_space
(
"+"
)
?
;
}
pub
fn
print_bounds
<
'b
>
(
&
mut
self
,
prefix
:
&
'static
str
,
bounds
:
impl
IntoIterator
<
Item
=
&
'b
hir
::
GenericBound
>
,
)
->
io
::
Result
<
()
>
{
let
mut
first
=
true
;
for
bound
in
bounds
{
if
first
{
self
.s
.word
(
prefix
)
?
;
}
if
!
(
first
&&
prefix
.is_empty
())
{
self
.nbsp
()
?
;
}
if
first
{
first
=
false
;
}
else
{
self
.word_space
(
"+"
)
?
;
}
match
bound
{
GenericBound
::
Trait
(
tref
,
modifier
)
=>
{
if
modifier
==
&
TraitBoundModifier
::
Maybe
{
self
.s
.word
(
"?"
)
?
;
}
self
.print_poly_trait_ref
(
tref
)
?
;
}
GenericBound
::
Outlives
(
lt
)
=>
{
self
.print_lifetime
(
lt
)
?
;
match
bound
{
GenericBound
::
Trait
(
tref
,
modifier
)
=>
{
if
modifier
==
&
TraitBoundModifier
::
Maybe
{
self
.s
.word
(
"?"
)
?
;
}
self
.print_poly_trait_ref
(
tref
)
?
;
}
GenericBound
::
Outlives
(
lt
)
=>
{
self
.print_lifetime
(
lt
)
?
;
}
}
}
...
...
src/librustc/traits/error_reporting.rs
浏览文件 @
673c3fc2
...
...
@@ -1050,10 +1050,10 @@ pub fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>) {
(
self
.tcx.sess
.source_map
()
.def_span
(
span
),
self
.tcx
.hir
()
.body
(
id
)
.arguments
.iter
()
.map
(|
arg
|
{
if
let
hir
::
Pat
{
node
:
hir
::
PatKind
::
Tuple
(
args
,
_
),
node
:
hir
::
PatKind
::
Tuple
(
ref
args
,
_
),
span
,
..
}
=
arg
.pat
.clone
()
.into_inner
()
{
}
=
*
arg
.pat
{
ArgKind
::
Tuple
(
Some
(
span
),
args
.iter
()
.map
(|
pat
|
{
...
...
src/librustc_mir/borrow_check/conflict_errors.rs
浏览文件 @
673c3fc2
...
...
@@ -1815,8 +1815,8 @@ fn annotate_fn_sig(
// as the HIR doesn't have full types for closure arguments.
let
return_ty
=
*
sig
.output
()
.skip_binder
();
let
mut
return_span
=
fn_decl
.output
.span
();
if
let
hir
::
FunctionRetTy
::
Return
(
ty
)
=
fn_decl
.output
{
if
let
hir
::
TyKind
::
Rptr
(
lifetime
,
_
)
=
ty
.
into_inner
()
.
node
{
if
let
hir
::
FunctionRetTy
::
Return
(
ty
)
=
&
fn_decl
.output
{
if
let
hir
::
TyKind
::
Rptr
(
lifetime
,
_
)
=
ty
.node
{
return_span
=
lifetime
.span
;
}
}
...
...
src/librustc_typeck/astconv.rs
浏览文件 @
673c3fc2
...
...
@@ -97,15 +97,15 @@ pub enum SizedByDefault {
No
,
}
struct
ConvertedBinding
<
'tcx
>
{
struct
ConvertedBinding
<
'
a
,
'
tcx
>
{
item_name
:
ast
::
Ident
,
kind
:
ConvertedBindingKind
<
'tcx
>
,
kind
:
ConvertedBindingKind
<
'
a
,
'
tcx
>
,
span
:
Span
,
}
enum
ConvertedBindingKind
<
'tcx
>
{
enum
ConvertedBindingKind
<
'
a
,
'
tcx
>
{
Equality
(
Ty
<
'tcx
>
),
Constraint
(
P
<
[
hir
::
GenericBound
]
>
),
Constraint
(
&
'a
[
hir
::
GenericBound
]
),
}
#[derive(PartialEq)]
...
...
@@ -596,7 +596,7 @@ fn create_substs_for_ast_path<'a>(&self,
generic_args
:
&
'a
hir
::
GenericArgs
,
infer_args
:
bool
,
self_ty
:
Option
<
Ty
<
'tcx
>>
)
->
(
SubstsRef
<
'tcx
>
,
Vec
<
ConvertedBinding
<
'tcx
>>
,
Option
<
Vec
<
Span
>>
)
->
(
SubstsRef
<
'tcx
>
,
Vec
<
ConvertedBinding
<
'
a
,
'
tcx
>>
,
Option
<
Vec
<
Span
>>
)
{
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
...
...
@@ -738,7 +738,7 @@ fn create_substs_for_ast_path<'a>(&self,
hir
::
TypeBindingKind
::
Equality
{
ref
ty
}
=>
ConvertedBindingKind
::
Equality
(
self
.ast_ty_to_ty
(
ty
)),
hir
::
TypeBindingKind
::
Constraint
{
ref
bounds
}
=>
ConvertedBindingKind
::
Constraint
(
bounds
.clone
()
),
ConvertedBindingKind
::
Constraint
(
bounds
),
};
ConvertedBinding
{
item_name
:
binding
.ident
,
...
...
@@ -859,13 +859,13 @@ fn ast_path_to_mono_trait_ref(&self,
ty
::
TraitRef
::
new
(
trait_def_id
,
substs
)
}
fn
create_substs_for_ast_trait_ref
(
fn
create_substs_for_ast_trait_ref
<
'a
>
(
&
self
,
span
:
Span
,
trait_def_id
:
DefId
,
self_ty
:
Ty
<
'tcx
>
,
trait_segment
:
&
hir
::
PathSegment
,
)
->
(
SubstsRef
<
'tcx
>
,
Vec
<
ConvertedBinding
<
'tcx
>>
,
Option
<
Vec
<
Span
>>
)
{
trait_segment
:
&
'a
hir
::
PathSegment
,
)
->
(
SubstsRef
<
'tcx
>
,
Vec
<
ConvertedBinding
<
'
a
,
'
tcx
>>
,
Option
<
Vec
<
Span
>>
)
{
debug!
(
"create_substs_for_ast_trait_ref(trait_segment={:?})"
,
trait_segment
);
...
...
@@ -912,7 +912,7 @@ pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound], span: Span) -> bool {
for
ab
in
ast_bounds
{
if
let
&
hir
::
GenericBound
::
Trait
(
ref
ptr
,
hir
::
TraitBoundModifier
::
Maybe
)
=
ab
{
if
unbound
.is_none
()
{
unbound
=
Some
(
ptr
.trait_ref
.clone
()
);
unbound
=
Some
(
&
ptr
.trait_ref
);
}
else
{
span_err!
(
tcx
.sess
,
...
...
@@ -927,7 +927,7 @@ pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound], span: Span) -> bool {
let
kind_id
=
tcx
.lang_items
()
.require
(
SizedTraitLangItem
);
match
unbound
{
Some
(
ref
tpb
)
=>
{
Some
(
tpb
)
=>
{
// FIXME(#8559) currently requires the unbound to be built-in.
if
let
Ok
(
kind_id
)
=
kind_id
{
if
tpb
.path.res
!=
Res
::
Def
(
DefKind
::
Trait
,
kind_id
)
{
...
...
@@ -1048,7 +1048,7 @@ fn add_predicates_for_ast_type_binding(
&
self
,
hir_ref_id
:
hir
::
HirId
,
trait_ref
:
ty
::
PolyTraitRef
<
'tcx
>
,
binding
:
&
ConvertedBinding
<
'tcx
>
,
binding
:
&
ConvertedBinding
<
'
_
,
'
tcx
>
,
bounds
:
&
mut
Bounds
<
'tcx
>
,
speculative
:
bool
,
dup_bindings
:
&
mut
FxHashMap
<
DefId
,
Span
>
,
...
...
@@ -1165,7 +1165,7 @@ fn add_predicates_for_ast_type_binding(
}
}),
binding
.span
));
}
ConvertedBindingKind
::
Constraint
(
ref
ast_bounds
)
=>
{
ConvertedBindingKind
::
Constraint
(
ast_bounds
)
=>
{
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
//
// `<T as Iterator>::Item: Debug`
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
673c3fc2
...
...
@@ -3696,39 +3696,39 @@ fn parent_item_span(&self, id: hir::HirId) -> Option<Span> {
}
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
fn
get_parent_fn_decl
(
&
self
,
blk_id
:
hir
::
HirId
)
->
Option
<
(
hir
::
FnDecl
,
ast
::
Ident
)
>
{
fn
get_parent_fn_decl
(
&
self
,
blk_id
:
hir
::
HirId
)
->
Option
<
(
&
'tcx
hir
::
FnDecl
,
ast
::
Ident
)
>
{
let
parent
=
self
.tcx
.hir
()
.get_by_hir_id
(
self
.tcx
.hir
()
.get_parent_item
(
blk_id
));
self
.get_node_fn_decl
(
parent
)
.map
(|(
fn_decl
,
ident
,
_
)|
(
fn_decl
,
ident
))
}
/// Given a function `Node`, return its `FnDecl` if it exists, or `None` otherwise.
fn
get_node_fn_decl
(
&
self
,
node
:
Node
<
'
_
>
)
->
Option
<
(
hir
::
FnDecl
,
ast
::
Ident
,
bool
)
>
{
fn
get_node_fn_decl
(
&
self
,
node
:
Node
<
'
tcx
>
)
->
Option
<
(
&
'tcx
hir
::
FnDecl
,
ast
::
Ident
,
bool
)
>
{
match
node
{
Node
::
Item
(
&
hir
::
Item
{
ident
,
node
:
hir
::
ItemKind
::
Fn
(
ref
decl
,
..
),
..
})
=>
decl
.clone
()
.and_then
(|
decl
|
{
})
=>
{
// This is less than ideal, it will not suggest a return type span on any
// method called `main`, regardless of whether it is actually the entry point,
// but it will still present it as the reason for the expected type.
Some
((
decl
,
ident
,
ident
.name
!=
sym
::
main
))
}
),
}
Node
::
TraitItem
(
&
hir
::
TraitItem
{
ident
,
node
:
hir
::
TraitItemKind
::
Method
(
hir
::
MethodSig
{
ref
decl
,
..
},
..
),
..
})
=>
decl
.clone
()
.and_then
(|
decl
|
Some
((
decl
,
ident
,
true
)
)),
})
=>
Some
((
decl
,
ident
,
true
)),
Node
::
ImplItem
(
&
hir
::
ImplItem
{
ident
,
node
:
hir
::
ImplItemKind
::
Method
(
hir
::
MethodSig
{
ref
decl
,
..
},
..
),
..
})
=>
decl
.clone
()
.and_then
(|
decl
|
Some
((
decl
,
ident
,
false
)
)),
})
=>
Some
((
decl
,
ident
,
false
)),
_
=>
None
,
}
}
/// Given a `HirId`, return the `FnDecl` of the method it is enclosed by and whether a
/// suggestion can be made, `None` otherwise.
pub
fn
get_fn_decl
(
&
self
,
blk_id
:
hir
::
HirId
)
->
Option
<
(
hir
::
FnDecl
,
bool
)
>
{
pub
fn
get_fn_decl
(
&
self
,
blk_id
:
hir
::
HirId
)
->
Option
<
(
&
'tcx
hir
::
FnDecl
,
bool
)
>
{
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
// `while` before reaching it, as block tail returns are not available in them.
self
.tcx
.hir
()
.get_return_block
(
blk_id
)
.and_then
(|
blk_id
|
{
...
...
src/librustc_typeck/collect.rs
浏览文件 @
673c3fc2
...
...
@@ -165,7 +165,7 @@ pub fn new(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> ItemCtxt<'tcx> {
ItemCtxt
{
tcx
,
item_def_id
}
}
pub
fn
to_ty
(
&
self
,
ast_ty
:
&
hir
::
Ty
)
->
Ty
<
'tcx
>
{
pub
fn
to_ty
(
&
self
,
ast_ty
:
&
'tcx
hir
::
Ty
)
->
Ty
<
'tcx
>
{
AstConv
::
ast_ty_to_ty
(
self
,
ast_ty
)
}
}
...
...
@@ -338,7 +338,7 @@ impl ItemCtxt<'tcx> {
/// bounds for a type parameter `X` if `X::Foo` is used.
fn
type_parameter_bounds_in_generics
(
&
self
,
ast_generics
:
&
hir
::
Generics
,
ast_generics
:
&
'tcx
hir
::
Generics
,
param_id
:
hir
::
HirId
,
ty
:
Ty
<
'tcx
>
,
only_self_bounds
:
OnlySelfBounds
,
...
...
@@ -1909,7 +1909,9 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
let
mut
is_default_impl_trait
=
None
;
let
icx
=
ItemCtxt
::
new
(
tcx
,
def_id
);
let
no_generics
=
hir
::
Generics
::
empty
();
const
NO_GENERICS
:
&
hir
::
Generics
=
&
hir
::
Generics
::
empty
();
let
empty_trait_items
=
HirVec
::
new
();
let
mut
predicates
=
UniquePredicates
::
new
();
...
...
@@ -1991,17 +1993,17 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
}
}
_
=>
&
no_generics
,
_
=>
NO_GENERICS
,
}
}
Node
::
ForeignItem
(
item
)
=>
match
item
.node
{
ForeignItemKind
::
Static
(
..
)
=>
&
no_generics
,
ForeignItemKind
::
Static
(
..
)
=>
NO_GENERICS
,
ForeignItemKind
::
Fn
(
_
,
_
,
ref
generics
)
=>
generics
,
ForeignItemKind
::
Type
=>
&
no_generics
,
ForeignItemKind
::
Type
=>
NO_GENERICS
,
},
_
=>
&
no_generics
,
_
=>
NO_GENERICS
,
};
let
generics
=
tcx
.generics_of
(
def_id
);
...
...
@@ -2205,7 +2207,7 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
fn
predicates_from_bound
<
'tcx
>
(
astconv
:
&
dyn
AstConv
<
'tcx
>
,
param_ty
:
Ty
<
'tcx
>
,
bound
:
&
hir
::
GenericBound
,
bound
:
&
'tcx
hir
::
GenericBound
,
)
->
Vec
<
(
ty
::
Predicate
<
'tcx
>
,
Span
)
>
{
match
*
bound
{
hir
::
GenericBound
::
Trait
(
ref
tr
,
hir
::
TraitBoundModifier
::
None
)
=>
{
...
...
@@ -2227,7 +2229,7 @@ fn predicates_from_bound<'tcx>(
fn
compute_sig_of_foreign_fn_decl
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
,
decl
:
&
hir
::
FnDecl
,
decl
:
&
'tcx
hir
::
FnDecl
,
abi
:
abi
::
Abi
,
)
->
ty
::
PolyFnSig
<
'tcx
>
{
let
unsafety
=
if
abi
==
abi
::
Abi
::
RustIntrinsic
{
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
673c3fc2
...
...
@@ -159,7 +159,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Crate {
// Clean the crate, translating the entire libsyntax AST to one that is
// understood by rustdoc.
let
mut
module
=
self
.module
.clean
(
cx
);
let
mut
module
=
self
.module
.
as_ref
()
.unwrap
()
.
clean
(
cx
);
let
mut
masked_crates
=
FxHashSet
::
default
();
match
module
.inner
{
...
...
@@ -600,7 +600,7 @@ pub struct Module {
pub
is_crate
:
bool
,
}
impl
Clean
<
Item
>
for
doctree
::
Module
{
impl
Clean
<
Item
>
for
doctree
::
Module
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
name
=
if
self
.name
.is_some
()
{
self
.name
.expect
(
"No name provided"
)
.clean
(
cx
)
...
...
@@ -620,7 +620,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
items
.extend
(
self
.unions
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.enums
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.fns
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.foreigns
.iter
()
.
flat_
map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.foreigns
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.mods
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.typedefs
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.existentials
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
...
...
@@ -1920,10 +1920,10 @@ pub struct Function {
pub
ret_types
:
Vec
<
Type
>
,
}
impl
Clean
<
Item
>
for
doctree
::
Function
{
impl
Clean
<
Item
>
for
doctree
::
Function
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
(
generics
,
decl
)
=
enter_impl_trait
(
cx
,
||
{
(
self
.generics
.clean
(
cx
),
(
&
self
.decl
,
self
.body
)
.clean
(
cx
))
(
self
.generics
.clean
(
cx
),
(
self
.decl
,
self
.body
)
.clean
(
cx
))
});
let
did
=
cx
.tcx
.hir
()
.local_def_id_from_hir_id
(
self
.id
);
...
...
@@ -2128,7 +2128,7 @@ pub struct Trait {
pub
is_auto
:
bool
,
}
impl
Clean
<
Item
>
for
doctree
::
Trait
{
impl
Clean
<
Item
>
for
doctree
::
Trait
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
attrs
=
self
.attrs
.clean
(
cx
);
let
is_spotlight
=
attrs
.has_doc_flag
(
sym
::
spotlight
);
...
...
@@ -2143,7 +2143,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
inner
:
TraitItem
(
Trait
{
auto
:
self
.is_auto
.clean
(
cx
),
unsafety
:
self
.unsafety
,
items
:
self
.items
.
clean
(
cx
),
items
:
self
.items
.
iter
()
.map
(|
ti
|
ti
.clean
(
cx
))
.collect
(
),
generics
:
self
.generics
.clean
(
cx
),
bounds
:
self
.bounds
.clean
(
cx
),
is_spotlight
,
...
...
@@ -2159,7 +2159,7 @@ pub struct TraitAlias {
pub
bounds
:
Vec
<
GenericBound
>
,
}
impl
Clean
<
Item
>
for
doctree
::
TraitAlias
{
impl
Clean
<
Item
>
for
doctree
::
TraitAlias
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
attrs
=
self
.attrs
.clean
(
cx
);
Item
{
...
...
@@ -2853,11 +2853,11 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
_
=>
None
,
}
});
if
let
Some
(
ty
)
=
type_
.cloned
()
{
if
let
Some
(
ty
)
=
type_
{
ty_substs
.insert
(
ty_param_def_id
,
ty
.clean
(
cx
));
}
else
if
let
Some
(
default
)
=
default
.clone
()
{
ty_substs
.insert
(
ty_param_def_id
,
default
.
into_inner
()
.
clean
(
cx
));
default
.clean
(
cx
));
}
indices
.types
+=
1
;
}
...
...
@@ -2877,7 +2877,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
_
=>
None
,
}
});
if
let
Some
(
ct
)
=
const_
.cloned
()
{
if
let
Some
(
ct
)
=
const_
{
ct_substs
.insert
(
const_param_def_id
,
ct
.clean
(
cx
));
}
// FIXME(const_generics:defaults)
...
...
@@ -2891,20 +2891,20 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
resolve_type
(
cx
,
path
.clean
(
cx
),
self
.hir_id
)
}
TyKind
::
Path
(
hir
::
QPath
::
Resolved
(
Some
(
ref
qself
),
ref
p
))
=>
{
let
mut
segments
:
Vec
<
_
>
=
p
.segments
.clone
()
.into
()
;
segments
.pop
()
;
let
trait_path
=
hir
::
Path
{
span
:
p
.span
,
let
segments
=
if
p
.is_global
()
{
&
p
.segments
[
1
..
]
}
else
{
&
p
.segments
}
;
let
trait_segments
=
&
segments
[
..
segments
.len
()
-
1
]
;
let
trait_path
=
self
::
Path
{
global
:
p
.is_global
()
,
res
:
Res
::
Def
(
DefKind
::
Trait
,
cx
.tcx
.associated_item
(
p
.res
.def_id
())
.container
.id
(),
),
segments
:
segments
.into
(
),
segments
:
trait_segments
.clean
(
cx
),
};
Type
::
QPath
{
name
:
p
.segments
.last
()
.expect
(
"segments were empty"
)
.ident.name
.clean
(
cx
),
self_type
:
box
qself
.clean
(
cx
),
trait_
:
box
resolve_type
(
cx
,
trait_path
.clean
(
cx
)
,
self
.hir_id
)
trait_
:
box
resolve_type
(
cx
,
trait_path
,
self
.hir_id
)
}
}
TyKind
::
Path
(
hir
::
QPath
::
TypeRelative
(
ref
qself
,
ref
segment
))
=>
{
...
...
@@ -3235,7 +3235,7 @@ pub struct Union {
pub
fields_stripped
:
bool
,
}
impl
Clean
<
Item
>
for
doctree
::
Struct
{
impl
Clean
<
Item
>
for
doctree
::
Struct
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3255,7 +3255,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
}
}
impl
Clean
<
Item
>
for
doctree
::
Union
{
impl
Clean
<
Item
>
for
doctree
::
Union
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3302,7 +3302,7 @@ pub struct Enum {
pub
variants_stripped
:
bool
,
}
impl
Clean
<
Item
>
for
doctree
::
Enum
{
impl
Clean
<
Item
>
for
doctree
::
Enum
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3326,7 +3326,7 @@ pub struct Variant {
pub
kind
:
VariantKind
,
}
impl
Clean
<
Item
>
for
doctree
::
Variant
{
impl
Clean
<
Item
>
for
doctree
::
Variant
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3631,7 +3631,7 @@ pub struct Typedef {
pub
generics
:
Generics
,
}
impl
Clean
<
Item
>
for
doctree
::
Typedef
{
impl
Clean
<
Item
>
for
doctree
::
Typedef
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3655,7 +3655,7 @@ pub struct Existential {
pub
generics
:
Generics
,
}
impl
Clean
<
Item
>
for
doctree
::
Existential
{
impl
Clean
<
Item
>
for
doctree
::
Existential
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3705,7 +3705,7 @@ pub struct Static {
pub
expr
:
String
,
}
impl
Clean
<
Item
>
for
doctree
::
Static
{
impl
Clean
<
Item
>
for
doctree
::
Static
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
debug!
(
"cleaning static {}: {:?}"
,
self
.name
.clean
(
cx
),
self
);
Item
{
...
...
@@ -3731,7 +3731,7 @@ pub struct Constant {
pub
expr
:
String
,
}
impl
Clean
<
Item
>
for
doctree
::
Constant
{
impl
Clean
<
Item
>
for
doctree
::
Constant
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
@@ -3801,11 +3801,11 @@ pub fn get_auto_trait_and_blanket_impls(
.chain
(
BlanketImplFinder
::
new
(
cx
)
.get_blanket_impls
(
ty
,
param_env_def_id
))
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Impl
{
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Impl
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Vec
<
Item
>
{
let
mut
ret
=
Vec
::
new
();
let
trait_
=
self
.trait_
.clean
(
cx
);
let
items
=
self
.items
.
clean
(
cx
);
let
items
=
self
.items
.
iter
()
.map
(|
ii
|
ii
.clean
(
cx
))
.collect
::
<
Vec
<
_
>>
(
);
// If this impl block is an implementation of the Deref trait, then we
// need to try inlining the target's inherent impl blocks as well.
...
...
@@ -3902,7 +3902,7 @@ fn build_deref_target_impls(cx: &DocContext<'_>,
}
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
ExternCrate
{
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
ExternCrate
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Vec
<
Item
>
{
let
please_inline
=
self
.vis.node
.is_pub
()
&&
self
.attrs
.iter
()
.any
(|
a
|
{
...
...
@@ -3941,7 +3941,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
}
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Import
{
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Import
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Vec
<
Item
>
{
// We consider inlining the documentation of `pub use` statements, but we
// forcefully don't inline if this is not public or if the
...
...
@@ -4017,22 +4017,11 @@ pub struct ImportSource {
pub
did
:
Option
<
DefId
>
,
}
impl
Clean
<
Vec
<
Item
>>
for
hir
::
ForeignMod
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Vec
<
Item
>
{
let
mut
items
=
self
.items
.clean
(
cx
);
for
item
in
&
mut
items
{
if
let
ForeignFunctionItem
(
ref
mut
f
)
=
item
.inner
{
f
.header.abi
=
self
.abi
;
}
}
items
}
}
impl
Clean
<
Item
>
for
hir
::
ForeignItem
{
impl
Clean
<
Item
>
for
doctree
::
ForeignItem
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
inner
=
match
self
.
node
{
let
inner
=
match
self
.
kind
{
hir
::
ForeignItemKind
::
Fn
(
ref
decl
,
ref
names
,
ref
generics
)
=>
{
let
abi
=
cx
.tcx
.hir
()
.get_foreign_abi
(
self
.id
);
let
(
generics
,
decl
)
=
enter_impl_trait
(
cx
,
||
{
(
generics
.clean
(
cx
),
(
&**
decl
,
&
names
[
..
])
.clean
(
cx
))
});
...
...
@@ -4042,7 +4031,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
generics
,
header
:
hir
::
FnHeader
{
unsafety
:
hir
::
Unsafety
::
Unsafe
,
abi
:
Abi
::
Rust
,
abi
,
constness
:
hir
::
Constness
::
NotConst
,
asyncness
:
hir
::
IsAsync
::
NotAsync
,
},
...
...
@@ -4062,16 +4051,14 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
}
};
let
local_did
=
cx
.tcx
.hir
()
.local_def_id_from_hir_id
(
self
.hir_id
);
Item
{
name
:
Some
(
self
.
ident
.clean
(
cx
)),
name
:
Some
(
self
.
name
.clean
(
cx
)),
attrs
:
self
.attrs
.clean
(
cx
),
source
:
self
.
span
.clean
(
cx
),
def_id
:
local_did
,
source
:
self
.
whence
.clean
(
cx
),
def_id
:
cx
.tcx
.hir
()
.local_def_id_from_hir_id
(
self
.id
)
,
visibility
:
self
.vis
.clean
(
cx
),
stability
:
get_stability
(
cx
,
local_did
),
deprecation
:
get_deprecation
(
cx
,
local_did
),
stability
:
self
.stab
.clean
(
cx
),
deprecation
:
self
.depr
.clean
(
cx
),
inner
,
}
}
...
...
@@ -4246,7 +4233,7 @@ pub struct Macro {
pub
imported_from
:
Option
<
String
>
,
}
impl
Clean
<
Item
>
for
doctree
::
Macro
{
impl
Clean
<
Item
>
for
doctree
::
Macro
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
let
name
=
self
.name
.clean
(
cx
);
Item
{
...
...
@@ -4275,7 +4262,7 @@ pub struct ProcMacro {
pub
helpers
:
Vec
<
String
>
,
}
impl
Clean
<
Item
>
for
doctree
::
ProcMacro
{
impl
Clean
<
Item
>
for
doctree
::
ProcMacro
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
...
...
src/librustdoc/doctree.rs
浏览文件 @
673c3fc2
...
...
@@ -7,52 +7,55 @@
use
syntax
::
attr
;
use
syntax
::
ext
::
base
::
MacroKind
;
use
syntax
::
ptr
::
P
;
use
syntax
::
source_map
::
Spanned
;
use
syntax_pos
::{
self
,
Span
};
use
rustc
::
hir
;
use
rustc
::
hir
::
def_id
::
CrateNum
;
pub
struct
Module
{
pub
struct
Module
<
'hir
>
{
pub
name
:
Option
<
Name
>
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
where_outer
:
Span
,
pub
where_inner
:
Span
,
pub
extern_crates
:
Vec
<
ExternCrate
>
,
pub
imports
:
Vec
<
Import
>
,
pub
structs
:
Vec
<
Struct
>
,
pub
unions
:
Vec
<
Union
>
,
pub
enums
:
Vec
<
Enum
>
,
pub
fns
:
Vec
<
Function
>
,
pub
mods
:
Vec
<
Module
>
,
pub
extern_crates
:
Vec
<
ExternCrate
<
'hir
>
>
,
pub
imports
:
Vec
<
Import
<
'hir
>
>
,
pub
structs
:
Vec
<
Struct
<
'hir
>
>
,
pub
unions
:
Vec
<
Union
<
'hir
>
>
,
pub
enums
:
Vec
<
Enum
<
'hir
>
>
,
pub
fns
:
Vec
<
Function
<
'hir
>
>
,
pub
mods
:
Vec
<
Module
<
'hir
>
>
,
pub
id
:
NodeId
,
pub
typedefs
:
Vec
<
Typedef
>
,
pub
existentials
:
Vec
<
Existential
>
,
pub
statics
:
Vec
<
Static
>
,
pub
constants
:
Vec
<
Constant
>
,
pub
traits
:
Vec
<
Trait
>
,
pub
vis
:
hir
::
Visibility
,
pub
typedefs
:
Vec
<
Typedef
<
'hir
>
>
,
pub
existentials
:
Vec
<
Existential
<
'hir
>
>
,
pub
statics
:
Vec
<
Static
<
'hir
>
>
,
pub
constants
:
Vec
<
Constant
<
'hir
>
>
,
pub
traits
:
Vec
<
Trait
<
'hir
>
>
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
impls
:
Vec
<
Impl
>
,
pub
foreigns
:
Vec
<
hir
::
ForeignMod
>
,
pub
macros
:
Vec
<
Macro
>
,
pub
proc_macros
:
Vec
<
ProcMacro
>
,
pub
trait_aliases
:
Vec
<
TraitAlias
>
,
pub
impls
:
Vec
<
Impl
<
'hir
>
>
,
pub
foreigns
:
Vec
<
ForeignItem
<
'hir
>
>
,
pub
macros
:
Vec
<
Macro
<
'hir
>
>
,
pub
proc_macros
:
Vec
<
ProcMacro
<
'hir
>
>
,
pub
trait_aliases
:
Vec
<
TraitAlias
<
'hir
>
>
,
pub
is_crate
:
bool
,
}
impl
Module
{
pub
fn
new
(
name
:
Option
<
Name
>
)
->
Module
{
impl
Module
<
'hir
>
{
pub
fn
new
(
name
:
Option
<
Name
>
,
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
vis
:
&
'hir
hir
::
Visibility
,
)
->
Module
<
'hir
>
{
Module
{
name
:
name
,
id
:
ast
::
CRATE_NODE_ID
,
vis
:
Spanned
{
span
:
syntax_pos
::
DUMMY_SP
,
node
:
hir
::
VisibilityKind
::
Inherited
}
,
vis
,
stab
:
None
,
depr
:
None
,
where_outer
:
syntax_pos
::
DUMMY_SP
,
where_inner
:
syntax_pos
::
DUMMY_SP
,
attrs
:
hir
::
HirVec
::
new
()
,
attrs
,
extern_crates
:
Vec
::
new
(),
imports
:
Vec
::
new
(),
structs
:
Vec
::
new
(),
...
...
@@ -85,167 +88,178 @@ pub enum StructType {
Unit
,
}
pub
struct
Struct
{
pub
vis
:
hir
::
Visibility
,
pub
struct
Struct
<
'hir
>
{
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
pub
struct_type
:
StructType
,
pub
name
:
Name
,
pub
generics
:
hir
::
Generics
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
fields
:
hir
::
HirVec
<
hir
::
StructField
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
fields
:
&
'hir
[
hir
::
StructField
]
,
pub
whence
:
Span
,
}
pub
struct
Union
{
pub
vis
:
hir
::
Visibility
,
pub
struct
Union
<
'hir
>
{
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
pub
struct_type
:
StructType
,
pub
name
:
Name
,
pub
generics
:
hir
::
Generics
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
fields
:
hir
::
HirVec
<
hir
::
StructField
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
fields
:
&
'hir
[
hir
::
StructField
]
,
pub
whence
:
Span
,
}
pub
struct
Enum
{
pub
vis
:
hir
::
Visibility
,
pub
struct
Enum
<
'hir
>
{
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
variants
:
hir
::
HirVec
<
Variant
>
,
pub
generics
:
hir
::
Generics
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
variants
:
Vec
<
Variant
<
'hir
>
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
id
:
hir
::
HirId
,
pub
whence
:
Span
,
pub
name
:
Name
,
}
pub
struct
Variant
{
pub
struct
Variant
<
'hir
>
{
pub
name
:
Name
,
pub
id
:
hir
::
HirId
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
def
:
hir
::
VariantData
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
def
:
&
'hir
hir
::
VariantData
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
whence
:
Span
,
}
pub
struct
Function
{
pub
decl
:
hir
::
FnDecl
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
struct
Function
<
'hir
>
{
pub
decl
:
&
'hir
hir
::
FnDecl
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
id
:
hir
::
HirId
,
pub
name
:
Name
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
header
:
hir
::
FnHeader
,
pub
whence
:
Span
,
pub
generics
:
hir
::
Generics
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
body
:
hir
::
BodyId
,
}
pub
struct
Typedef
{
pub
ty
:
P
<
hir
::
Ty
>
,
pub
gen
:
hir
::
Generics
,
pub
struct
Typedef
<
'hir
>
{
pub
ty
:
&
'hir
P
<
hir
::
Ty
>
,
pub
gen
:
&
'hir
hir
::
Generics
,
pub
name
:
Name
,
pub
id
:
hir
::
HirId
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
}
pub
struct
Existential
{
pub
exist_ty
:
hir
::
ExistTy
,
pub
struct
Existential
<
'hir
>
{
pub
exist_ty
:
&
'hir
hir
::
ExistTy
,
pub
name
:
Name
,
pub
id
:
hir
::
HirId
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
}
#[derive(Debug)]
pub
struct
Static
{
pub
type_
:
P
<
hir
::
Ty
>
,
pub
struct
Static
<
'hir
>
{
pub
type_
:
&
'hir
P
<
hir
::
Ty
>
,
pub
mutability
:
hir
::
Mutability
,
pub
expr
:
hir
::
BodyId
,
pub
name
:
Name
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
vis
:
hir
::
Visibility
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
pub
whence
:
Span
,
}
pub
struct
Constant
{
pub
type_
:
P
<
hir
::
Ty
>
,
pub
struct
Constant
<
'hir
>
{
pub
type_
:
&
'hir
P
<
hir
::
Ty
>
,
pub
expr
:
hir
::
BodyId
,
pub
name
:
Name
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
vis
:
hir
::
Visibility
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
pub
whence
:
Span
,
}
pub
struct
Trait
{
pub
struct
Trait
<
'hir
>
{
pub
is_auto
:
hir
::
IsAuto
,
pub
unsafety
:
hir
::
Unsafety
,
pub
name
:
Name
,
pub
items
:
hir
::
HirVec
<
hir
::
TraitItem
>
,
pub
generics
:
hir
::
Generics
,
pub
bounds
:
hir
::
HirVec
<
hir
::
GenericBound
>
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
items
:
Vec
<&
'hir
hir
::
TraitItem
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
bounds
:
&
'hir
hir
::
HirVec
<
hir
::
GenericBound
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
id
:
hir
::
HirId
,
pub
whence
:
Span
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
}
pub
struct
TraitAlias
{
pub
struct
TraitAlias
<
'hir
>
{
pub
name
:
Name
,
pub
generics
:
hir
::
Generics
,
pub
bounds
:
hir
::
HirVec
<
hir
::
GenericBound
>
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
bounds
:
&
'hir
hir
::
HirVec
<
hir
::
GenericBound
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
id
:
hir
::
HirId
,
pub
whence
:
Span
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
}
#[derive(Debug)]
pub
struct
Impl
{
pub
struct
Impl
<
'hir
>
{
pub
unsafety
:
hir
::
Unsafety
,
pub
polarity
:
hir
::
ImplPolarity
,
pub
defaultness
:
hir
::
Defaultness
,
pub
generics
:
hir
::
Generics
,
pub
trait_
:
Option
<
hir
::
TraitRef
>
,
pub
for_
:
P
<
hir
::
Ty
>
,
pub
items
:
hir
::
HirVec
<
hir
::
ImplItem
>
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
generics
:
&
'hir
hir
::
Generics
,
pub
trait_
:
&
'hir
Option
<
hir
::
TraitRef
>
,
pub
for_
:
&
'hir
P
<
hir
::
Ty
>
,
pub
items
:
Vec
<&
'hir
hir
::
ImplItem
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
pub
vis
:
hir
::
Visibility
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
}
pub
struct
ForeignItem
<
'hir
>
{
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
pub
id
:
hir
::
HirId
,
pub
name
:
Name
,
pub
kind
:
&
'hir
hir
::
ForeignItemKind
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
}
// For Macro we store the DefId instead of the NodeId, since we also create
// these imported macro_rules (which only have a DUMMY_NODE_ID).
pub
struct
Macro
{
pub
struct
Macro
<
'hir
>
{
pub
name
:
Name
,
pub
def_id
:
hir
::
def_id
::
DefId
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
pub
matchers
:
hir
::
HirVec
<
Span
>
,
pub
stab
:
Option
<
attr
::
Stability
>
,
...
...
@@ -253,31 +267,31 @@ pub struct Macro {
pub
imported_from
:
Option
<
Name
>
,
}
pub
struct
ExternCrate
{
pub
struct
ExternCrate
<
'hir
>
{
pub
name
:
Name
,
pub
cnum
:
CrateNum
,
pub
path
:
Option
<
String
>
,
pub
vis
:
hir
::
Visibility
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
}
pub
struct
Import
{
pub
struct
Import
<
'hir
>
{
pub
name
:
Name
,
pub
id
:
hir
::
HirId
,
pub
vis
:
hir
::
Visibility
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
path
:
hir
::
Path
,
pub
vis
:
&
'hir
hir
::
Visibility
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
path
:
&
'hir
hir
::
Path
,
pub
glob
:
bool
,
pub
whence
:
Span
,
}
pub
struct
ProcMacro
{
pub
struct
ProcMacro
<
'hir
>
{
pub
name
:
Name
,
pub
id
:
hir
::
HirId
,
pub
kind
:
MacroKind
,
pub
helpers
:
Vec
<
Name
>
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
attrs
:
&
'hir
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
whence
:
Span
,
pub
stab
:
Option
<
attr
::
Stability
>
,
pub
depr
:
Option
<
attr
::
Deprecation
>
,
...
...
src/librustdoc/visit_ast.rs
浏览文件 @
673c3fc2
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录