Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bb301446
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,发现更多精彩内容 >>
提交
bb301446
编写于
9月 25, 2017
作者:
S
Sunjay Varma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lifted generics into TraitItem and ImplItem from MethodSig -- HIR now matches AST
上级
892e4689
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
42 addition
and
71 deletion
+42
-71
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+4
-4
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+6
-5
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+2
-1
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+5
-4
src/librustc/ich/impls_hir.rs
src/librustc/ich/impls_hir.rs
+5
-2
src/librustc/middle/reachable.rs
src/librustc/middle/reachable.rs
+5
-6
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+2
-2
src/librustc_typeck/check/compare_method.rs
src/librustc_typeck/check/compare_method.rs
+5
-9
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+8
-38
未找到文件。
src/librustc/hir/intravisit.rs
浏览文件 @
bb301446
...
...
@@ -780,9 +780,7 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'
FnKind
::
ItemFn
(
_
,
generics
,
..
)
=>
{
visitor
.visit_generics
(
generics
);
}
FnKind
::
Method
(
_
,
sig
,
..
)
=>
{
visitor
.visit_generics
(
&
sig
.generics
);
}
FnKind
::
Method
(
..
)
|
FnKind
::
Closure
(
_
)
=>
{}
}
}
...
...
@@ -802,6 +800,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
pub
fn
walk_trait_item
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
trait_item
:
&
'v
TraitItem
)
{
visitor
.visit_name
(
trait_item
.span
,
trait_item
.name
);
walk_list!
(
visitor
,
visit_attribute
,
&
trait_item
.attrs
);
visitor
.visit_generics
(
&
trait_item
.generics
);
match
trait_item
.node
{
TraitItemKind
::
Const
(
ref
ty
,
default
)
=>
{
visitor
.visit_id
(
trait_item
.id
);
...
...
@@ -810,7 +809,6 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
}
TraitItemKind
::
Method
(
ref
sig
,
TraitMethod
::
Required
(
ref
names
))
=>
{
visitor
.visit_id
(
trait_item
.id
);
visitor
.visit_generics
(
&
sig
.generics
);
visitor
.visit_fn_decl
(
&
sig
.decl
);
for
name
in
names
{
visitor
.visit_name
(
name
.span
,
name
.node
);
...
...
@@ -852,6 +850,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
ref
vis
,
ref
defaultness
,
ref
attrs
,
ref
generics
,
ref
node
,
span
}
=
*
impl_item
;
...
...
@@ -860,6 +859,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor
.visit_vis
(
vis
);
visitor
.visit_defaultness
(
defaultness
);
walk_list!
(
visitor
,
visit_attribute
,
attrs
);
visitor
.visit_generics
(
generics
);
match
*
node
{
ImplItemKind
::
Const
(
ref
ty
,
body
)
=>
{
visitor
.visit_id
(
impl_item
.id
);
...
...
src/librustc/hir/lowering.rs
浏览文件 @
bb301446
...
...
@@ -1539,6 +1539,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
hir_id
,
name
:
this
.lower_ident
(
i
.ident
),
attrs
:
this
.lower_attrs
(
&
i
.attrs
),
generics
:
this
.lower_generics
(
&
i
.generics
),
node
:
match
i
.node
{
TraitItemKind
::
Const
(
ref
ty
,
ref
default
)
=>
{
hir
::
TraitItemKind
::
Const
(
this
.lower_ty
(
ty
),
...
...
@@ -1548,7 +1549,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
}
TraitItemKind
::
Method
(
ref
sig
,
None
)
=>
{
let
names
=
this
.lower_fn_args_to_names
(
&
sig
.decl
);
hir
::
TraitItemKind
::
Method
(
this
.lower_method_sig
(
&
i
.generics
,
sig
),
hir
::
TraitItemKind
::
Method
(
this
.lower_method_sig
(
sig
),
hir
::
TraitMethod
::
Required
(
names
))
}
TraitItemKind
::
Method
(
ref
sig
,
Some
(
ref
body
))
=>
{
...
...
@@ -1556,7 +1557,7 @@ fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem {
let
body
=
this
.lower_block
(
body
,
false
);
this
.expr_block
(
body
,
ThinVec
::
new
())
});
hir
::
TraitItemKind
::
Method
(
this
.lower_method_sig
(
&
i
.generics
,
sig
),
hir
::
TraitItemKind
::
Method
(
this
.lower_method_sig
(
sig
),
hir
::
TraitMethod
::
Provided
(
body_id
))
}
TraitItemKind
::
Type
(
ref
bounds
,
ref
default
)
=>
{
...
...
@@ -1603,6 +1604,7 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
hir_id
,
name
:
this
.lower_ident
(
i
.ident
),
attrs
:
this
.lower_attrs
(
&
i
.attrs
),
generics
:
this
.lower_generics
(
&
i
.generics
),
vis
:
this
.lower_visibility
(
&
i
.vis
,
None
),
defaultness
:
this
.lower_defaultness
(
i
.defaultness
,
true
/* [1] */
),
node
:
match
i
.node
{
...
...
@@ -1615,7 +1617,7 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem {
let
body
=
this
.lower_block
(
body
,
false
);
this
.expr_block
(
body
,
ThinVec
::
new
())
});
hir
::
ImplItemKind
::
Method
(
this
.lower_method_sig
(
&
i
.generics
,
sig
),
body_id
)
hir
::
ImplItemKind
::
Method
(
this
.lower_method_sig
(
sig
),
body_id
)
}
ImplItemKind
::
Type
(
ref
ty
)
=>
hir
::
ImplItemKind
::
Type
(
this
.lower_ty
(
ty
)),
ImplItemKind
::
Macro
(
..
)
=>
panic!
(
"Shouldn't exist any more"
),
...
...
@@ -1727,9 +1729,8 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem {
})
}
fn
lower_method_sig
(
&
mut
self
,
generics
:
&
Generics
,
sig
:
&
MethodSig
)
->
hir
::
MethodSig
{
fn
lower_method_sig
(
&
mut
self
,
sig
:
&
MethodSig
)
->
hir
::
MethodSig
{
hir
::
MethodSig
{
generics
:
self
.lower_generics
(
generics
),
abi
:
sig
.abi
,
unsafety
:
self
.lower_unsafety
(
sig
.unsafety
),
constness
:
self
.lower_constness
(
sig
.constness
),
...
...
src/librustc/hir/mod.rs
浏览文件 @
bb301446
...
...
@@ -1295,7 +1295,6 @@ pub struct MethodSig {
pub
constness
:
Constness
,
pub
abi
:
Abi
,
pub
decl
:
P
<
FnDecl
>
,
pub
generics
:
Generics
,
}
// The bodies for items are stored "out of line", in a separate
...
...
@@ -1316,6 +1315,7 @@ pub struct TraitItem {
pub
name
:
Name
,
pub
hir_id
:
HirId
,
pub
attrs
:
HirVec
<
Attribute
>
,
pub
generics
:
Generics
,
pub
node
:
TraitItemKind
,
pub
span
:
Span
,
}
...
...
@@ -1360,6 +1360,7 @@ pub struct ImplItem {
pub
vis
:
Visibility
,
pub
defaultness
:
Defaultness
,
pub
attrs
:
HirVec
<
Attribute
>
,
pub
generics
:
Generics
,
pub
node
:
ImplItemKind
,
pub
span
:
Span
,
}
...
...
src/librustc/hir/print.rs
浏览文件 @
bb301446
...
...
@@ -880,6 +880,7 @@ pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
pub
fn
print_method_sig
(
&
mut
self
,
name
:
ast
::
Name
,
m
:
&
hir
::
MethodSig
,
generics
:
&
hir
::
Generics
,
vis
:
&
hir
::
Visibility
,
arg_names
:
&
[
Spanned
<
ast
::
Name
>
],
body_id
:
Option
<
hir
::
BodyId
>
)
...
...
@@ -889,7 +890,7 @@ pub fn print_method_sig(&mut self,
m
.constness
,
m
.abi
,
Some
(
name
),
&
m
.
generics
,
generics
,
vis
,
arg_names
,
body_id
)
...
...
@@ -905,12 +906,12 @@ pub fn print_trait_item(&mut self, ti: &hir::TraitItem) -> io::Result<()> {
self
.print_associated_const
(
ti
.name
,
&
ty
,
default
,
&
hir
::
Inherited
)
?
;
}
hir
::
TraitItemKind
::
Method
(
ref
sig
,
hir
::
TraitMethod
::
Required
(
ref
arg_names
))
=>
{
self
.print_method_sig
(
ti
.name
,
sig
,
&
hir
::
Inherited
,
arg_names
,
None
)
?
;
self
.print_method_sig
(
ti
.name
,
sig
,
&
ti
.generics
,
&
hir
::
Inherited
,
arg_names
,
None
)
?
;
self
.s
.word
(
";"
)
?
;
}
hir
::
TraitItemKind
::
Method
(
ref
sig
,
hir
::
TraitMethod
::
Provided
(
body
))
=>
{
self
.head
(
""
)
?
;
self
.print_method_sig
(
ti
.name
,
sig
,
&
hir
::
Inherited
,
&
[],
Some
(
body
))
?
;
self
.print_method_sig
(
ti
.name
,
sig
,
&
ti
.generics
,
&
hir
::
Inherited
,
&
[],
Some
(
body
))
?
;
self
.nbsp
()
?
;
self
.end
()
?
;
// need to close a box
self
.end
()
?
;
// need to close a box
...
...
@@ -938,7 +939,7 @@ pub fn print_impl_item(&mut self, ii: &hir::ImplItem) -> io::Result<()> {
}
hir
::
ImplItemKind
::
Method
(
ref
sig
,
body
)
=>
{
self
.head
(
""
)
?
;
self
.print_method_sig
(
ii
.name
,
sig
,
&
ii
.vis
,
&
[],
Some
(
body
))
?
;
self
.print_method_sig
(
ii
.name
,
sig
,
&
ii
.
generics
,
&
ii
.
vis
,
&
[],
Some
(
body
))
?
;
self
.nbsp
()
?
;
self
.end
()
?
;
// need to close a box
self
.end
()
?
;
// need to close a box
...
...
src/librustc/ich/impls_hir.rs
浏览文件 @
bb301446
...
...
@@ -232,8 +232,7 @@ fn hash_stable<W: StableHasherResult>(&self,
unsafety
,
constness
,
abi
,
decl
,
generics
decl
});
impl_stable_hash_for!
(
struct
hir
::
TypeBinding
{
...
...
@@ -709,6 +708,7 @@ fn hash_stable<W: StableHasherResult>(&self,
hir_id
:
_
,
name
,
ref
attrs
,
ref
generics
,
ref
node
,
span
}
=
*
self
;
...
...
@@ -716,6 +716,7 @@ fn hash_stable<W: StableHasherResult>(&self,
hcx
.hash_hir_item_like
(
attrs
,
|
hcx
|
{
name
.hash_stable
(
hcx
,
hasher
);
attrs
.hash_stable
(
hcx
,
hasher
);
generics
.hash_stable
(
hcx
,
hasher
);
node
.hash_stable
(
hcx
,
hasher
);
span
.hash_stable
(
hcx
,
hasher
);
});
...
...
@@ -744,6 +745,7 @@ fn hash_stable<W: StableHasherResult>(&self,
ref
vis
,
defaultness
,
ref
attrs
,
ref
generics
,
ref
node
,
span
}
=
*
self
;
...
...
@@ -753,6 +755,7 @@ fn hash_stable<W: StableHasherResult>(&self,
vis
.hash_stable
(
hcx
,
hasher
);
defaultness
.hash_stable
(
hcx
,
hasher
);
attrs
.hash_stable
(
hcx
,
hasher
);
generics
.hash_stable
(
hcx
,
hasher
);
node
.hash_stable
(
hcx
,
hasher
);
span
.hash_stable
(
hcx
,
hasher
);
});
...
...
src/librustc/middle/reachable.rs
浏览文件 @
bb301446
...
...
@@ -58,11 +58,10 @@ fn item_might_be_inlined(item: &hir::Item) -> bool {
}
fn
method_might_be_inlined
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
sig
:
&
hir
::
MethodSig
,
impl_item
:
&
hir
::
ImplItem
,
impl_src
:
DefId
)
->
bool
{
if
attr
::
requests_inline
(
&
impl_item
.attrs
)
||
generics_require_inlining
(
&
sig
.generics
)
{
generics_require_inlining
(
&
impl_item
.generics
)
{
return
true
}
if
let
Some
(
impl_node_id
)
=
tcx
.hir
.as_local_node_id
(
impl_src
)
{
...
...
@@ -176,8 +175,8 @@ fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
Some
(
hir_map
::
NodeImplItem
(
impl_item
))
=>
{
match
impl_item
.node
{
hir
::
ImplItemKind
::
Const
(
..
)
=>
true
,
hir
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
{
if
generics_require_inlining
(
&
sig
.generics
)
||
hir
::
ImplItemKind
::
Method
(
..
)
=>
{
if
generics_require_inlining
(
&
impl_item
.generics
)
||
attr
::
requests_inline
(
&
impl_item
.attrs
)
{
true
}
else
{
...
...
@@ -293,9 +292,9 @@ fn propagate_node(&mut self, node: &hir_map::Node<'tcx>,
hir
::
ImplItemKind
::
Const
(
_
,
body
)
=>
{
self
.visit_nested_body
(
body
);
}
hir
::
ImplItemKind
::
Method
(
ref
sig
,
body
)
=>
{
hir
::
ImplItemKind
::
Method
(
_
,
body
)
=>
{
let
did
=
self
.tcx.hir
.get_parent_did
(
search_item
);
if
method_might_be_inlined
(
self
.tcx
,
sig
,
impl_item
,
did
)
{
if
method_might_be_inlined
(
self
.tcx
,
impl_item
,
did
)
{
self
.visit_nested_body
(
body
)
}
}
...
...
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
bb301446
...
...
@@ -412,7 +412,7 @@ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
if
let
hir
::
TraitItemKind
::
Method
(
ref
sig
,
_
)
=
trait_item
.node
{
self
.visit_early_late
(
Some
(
self
.hir_map
.get_parent
(
trait_item
.id
)),
&
sig
.decl
,
&
sig
.generics
,
&
sig
.decl
,
&
trait_item
.generics
,
|
this
|
intravisit
::
walk_trait_item
(
this
,
trait_item
))
}
else
{
intravisit
::
walk_trait_item
(
self
,
trait_item
);
...
...
@@ -423,7 +423,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
if
let
hir
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=
impl_item
.node
{
self
.visit_early_late
(
Some
(
self
.hir_map
.get_parent
(
impl_item
.id
)),
&
sig
.decl
,
&
sig
.generics
,
&
sig
.decl
,
&
impl_item
.generics
,
|
this
|
intravisit
::
walk_impl_item
(
this
,
impl_item
))
}
else
{
intravisit
::
walk_impl_item
(
self
,
impl_item
);
...
...
src/librustc_typeck/check/compare_method.rs
浏览文件 @
bb301446
...
...
@@ -568,15 +568,11 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
num_trait_m_type_params
=
trait_m_generics
.types
.len
();
if
num_impl_m_type_params
!=
num_trait_m_type_params
{
let
impl_m_node_id
=
tcx
.hir
.as_local_node_id
(
impl_m
.def_id
)
.unwrap
();
let
span
=
match
tcx
.hir
.expect_impl_item
(
impl_m_node_id
)
.node
{
ImplItemKind
::
Method
(
ref
impl_m_sig
,
_
)
=>
{
if
impl_m_sig
.generics
.is_parameterized
()
{
impl_m_sig
.generics.span
}
else
{
impl_m_span
}
}
_
=>
bug!
(
"{:?} is not a method"
,
impl_m
),
let
impl_m_item
=
tcx
.hir
.expect_impl_item
(
impl_m_node_id
);
let
span
=
if
impl_m_item
.generics
.is_parameterized
()
{
impl_m_item
.generics.span
}
else
{
impl_m_span
};
let
mut
err
=
struct_span_err!
(
tcx
.sess
,
...
...
src/librustc_typeck/collect.rs
浏览文件 @
bb301446
...
...
@@ -261,19 +261,9 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
item_node_id
=
tcx
.hir
.as_local_node_id
(
item_def_id
)
.unwrap
();
let
ast_generics
=
match
tcx
.hir
.get
(
item_node_id
)
{
NodeTraitItem
(
item
)
=>
{
match
item
.node
{
TraitItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
return
result
}
}
NodeTraitItem
(
item
)
=>
&
item
.generics
,
NodeImplItem
(
item
)
=>
{
match
item
.node
{
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
return
result
}
}
NodeImplItem
(
item
)
=>
&
item
.generics
,
NodeItem
(
item
)
=>
{
match
item
.node
{
...
...
@@ -818,12 +808,12 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
match
node
{
hir_map
::
NodeTraitItem
(
item
)
=>
match
item
.node
{
hir
::
TraitItemKind
::
Method
(
ref
sig
,
_
)
=>
has_late_bound_regions
(
tcx
,
&
sig
.generics
,
&
sig
.decl
),
has_late_bound_regions
(
tcx
,
&
item
.generics
,
&
sig
.decl
),
_
=>
None
,
},
hir_map
::
NodeImplItem
(
item
)
=>
match
item
.node
{
hir
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
has_late_bound_regions
(
tcx
,
&
sig
.generics
,
&
sig
.decl
),
has_late_bound_regions
(
tcx
,
&
item
.generics
,
&
sig
.decl
),
_
=>
None
,
},
hir_map
::
NodeForeignItem
(
item
)
=>
match
item
.node
{
...
...
@@ -881,19 +871,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
no_generics
=
hir
::
Generics
::
empty
();
let
ast_generics
=
match
node
{
NodeTraitItem
(
item
)
=>
{
match
item
.node
{
TraitItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
&
no_generics
}
}
NodeTraitItem
(
item
)
=>
&
item
.generics
,
NodeImplItem
(
item
)
=>
{
match
item
.node
{
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
&
no_generics
}
}
NodeImplItem
(
item
)
=>
&
item
.generics
,
NodeItem
(
item
)
=>
{
match
item
.node
{
...
...
@@ -1353,19 +1333,9 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
icx
=
ItemCtxt
::
new
(
tcx
,
def_id
);
let
no_generics
=
hir
::
Generics
::
empty
();
let
ast_generics
=
match
node
{
NodeTraitItem
(
item
)
=>
{
match
item
.node
{
TraitItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
&
no_generics
}
}
NodeTraitItem
(
item
)
=>
&
item
.generics
,
NodeImplItem
(
item
)
=>
{
match
item
.node
{
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
&
sig
.generics
,
_
=>
&
no_generics
}
}
NodeImplItem
(
item
)
=>
&
item
.generics
,
NodeItem
(
item
)
=>
{
match
item
.node
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录