Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
683d20c3
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
683d20c3
编写于
1月 07, 2015
作者:
F
Flavio Percoco
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Record negative trait_impls separatedly
上级
b565501a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
2 deletion
+64
-2
src/librustc/metadata/csearch.rs
src/librustc/metadata/csearch.rs
+9
-0
src/librustc/metadata/decoder.rs
src/librustc/metadata/decoder.rs
+23
-0
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+32
-2
未找到文件。
src/librustc/metadata/csearch.rs
浏览文件 @
683d20c3
...
...
@@ -262,6 +262,15 @@ pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId,
}
}
pub
fn
get_impl_polarity
<
'tcx
>
(
tcx
:
&
ty
::
ctxt
<
'tcx
>
,
def
:
ast
::
DefId
)
->
Option
<
ast
::
ImplPolarity
>
{
let
cstore
=
&
tcx
.sess.cstore
;
let
cdata
=
cstore
.get_crate_data
(
def
.krate
);
decoder
::
get_impl_polarity
(
&*
cdata
,
def
.node
)
}
// Given a def_id for an impl, return the trait it implements,
// if there is one.
pub
fn
get_impl_trait
<
'tcx
>
(
tcx
:
&
ty
::
ctxt
<
'tcx
>
,
...
...
src/librustc/metadata/decoder.rs
浏览文件 @
683d20c3
...
...
@@ -371,6 +371,15 @@ fn parse_unsafety(item_doc: rbml::Doc) -> ast::Unsafety {
}
}
fn
parse_polarity
(
item_doc
:
rbml
::
Doc
)
->
ast
::
ImplPolarity
{
let
polarity_doc
=
reader
::
get_doc
(
item_doc
,
tag_polarity
);
if
reader
::
doc_as_u8
(
polarity_doc
)
!=
0
{
ast
::
ImplPolarity
::
Negative
}
else
{
ast
::
ImplPolarity
::
Positive
}
}
fn
parse_associated_type_names
(
item_doc
:
rbml
::
Doc
)
->
Vec
<
ast
::
Name
>
{
let
names_doc
=
reader
::
get_doc
(
item_doc
,
tag_associated_type_names
);
let
mut
names
=
Vec
::
new
();
...
...
@@ -436,6 +445,20 @@ pub fn get_repr_attrs(cdata: Cmd, id: ast::NodeId) -> Vec<attr::ReprAttr> {
}
}
pub
fn
get_impl_polarity
<
'tcx
>
(
cdata
:
Cmd
,
id
:
ast
::
NodeId
)
->
Option
<
ast
::
ImplPolarity
>
{
let
item_doc
=
lookup_item
(
id
,
cdata
.data
());
let
fam
=
item_family
(
item_doc
);
match
fam
{
Family
::
Impl
=>
{
Some
(
parse_polarity
(
item_doc
))
}
_
=>
None
}
}
pub
fn
get_impl_trait
<
'tcx
>
(
cdata
:
Cmd
,
id
:
ast
::
NodeId
,
tcx
:
&
ty
::
ctxt
<
'tcx
>
)
...
...
src/librustc/middle/ty.rs
浏览文件 @
683d20c3
...
...
@@ -750,6 +750,9 @@ pub struct ctxt<'tcx> {
/// Maps a trait onto a list of impls of that trait.
pub
trait_impls
:
RefCell
<
DefIdMap
<
Rc
<
RefCell
<
Vec
<
ast
::
DefId
>>>>>
,
/// Maps a trait onto a list of negative impls of that trait.
pub
trait_negative_impls
:
RefCell
<
DefIdMap
<
Rc
<
RefCell
<
Vec
<
ast
::
DefId
>>>>>
,
/// Maps a DefId of a type to a list of its inherent impls.
/// Contains implementations of methods that are inherent to a type.
/// Methods in these implementations don't need to be exported.
...
...
@@ -2412,6 +2415,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
destructor_for_type
:
RefCell
::
new
(
DefIdMap
::
new
()),
destructors
:
RefCell
::
new
(
DefIdSet
::
new
()),
trait_impls
:
RefCell
::
new
(
DefIdMap
::
new
()),
trait_negative_impls
:
RefCell
::
new
(
DefIdMap
::
new
()),
inherent_impls
:
RefCell
::
new
(
DefIdMap
::
new
()),
impl_items
:
RefCell
::
new
(
DefIdMap
::
new
()),
used_unsafe
:
RefCell
::
new
(
NodeSet
::
new
()),
...
...
@@ -5035,6 +5039,23 @@ pub fn trait_items<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId)
}
}
pub
fn
trait_impl_polarity
<
'tcx
>
(
cx
:
&
ctxt
<
'tcx
>
,
id
:
ast
::
DefId
)
->
Option
<
ast
::
ImplPolarity
>
{
if
id
.krate
==
ast
::
LOCAL_CRATE
{
match
cx
.map
.find
(
id
.node
)
{
Some
(
ast_map
::
NodeItem
(
item
))
=>
{
match
item
.node
{
ast
::
ItemImpl
(
_
,
polarity
,
_
,
_
,
_
,
_
)
=>
Some
(
polarity
),
_
=>
None
}
}
_
=>
None
}
}
else
{
csearch
::
get_impl_polarity
(
cx
,
id
)
}
}
pub
fn
impl_or_trait_item
<
'tcx
>
(
cx
:
&
ctxt
<
'tcx
>
,
id
:
ast
::
DefId
)
->
ImplOrTraitItem
<
'tcx
>
{
lookup_locally_or_in_crate_store
(
"impl_or_trait_items"
,
...
...
@@ -5984,14 +6005,23 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
pub
fn
record_trait_implementation
(
tcx
:
&
ctxt
,
trait_def_id
:
DefId
,
impl_def_id
:
DefId
)
{
match
tcx
.trait_impls
.borrow
()
.get
(
&
trait_def_id
)
{
let
trait_impls
=
match
trait_impl_polarity
(
tcx
,
impl_def_id
)
{
Some
(
ast
::
ImplPolarity
::
Positive
)
=>
&
tcx
.trait_impls
,
Some
(
ast
::
ImplPolarity
::
Negative
)
=>
&
tcx
.trait_negative_impls
,
_
=>
tcx
.sess
.bug
(
&
format!
(
"tried to record a non-impl item with id {:?}"
,
impl_def_id
)[])
};
match
trait_impls
.borrow
()
.get
(
&
trait_def_id
)
{
Some
(
impls_for_trait
)
=>
{
impls_for_trait
.borrow_mut
()
.push
(
impl_def_id
);
return
;
}
None
=>
{}
}
tcx
.trait_impls
.borrow_mut
()
.insert
(
trait_def_id
,
Rc
::
new
(
RefCell
::
new
(
vec!
(
impl_def_id
))));
trait_impls
.borrow_mut
()
.insert
(
trait_def_id
,
Rc
::
new
(
RefCell
::
new
(
vec!
(
impl_def_id
))));
}
/// Populates the type context with all the implementations for the given type
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录