Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
623ea5f5
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,发现更多精彩内容 >>
提交
623ea5f5
编写于
5月 27, 2022
作者:
C
Camille GILLOT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make hir().get_generics and generics_of consistent.
上级
7e9b92cb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
71 deletion
+23
-71
compiler/rustc_hir/src/hir.rs
compiler/rustc_hir/src/hir.rs
+9
-12
compiler/rustc_middle/src/hir/map/mod.rs
compiler/rustc_middle/src/hir/map/mod.rs
+1
-21
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+13
-38
未找到文件。
compiler/rustc_hir/src/hir.rs
浏览文件 @
623ea5f5
...
...
@@ -3004,13 +3004,12 @@ pub fn generics(&self) -> Option<&Generics<'_>> {
Some
(
match
*
self
{
ItemKind
::
Fn
(
_
,
ref
generics
,
_
)
|
ItemKind
::
TyAlias
(
_
,
ref
generics
)
|
ItemKind
::
OpaqueTy
(
OpaqueTy
{
ref
generics
,
origin
:
OpaqueTyOrigin
::
TyAlias
,
..
})
|
ItemKind
::
OpaqueTy
(
OpaqueTy
{
ref
generics
,
..
})
|
ItemKind
::
Enum
(
_
,
ref
generics
)
|
ItemKind
::
Struct
(
_
,
ref
generics
)
|
ItemKind
::
Union
(
_
,
ref
generics
)
|
ItemKind
::
Trait
(
_
,
_
,
ref
generics
,
_
,
_
)
|
ItemKind
::
TraitAlias
(
ref
generics
,
_
)
|
ItemKind
::
Impl
(
Impl
{
ref
generics
,
..
})
=>
generics
,
_
=>
return
None
,
})
...
...
@@ -3210,13 +3209,8 @@ pub fn body_id(&self) -> Option<BodyId> {
}
}
pub
fn
generics
(
&
self
)
->
Option
<&
'hir
Generics
<
'hir
>>
{
match
self
{
OwnerNode
::
TraitItem
(
TraitItem
{
generics
,
..
})
|
OwnerNode
::
ImplItem
(
ImplItem
{
generics
,
..
})
=>
Some
(
generics
),
OwnerNode
::
Item
(
item
)
=>
item
.kind
.generics
(),
_
=>
None
,
}
pub
fn
generics
(
self
)
->
Option
<&
'hir
Generics
<
'hir
>>
{
Node
::
generics
(
self
.into
())
}
pub
fn
def_id
(
self
)
->
LocalDefId
{
...
...
@@ -3403,9 +3397,12 @@ pub fn body_id(&self) -> Option<BodyId> {
}
}
pub
fn
generics
(
&
self
)
->
Option
<&
'hir
Generics
<
'hir
>>
{
pub
fn
generics
(
self
)
->
Option
<&
'hir
Generics
<
'hir
>>
{
match
self
{
Node
::
TraitItem
(
TraitItem
{
generics
,
..
})
Node
::
ForeignItem
(
ForeignItem
{
kind
:
ForeignItemKind
::
Fn
(
_
,
_
,
generics
),
..
})
|
Node
::
TraitItem
(
TraitItem
{
generics
,
..
})
|
Node
::
ImplItem
(
ImplItem
{
generics
,
..
})
=>
Some
(
generics
),
Node
::
Item
(
item
)
=>
item
.kind
.generics
(),
_
=>
None
,
...
...
compiler/rustc_middle/src/hir/map/mod.rs
浏览文件 @
623ea5f5
...
...
@@ -361,27 +361,7 @@ pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
pub
fn
get_generics
(
self
,
id
:
LocalDefId
)
->
Option
<&
'hir
Generics
<
'hir
>>
{
let
node
=
self
.tcx
.hir_owner
(
id
)
?
;
match
node
.node
{
OwnerNode
::
ImplItem
(
impl_item
)
=>
Some
(
&
impl_item
.generics
),
OwnerNode
::
TraitItem
(
trait_item
)
=>
Some
(
&
trait_item
.generics
),
OwnerNode
::
ForeignItem
(
ForeignItem
{
kind
:
ForeignItemKind
::
Fn
(
_
,
_
,
generics
),
..
})
|
OwnerNode
::
Item
(
Item
{
kind
:
ItemKind
::
Fn
(
_
,
generics
,
_
)
|
ItemKind
::
TyAlias
(
_
,
generics
)
|
ItemKind
::
Enum
(
_
,
generics
)
|
ItemKind
::
Struct
(
_
,
generics
)
|
ItemKind
::
Union
(
_
,
generics
)
|
ItemKind
::
Trait
(
_
,
_
,
generics
,
..
)
|
ItemKind
::
TraitAlias
(
generics
,
_
)
|
ItemKind
::
Impl
(
Impl
{
generics
,
..
}),
..
})
=>
Some
(
generics
),
_
=>
None
,
}
node
.node
.generics
()
}
pub
fn
item
(
self
,
id
:
ItemId
)
->
&
'hir
Item
<
'hir
>
{
...
...
compiler/rustc_typeck/src/collect.rs
浏览文件 @
623ea5f5
...
...
@@ -1588,41 +1588,20 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
_
=>
None
,
};
let
mut
opt_self
=
None
;
let
mut
allow_defaults
=
false
;
let
no_generics
=
hir
::
Generics
::
empty
();
let
ast_generics
=
match
node
{
Node
::
TraitItem
(
item
)
=>
&
item
.generics
,
Node
::
ImplItem
(
item
)
=>
&
item
.generics
,
let
ast_generics
=
node
.generics
()
.unwrap_or
(
&
no_generics
);
let
(
opt_self
,
allow_defaults
)
=
match
node
{
Node
::
Item
(
item
)
=>
{
match
item
.kind
{
ItemKind
::
Fn
(
..
,
ref
generics
,
_
)
|
ItemKind
::
Impl
(
hir
::
Impl
{
ref
generics
,
..
})
=>
generics
,
ItemKind
::
TyAlias
(
_
,
ref
generics
)
|
ItemKind
::
Enum
(
_
,
ref
generics
)
|
ItemKind
::
Struct
(
_
,
ref
generics
)
|
ItemKind
::
OpaqueTy
(
hir
::
OpaqueTy
{
ref
generics
,
..
})
|
ItemKind
::
Union
(
_
,
ref
generics
)
=>
{
allow_defaults
=
true
;
generics
}
ItemKind
::
Trait
(
_
,
_
,
ref
generics
,
..
)
|
ItemKind
::
TraitAlias
(
ref
generics
,
..
)
=>
{
ItemKind
::
Trait
(
..
)
|
ItemKind
::
TraitAlias
(
..
)
=>
{
// Add in the self type parameter.
//
// Something of a hack: use the node id for the trait, also as
// the node id for the Self type parameter.
let
param_id
=
item
.def_id
;
opt_self
=
Some
(
ty
::
GenericParamDef
{
let
opt_self
=
Some
(
ty
::
GenericParamDef
{
index
:
0
,
name
:
kw
::
SelfUpper
,
def_id
:
param_id
.to_def_id
()
,
def_id
,
pure_wrt_drop
:
false
,
kind
:
ty
::
GenericParamDefKind
::
Type
{
has_default
:
false
,
...
...
@@ -1631,21 +1610,17 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
},
});
allow_defaults
=
true
;
generics
(
opt_self
,
true
)
}
_
=>
&
no_generics
,
ItemKind
::
TyAlias
(
..
)
|
ItemKind
::
Enum
(
..
)
|
ItemKind
::
Struct
(
..
)
|
ItemKind
::
OpaqueTy
(
..
)
|
ItemKind
::
Union
(
..
)
=>
(
None
,
true
),
_
=>
(
None
,
false
),
}
}
Node
::
ForeignItem
(
item
)
=>
match
item
.kind
{
ForeignItemKind
::
Static
(
..
)
=>
&
no_generics
,
ForeignItemKind
::
Fn
(
_
,
_
,
ref
generics
)
=>
generics
,
ForeignItemKind
::
Type
=>
&
no_generics
,
},
_
=>
&
no_generics
,
_
=>
(
None
,
false
),
};
let
has_self
=
opt_self
.is_some
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录