Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5ea3c969
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,发现更多精彩内容 >>
提交
5ea3c969
编写于
1月 03, 2012
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Wire in resolution of param bounds for method calls
Issue #1227
上级
506a6ec3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
15 deletion
+61
-15
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+0
-2
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+39
-13
src/test/run-pass/iface-to-str.rs
src/test/run-pass/iface-to-str.rs
+22
-0
未找到文件。
src/comp/middle/ty.rs
浏览文件 @
5ea3c969
...
...
@@ -1462,8 +1462,6 @@ fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool {
// Type lookups
fn
node_id_to_ty_param_substs_opt_and_ty
(
cx
:
ctxt
,
id
:
ast
::
node_id
)
->
ty_param_substs_opt_and_ty
{
// Pull out the node type table.
alt
smallintmap
::
find
(
*
cx
.node_types
,
id
as
uint
)
{
none
.
{
...
...
src/comp/middle/typeck.rs
浏览文件 @
5ea3c969
...
...
@@ -2875,11 +2875,21 @@ fn check_for_main_fn(tcx: ty::ctxt, crate: @ast::crate) {
// Detect points where an interface-bounded type parameter is instantiated,
// resolve the impls for the parameters.
fn
resolve_dicts
(
tcx
:
ty
::
ctxt
,
impl_map
:
resolve
::
impl_map
,
crate
:
@
ast
::
crate
)
->
dict_map
{
method_map
:
method_map
,
crate
:
@
ast
::
crate
)
->
dict_map
{
type
ccx
=
{
tcx
:
ty
::
ctxt
,
impl_map
:
resolve
::
impl_map
,
method_map
:
method_map
,
dict_map
:
dict_map
};
let
cx
=
{
tcx
:
tcx
,
impl_map
:
impl_map
,
dict_map
:
new_int_hash
()};
let
cx
=
{
tcx
:
tcx
,
impl_map
:
impl_map
,
method_map
:
method_map
,
dict_map
:
new_int_hash
()};
fn
has_iface_bounds
(
tps
:
[
ty
::
param_bounds
])
->
bool
{
vec
::
any
(
tps
,
{|
bs
|
vec
::
any
(
*
bs
,
{|
b
|
alt
b
{
ty
::
bound_iface
(
_
)
{
true
}
_
{
false
}
}
})
})
}
fn
resolve_expr
(
ex
:
@
ast
::
expr
,
cx
:
ccx
,
v
:
visit
::
vt
<
ccx
>
)
{
alt
ex
.node
{
ast
::
expr_path
(
_
)
{
...
...
@@ -2889,14 +2899,25 @@ fn resolve_expr(ex: @ast::expr, cx: ccx, v: visit::vt<ccx>) {
some
(
ts
)
{
let
did
=
ast_util
::
def_id_of_def
(
cx
.tcx.def_map
.get
(
ex
.id
));
let
item_ty
=
ty
::
lookup_item_type
(
cx
.tcx
,
did
);
if
vec
::
any
(
*
item_ty
.bounds
,
{|
bs
|
vec
::
any
(
*
bs
,
{|
b
|
alt
b
{
ty
::
bound_iface
(
_
)
{
true
}
_
{
false
}
}
})
})
{
if
has_iface_bounds
(
*
item_ty
.bounds
)
{
let
impls
=
cx
.impl_map
.get
(
ex
.id
);
cx
.dict_map
.insert
(
ex
.id
,
lookup_dicts
(
cx
.tcx
,
impls
,
ex
.span
,
*
item_ty
.bounds
,
ts
));
cx
.tcx
,
impls
,
ex
.span
,
item_ty
.bounds
,
ts
));
}
}
_
{}
}
}
// Must resolve bounds on methods with bounded params
ast
::
expr_field
(
_
,
_
,
_
)
{
alt
cx
.method_map
.find
(
ex
.id
)
{
some
(
method_static
(
did
))
{
let
bounds
=
ty
::
lookup_item_type
(
cx
.tcx
,
did
)
.bounds
;
if
has_iface_bounds
(
*
bounds
)
{
let
tys
=
ty
::
node_id_to_type_params
(
cx
.tcx
,
ex
.id
);
let
iscs
=
cx
.impl_map
.get
(
ex
.id
);
cx
.dict_map
.insert
(
ex
.id
,
lookup_dicts
(
cx
.tcx
,
iscs
,
ex
.span
,
bounds
,
tys
));
}
}
_
{}
...
...
@@ -2906,8 +2927,9 @@ fn resolve_expr(ex: @ast::expr, cx: ccx, v: visit::vt<ccx>) {
}
visit
::
visit_expr
(
ex
,
cx
,
v
);
}
fn
lookup_dicts
(
tcx
:
ty
::
ctxt
,
isc
:
resolve
::
iscopes
,
sp
:
span
,
bounds
:
[
ty
::
param_bounds
],
tys
:
[
ty
::
t
])
bounds
:
@
[
ty
::
param_bounds
],
tys
:
[
ty
::
t
])
->
dict_res
{
let
result
=
[],
i
=
0u
;
for
ty
in
tys
{
...
...
@@ -2923,6 +2945,7 @@ fn lookup_dicts(tcx: ty::ctxt, isc: resolve::iscopes, sp: span,
}
@
result
}
fn
lookup_dict
(
tcx
:
ty
::
ctxt
,
isc
:
resolve
::
iscopes
,
sp
:
span
,
ty
:
ty
::
t
,
iface_ty
:
ty
::
t
)
->
dict_origin
{
let
iface_id
=
alt
ty
::
struct
(
tcx
,
iface_ty
)
{
...
...
@@ -2951,6 +2974,7 @@ fn lookup_dict(tcx: ty::ctxt, isc: resolve::iscopes, sp: span,
for
im
in
*
impls
{
if
im
.iface_did
==
some
(
iface_id
)
{
let
self_ty
=
impl_self_ty
(
tcx
,
im
.did
)
.ty
;
let
im_bs
=
ty
::
lookup_item_type
(
tcx
,
im
.did
)
.bounds
;
let
params
=
@
mutable
[
mutable
];
alt
ty
::
unify
::
unify
(
ty
,
self_ty
,
ty
::
unify
::
bind_params
(
params
),
...
...
@@ -2963,9 +2987,10 @@ fn lookup_dict(tcx: ty::ctxt, isc: resolve::iscopes, sp: span,
}
else
{
let
params
=
vec
::
map_mut
(
*
params
,
{|
p
|
option
::
get
(
p
)});
// FIXME[impl] check for sub-bounds
found
=
some
(
dict_static
(
im
.did
,
params
,
@
[]));
let
subres
=
lookup_dicts
(
tcx
,
isc
,
sp
,
im_bs
,
params
);
found
=
some
(
dict_static
(
im
.did
,
params
,
subres
));
}
}
_
{}
...
...
@@ -2985,6 +3010,7 @@ fn lookup_dict(tcx: ty::ctxt, isc: resolve::iscopes, sp: span,
ty_to_str
(
tcx
,
iface_ty
)
+
" for "
+
ty_to_str
(
tcx
,
ty
));
}
visit
::
visit_crate
(
*
crate
,
cx
,
visit
::
mk_vt
(
@
{
visit_expr
:
resolve_expr
with
*
visit
::
default_visitor
()
...
...
@@ -3006,7 +3032,7 @@ fn check_crate(tcx: ty::ctxt, impl_map: resolve::impl_map,
bind
check_native_item
(
ccx
,
_
)
with
*
visit
::
default_simple_visitor
()});
visit
::
visit_crate
(
*
crate
,
(),
visit
);
let
dict_map
=
resolve_dicts
(
tcx
,
impl_map
,
crate
);
let
dict_map
=
resolve_dicts
(
tcx
,
impl_map
,
c
cx
.method_map
,
c
rate
);
check_for_main_fn
(
tcx
,
crate
);
tcx
.sess
.abort_if_errors
();
(
ccx
.method_map
,
dict_map
)
...
...
src/test/run-pass/iface-to-str.rs
0 → 100644
浏览文件 @
5ea3c969
iface
to_str
{
fn
to_str
()
->
str
;
}
impl
of
to_str
for
int
{
fn
to_str
()
->
str
{
int
::
str
(
self
)
}
}
impl
<
T
:
to_str
>
of
to_str
for
[
T
]
{
fn
to_str
()
->
str
{
"["
+
str
::
connect
(
vec
::
map
(
self
,
{|
e
|
e
.to_str
()}),
", "
)
+
"]"
}
}
fn
main
()
{
fn
indirect
<
T
:
to_str
>
(
x
:
T
)
->
str
{
x
.to_str
()
+
"!"
}
assert
1
.to_str
()
==
"1"
;
assert
[
2
,
3
,
4
]
.to_str
()
==
"[2, 3, 4]"
;
assert
indirect
([
10
,
20
])
==
"[10, 20]!"
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录