Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b11da34a
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,发现更多精彩内容 >>
提交
b11da34a
编写于
4月 18, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
do not access `associated_item` map directly
上级
f35ff22f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
25 deletion
+40
-25
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+29
-10
src/librustc_lint/bad_style.rs
src/librustc_lint/bad_style.rs
+9
-13
src/librustc_lint/builtin.rs
src/librustc_lint/builtin.rs
+1
-1
src/librustc_metadata/decoder.rs
src/librustc_metadata/decoder.rs
+1
-1
未找到文件。
src/librustc/ty/mod.rs
浏览文件 @
b11da34a
...
...
@@ -2139,6 +2139,26 @@ pub fn trait_relevant_for_never(self, did: DefId) -> bool {
})
}
pub
fn
opt_associated_item
(
self
,
def_id
:
DefId
)
->
Option
<
AssociatedItem
>
{
let
is_associated_item
=
if
let
Some
(
node_id
)
=
self
.hir
.as_local_node_id
(
def_id
)
{
match
self
.hir
.get
(
node_id
)
{
hir_map
::
NodeTraitItem
(
_
)
|
hir_map
::
NodeImplItem
(
_
)
=>
true
,
_
=>
false
,
}
}
else
{
match
self
.sess.cstore
.describe_def
(
def_id
)
.expect
(
"no def for def-id"
)
{
Def
::
AssociatedConst
(
_
)
|
Def
::
Method
(
_
)
|
Def
::
AssociatedTy
(
_
)
=>
true
,
_
=>
false
,
}
};
if
is_associated_item
{
Some
(
self
.associated_item
(
def_id
))
}
else
{
None
}
}
fn
associated_item_from_trait_item_ref
(
self
,
parent_def_id
:
DefId
,
parent_vis
:
&
hir
::
Visibility
,
...
...
@@ -2391,7 +2411,7 @@ pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
None
}
}
else
{
self
.
maps.associated_item
.borrow
()
.get
(
&
def_id
)
.cloned
(
)
self
.
opt_associated_item
(
def_id
)
};
match
item
{
...
...
@@ -2412,15 +2432,13 @@ pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
if
def_id
.krate
!=
LOCAL_CRATE
{
return
self
.sess.cstore
.trait_of_item
(
def_id
);
}
match
self
.maps.associated_item
.borrow
()
.get
(
&
def_id
)
{
Some
(
associated_item
)
=>
{
self
.opt_associated_item
(
def_id
)
.and_then
(|
associated_item
|
{
match
associated_item
.container
{
TraitContainer
(
def_id
)
=>
Some
(
def_id
),
ImplContainer
(
_
)
=>
None
}
}
None
=>
None
}
})
}
/// Construct a parameter environment suitable for static contexts or other contexts where there
...
...
@@ -2588,11 +2606,12 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
}
}
ref
r
=>
{
panic!
(
"unexpected container of associated items: {:?}"
,
r
)
}
_
=>
{
}
}
panic!
(
"associated item not found for def_id: {:?}"
,
def_id
);
span_bug!
(
parent_item
.span
,
"unexpected parent of trait or impl item or item not found: {:?}"
,
parent_item
.node
)
}
/// Calculates the Sized-constraint.
...
...
src/librustc_lint/bad_style.rs
浏览文件 @
b11da34a
...
...
@@ -27,19 +27,15 @@ pub enum MethodLateContext {
PlainImpl
,
}
pub
fn
method_context
(
cx
:
&
LateContext
,
id
:
ast
::
NodeId
,
span
:
Span
)
->
MethodLateContext
{
pub
fn
method_context
(
cx
:
&
LateContext
,
id
:
ast
::
NodeId
)
->
MethodLateContext
{
let
def_id
=
cx
.tcx.hir
.local_def_id
(
id
);
match
cx
.tcx.maps.associated_item
.borrow
()
.get
(
&
def_id
)
{
None
=>
span_bug!
(
span
,
"missing method descriptor?!"
),
Some
(
item
)
=>
{
match
item
.container
{
ty
::
TraitContainer
(
..
)
=>
MethodLateContext
::
TraitDefaultImpl
,
ty
::
ImplContainer
(
cid
)
=>
{
match
cx
.tcx
.impl_trait_ref
(
cid
)
{
Some
(
_
)
=>
MethodLateContext
::
TraitImpl
,
None
=>
MethodLateContext
::
PlainImpl
,
}
}
let
item
=
cx
.tcx
.associated_item
(
def_id
);
match
item
.container
{
ty
::
TraitContainer
(
..
)
=>
MethodLateContext
::
TraitDefaultImpl
,
ty
::
ImplContainer
(
cid
)
=>
{
match
cx
.tcx
.impl_trait_ref
(
cid
)
{
Some
(
_
)
=>
MethodLateContext
::
TraitImpl
,
None
=>
MethodLateContext
::
PlainImpl
,
}
}
}
...
...
@@ -244,7 +240,7 @@ fn check_fn(&mut self,
id
:
ast
::
NodeId
)
{
match
fk
{
FnKind
::
Method
(
name
,
..
)
=>
{
match
method_context
(
cx
,
id
,
span
)
{
match
method_context
(
cx
,
id
)
{
MethodLateContext
::
PlainImpl
=>
{
self
.check_snake_case
(
cx
,
"method"
,
&
name
.as_str
(),
Some
(
span
))
}
...
...
src/librustc_lint/builtin.rs
浏览文件 @
b11da34a
...
...
@@ -432,7 +432,7 @@ fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) {
fn
check_impl_item
(
&
mut
self
,
cx
:
&
LateContext
,
impl_item
:
&
hir
::
ImplItem
)
{
// If the method is an impl for a trait, don't doc.
if
method_context
(
cx
,
impl_item
.id
,
impl_item
.span
)
==
MethodLateContext
::
TraitImpl
{
if
method_context
(
cx
,
impl_item
.id
)
==
MethodLateContext
::
TraitImpl
{
return
;
}
...
...
src/librustc_metadata/decoder.rs
浏览文件 @
b11da34a
...
...
@@ -827,7 +827,7 @@ pub fn get_associated_item(&self, id: DefIndex) -> ty::AssociatedItem {
EntryKind
::
AssociatedType
(
container
)
=>
{
(
ty
::
AssociatedKind
::
Type
,
container
,
false
)
}
_
=>
bug!
()
_
=>
bug!
(
"cannot get associated-item of `{:?}`"
,
def_key
)
};
ty
::
AssociatedItem
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录