Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
15ef2c2e
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,发现更多精彩内容 >>
提交
15ef2c2e
编写于
2月 17, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert `astconv` to request bounds through the `AstConv` interface
rather than poking through the `TypeParameterDef` directly.
上级
e033a231
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
7 deletion
+55
-7
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+8
-1
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+6
-2
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+25
-1
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+16
-3
未找到文件。
src/librustc/middle/ty.rs
浏览文件 @
15ef2c2e
...
@@ -55,7 +55,7 @@
...
@@ -55,7 +55,7 @@
use
middle
::
resolve_lifetime
;
use
middle
::
resolve_lifetime
;
use
middle
::
infer
;
use
middle
::
infer
;
use
middle
::
stability
;
use
middle
::
stability
;
use
middle
::
subst
::{
self
,
Subst
,
Substs
,
VecPerParamSpace
};
use
middle
::
subst
::{
self
,
ParamSpace
,
Subst
,
Substs
,
VecPerParamSpace
};
use
middle
::
traits
;
use
middle
::
traits
;
use
middle
::
ty
;
use
middle
::
ty
;
use
middle
::
ty_fold
::{
self
,
TypeFoldable
,
TypeFolder
};
use
middle
::
ty_fold
::{
self
,
TypeFoldable
,
TypeFolder
};
...
@@ -2996,6 +2996,13 @@ pub fn as_opt_param_ty(&self) -> Option<ty::ParamTy> {
...
@@ -2996,6 +2996,13 @@ pub fn as_opt_param_ty(&self) -> Option<ty::ParamTy> {
_
=>
None
,
_
=>
None
,
}
}
}
}
pub
fn
is_param
(
&
self
,
space
:
ParamSpace
,
index
:
u32
)
->
bool
{
match
self
.sty
{
ty
::
ty_param
(
ref
data
)
=>
data
.space
==
space
&&
data
.idx
==
index
,
_
=>
false
,
}
}
}
}
pub
fn
walk_ty
<
'tcx
,
F
>
(
ty_root
:
Ty
<
'tcx
>
,
mut
f
:
F
)
pub
fn
walk_ty
<
'tcx
,
F
>
(
ty_root
:
Ty
<
'tcx
>
,
mut
f
:
F
)
...
...
src/librustc_typeck/astconv.rs
浏览文件 @
15ef2c2e
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
use
middle
::
def
;
use
middle
::
def
;
use
middle
::
resolve_lifetime
as
rl
;
use
middle
::
resolve_lifetime
as
rl
;
use
middle
::
privacy
::{
AllPublic
,
LastMod
};
use
middle
::
privacy
::{
AllPublic
,
LastMod
};
use
middle
::
subst
::{
FnSpace
,
TypeSpace
,
SelfSpace
,
Subst
,
Substs
};
use
middle
::
subst
::{
FnSpace
,
ParamSpace
,
TypeSpace
,
SelfSpace
,
Subst
,
Substs
};
use
middle
::
traits
;
use
middle
::
traits
;
use
middle
::
ty
::{
self
,
RegionEscape
,
ToPolyTraitRef
,
Ty
};
use
middle
::
ty
::{
self
,
RegionEscape
,
ToPolyTraitRef
,
Ty
};
use
rscope
::{
self
,
UnelidableRscope
,
RegionScope
,
ElidableRscope
,
use
rscope
::{
self
,
UnelidableRscope
,
RegionScope
,
ElidableRscope
,
...
@@ -77,6 +77,8 @@ pub trait AstConv<'tcx> {
...
@@ -77,6 +77,8 @@ pub trait AstConv<'tcx> {
fn
get_trait_def
(
&
self
,
id
:
ast
::
DefId
)
->
Rc
<
ty
::
TraitDef
<
'tcx
>>
;
fn
get_trait_def
(
&
self
,
id
:
ast
::
DefId
)
->
Rc
<
ty
::
TraitDef
<
'tcx
>>
;
fn
get_type_parameter_bounds
(
&
self
,
space
:
ParamSpace
,
index
:
u32
)
->
Vec
<
ty
::
PolyTraitRef
<
'tcx
>>
;
/// Return an (optional) substitution to convert bound type parameters that
/// Return an (optional) substitution to convert bound type parameters that
/// are in scope into free ones. This function should only return Some
/// are in scope into free ones. This function should only return Some
/// within a fn body.
/// within a fn body.
...
@@ -1011,7 +1013,9 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
...
@@ -1011,7 +1013,9 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
// FIXME(#20300) -- search where clauses, not bounds
// FIXME(#20300) -- search where clauses, not bounds
suitable_bounds
=
suitable_bounds
=
traits
::
transitive_bounds
(
tcx
,
&
ty_param_def
.bounds.trait_bounds
)
traits
::
transitive_bounds
(
tcx
,
&
this
.get_type_parameter_bounds
(
ty_param_def
.space
,
ty_param_def
.index
))
.filter
(|
b
|
trait_defines_associated_type_named
(
this
,
b
.def_id
(),
assoc_name
))
.filter
(|
b
|
trait_defines_associated_type_named
(
this
,
b
.def_id
(),
assoc_name
))
.collect
();
.collect
();
}
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
15ef2c2e
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
use
middle
::
traits
;
use
middle
::
traits
;
use
middle
::
ty
::{
FnSig
,
GenericPredicates
,
VariantInfo
,
TypeScheme
};
use
middle
::
ty
::{
FnSig
,
GenericPredicates
,
VariantInfo
,
TypeScheme
};
use
middle
::
ty
::{
Disr
,
ParamTy
,
ParameterEnvironment
};
use
middle
::
ty
::{
Disr
,
ParamTy
,
ParameterEnvironment
};
use
middle
::
ty
::{
self
,
HasProjectionTypes
,
RegionEscape
,
Ty
};
use
middle
::
ty
::{
self
,
HasProjectionTypes
,
RegionEscape
,
T
oPolyTraitRef
,
T
y
};
use
middle
::
ty
::
liberate_late_bound_regions
;
use
middle
::
ty
::
liberate_late_bound_regions
;
use
middle
::
ty
::{
MethodCall
,
MethodCallee
,
MethodMap
,
ObjectCastMap
};
use
middle
::
ty
::{
MethodCall
,
MethodCallee
,
MethodMap
,
ObjectCastMap
};
use
middle
::
ty_fold
::{
TypeFolder
,
TypeFoldable
};
use
middle
::
ty_fold
::{
TypeFolder
,
TypeFoldable
};
...
@@ -1218,6 +1218,30 @@ fn get_free_substs(&self) -> Option<&Substs<'tcx>> {
...
@@ -1218,6 +1218,30 @@ fn get_free_substs(&self) -> Option<&Substs<'tcx>> {
Some
(
&
self
.inh.param_env.free_substs
)
Some
(
&
self
.inh.param_env.free_substs
)
}
}
fn
get_type_parameter_bounds
(
&
self
,
space
:
ParamSpace
,
index
:
u32
)
->
Vec
<
ty
::
PolyTraitRef
<
'tcx
>>
{
self
.inh.param_env.caller_bounds
.iter
()
.filter_map
(|
predicate
|
{
match
*
predicate
{
ty
::
Predicate
::
Trait
(
ref
data
)
=>
{
if
data
.0
.self_ty
()
.is_param
(
space
,
index
)
{
Some
(
data
.to_poly_trait_ref
())
}
else
{
None
}
}
_
=>
{
None
}
}
})
.collect
()
}
fn
ty_infer
(
&
self
,
_
span
:
Span
)
->
Ty
<
'tcx
>
{
fn
ty_infer
(
&
self
,
_
span
:
Span
)
->
Ty
<
'tcx
>
{
self
.infcx
()
.next_ty_var
()
self
.infcx
()
.next_ty_var
()
}
}
...
...
src/librustc_typeck/collect.rs
浏览文件 @
15ef2c2e
...
@@ -145,7 +145,6 @@ struct CrateCtxt<'a,'tcx:'a> {
...
@@ -145,7 +145,6 @@ struct CrateCtxt<'a,'tcx:'a> {
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
}
}
#[allow(dead_code)]
// just temporary, for generics
struct
ItemCtxt
<
'a
,
'tcx
:
'a
>
{
struct
ItemCtxt
<
'a
,
'tcx
:
'a
>
{
ccx
:
&
'a
CrateCtxt
<
'a
,
'tcx
>
,
ccx
:
&
'a
CrateCtxt
<
'a
,
'tcx
>
,
generics
:
&
'a
ty
::
Generics
<
'tcx
>
,
generics
:
&
'a
ty
::
Generics
<
'tcx
>
,
...
@@ -241,6 +240,19 @@ fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef<'tcx>> {
...
@@ -241,6 +240,19 @@ fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef<'tcx>> {
get_trait_def
(
self
.ccx
,
id
)
get_trait_def
(
self
.ccx
,
id
)
}
}
fn
get_type_parameter_bounds
(
&
self
,
param
:
subst
::
ParamSpace
,
index
:
u32
)
->
Vec
<
ty
::
PolyTraitRef
<
'tcx
>>
{
// TODO out of range indices can occur when you have something
// like fn foo<T:U::X,U>() { }
match
self
.generics.types
.opt_get
(
param
,
index
as
usize
)
{
Some
(
def
)
=>
def
.bounds.trait_bounds
.clone
(),
None
=>
Vec
::
new
(),
}
}
fn
ty_infer
(
&
self
,
span
:
Span
)
->
Ty
<
'tcx
>
{
fn
ty_infer
(
&
self
,
span
:
Span
)
->
Ty
<
'tcx
>
{
span_err!
(
self
.tcx
()
.sess
,
span
,
E0121
,
span_err!
(
self
.tcx
()
.sess
,
span
,
E0121
,
"the type placeholder `_` is not allowed within types on item signatures"
);
"the type placeholder `_` is not allowed within types on item signatures"
);
...
@@ -1596,7 +1608,7 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
...
@@ -1596,7 +1608,7 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
// Now create the real type parameters.
// Now create the real type parameters.
for
(
i
,
param
)
in
types
.iter
()
.enumerate
()
{
for
(
i
,
param
)
in
types
.iter
()
.enumerate
()
{
let
def
=
get_or_create_type_parameter_def
(
ccx
,
space
,
param
,
i
as
u32
,
where_clause
);
let
def
=
get_or_create_type_parameter_def
(
ccx
,
&
result
,
space
,
param
,
i
as
u32
);
debug!
(
"ty_generics: def for type param: {:?}, {:?}"
,
def
,
space
);
debug!
(
"ty_generics: def for type param: {:?}, {:?}"
,
def
,
space
);
result
.types
.push
(
space
,
def
);
result
.types
.push
(
space
,
def
);
}
}
...
@@ -1605,6 +1617,7 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
...
@@ -1605,6 +1617,7 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
}
}
fn
get_or_create_type_parameter_def
<
'a
,
'tcx
>
(
ccx
:
&
CrateCtxt
<
'a
,
'tcx
>
,
fn
get_or_create_type_parameter_def
<
'a
,
'tcx
>
(
ccx
:
&
CrateCtxt
<
'a
,
'tcx
>
,
generics_so_far
:
&
ty
::
Generics
<
'tcx
>
,
space
:
subst
::
ParamSpace
,
space
:
subst
::
ParamSpace
,
param
:
&
ast
::
TyParam
,
param
:
&
ast
::
TyParam
,
index
:
u32
,
index
:
u32
,
...
@@ -1619,7 +1632,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
...
@@ -1619,7 +1632,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
let
param_ty
=
ty
::
ParamTy
::
new
(
space
,
index
,
param
.ident.name
);
let
param_ty
=
ty
::
ParamTy
::
new
(
space
,
index
,
param
.ident.name
);
let
bounds
=
compute_bounds
(
ccx
,
let
bounds
=
compute_bounds
(
ccx
,
&
ty
::
Generics
::
empty
()
,
generics_so_far
,
param_ty
.to_ty
(
ccx
.tcx
),
param_ty
.to_ty
(
ccx
.tcx
),
&
param
.bounds
,
&
param
.bounds
,
SizedByDefault
::
Yes
,
SizedByDefault
::
Yes
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录