Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fc9c4c32
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,发现更多精彩内容 >>
提交
fc9c4c32
编写于
7月 10, 2012
作者:
L
Lindsey Kuper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Front-end support for default impls in traits.
上级
d5563d73
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
252 addition
and
68 deletion
+252
-68
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+10
-1
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+3
-0
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+43
-13
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+9
-1
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+23
-1
src/rustc/metadata/encoder.rs
src/rustc/metadata/encoder.rs
+15
-6
src/rustc/middle/resolve.rs
src/rustc/middle/resolve.rs
+33
-6
src/rustc/middle/resolve3.rs
src/rustc/middle/resolve3.rs
+47
-22
src/rustc/middle/typeck.rs
src/rustc/middle/typeck.rs
+1
-0
src/rustc/middle/typeck/collect.rs
src/rustc/middle/typeck/collect.rs
+9
-2
src/rustdoc/attr_pass.rs
src/rustdoc/attr_pass.rs
+8
-1
src/rustdoc/doc.rs
src/rustdoc/doc.rs
+7
-1
src/rustdoc/extract.rs
src/rustdoc/extract.rs
+24
-8
src/rustdoc/tystr_pass.rs
src/rustdoc/tystr_pass.rs
+20
-6
未找到文件。
src/libsyntax/ast.rs
浏览文件 @
fc9c4c32
...
...
@@ -452,6 +452,15 @@ enum lit_ {
type
ty_method
=
{
ident
:
ident
,
attrs
:
~
[
attribute
],
decl
:
fn_decl
,
tps
:
~
[
ty_param
],
span
:
span
};
#[auto_serialize]
// A trait method is either required (meaning it doesn't have an
// implementation, just a signature) or provided (meaning it has a default
// implementation).
enum
trait_method
{
required
(
ty_method
),
provided
(
@
method
),
}
#[auto_serialize]
enum
int_ty
{
ty_i
,
ty_char
,
ty_i8
,
ty_i16
,
ty_i32
,
ty_i64
,
}
...
...
@@ -695,7 +704,7 @@ enum item_ {
/* dtor is optional */
option
<
class_dtor
>
),
item_trait
(
~
[
ty_param
],
~
[
t
y
_method
]),
item_trait
(
~
[
ty_param
],
~
[
t
rait
_method
]),
item_impl
(
~
[
ty_param
],
option
<@
trait_ref
>
/* trait */
,
@
ty
/* self */
,
~
[
@
method
]),
item_mac
(
mac
),
...
...
src/libsyntax/ast_util.rs
浏览文件 @
fc9c4c32
...
...
@@ -511,6 +511,9 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
visit_ty_method
:
fn
@
(
_
ty_m
:
ty_method
)
{
},
visit_trait_method
:
fn
@
(
_
ty_m
:
trait_method
)
{
},
visit_class_item
:
fn
@
(
c
:
@
class_member
)
{
alt
c
.node
{
instance_var
(
_
,
_
,
_
,
id
,
_
)
{
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
fc9c4c32
...
...
@@ -42,14 +42,14 @@
mtc_rep
,
mtc_tok
,
mul
,
mutability
,
neg
,
noreturn
,
not
,
pat
,
pat_box
,
pat_enum
,
pat_ident
,
pat_lit
,
pat_range
,
pat_rec
,
pat_tup
,
pat_uniq
,
pat_wild
,
path
,
private
,
proto
,
proto_any
,
proto_bare
,
proto_block
,
proto_box
,
proto_uniq
,
p
ublic
,
pure_fn
,
pur
ity
,
re_anon
,
re_named
,
region
,
rem
,
ret_style
,
ret
urn_val
,
shl
,
shr
,
stmt
,
stmt_decl
,
stmt_
expr
,
stmt_semi
,
subtract
,
token_tree
,
trait_ref
,
tt_delim
,
tt_d
otdotdot
,
tt_flat
,
tt_interpolate
,
ty
,
ty_
,
ty_bot
,
ty_box
,
ty_
constr
,
ty_constr_
,
ty_constr_arg
,
ty_field
,
ty_fn
,
ty_infer
,
ty_
mac
,
ty_method
,
ty_nil
,
ty_param
,
ty_path
,
ty_ptr
,
ty_rec
,
ty_rptr
,
ty_tup
,
ty_u32
,
ty_uniq
,
ty_vec
,
ty_vstore
,
proto_bare
,
proto_block
,
proto_box
,
proto_uniq
,
p
rovided
,
public
,
pur
e_fn
,
purity
,
re_anon
,
re_named
,
region
,
rem
,
required
,
ret
_style
,
return_val
,
shl
,
shr
,
stmt
,
stmt_decl
,
stmt_expr
,
stmt_
semi
,
subtract
,
token_tree
,
trait_method
,
trait_ref
,
tt_d
elim
,
tt_dotdotdot
,
tt_flat
,
tt_interpolate
,
ty
,
ty_
,
ty_bot
,
ty_
box
,
ty_constr
,
ty_constr_
,
ty_constr_arg
,
ty_field
,
ty_fn
,
ty_
infer
,
ty_mac
,
ty_method
,
ty_nil
,
ty_param
,
ty_path
,
ty_ptr
,
ty_r
ec
,
ty_r
ptr
,
ty_tup
,
ty_u32
,
ty_uniq
,
ty_vec
,
ty_vstore
,
unchecked_blk
,
uniq
,
unsafe_blk
,
unsafe_fn
,
variant
,
view_item
,
view_item_
,
view_item_export
,
view_item_import
,
view_item_use
,
view_path
,
view_path_glob
,
view_path_list
,
view_path_simple
,
...
...
@@ -275,7 +275,7 @@ fn parse_ty_fn_decl(purity: ast::purity) -> fn_decl {
constraints
:
constrs
};
}
fn
parse_t
y_methods
()
->
~
[
ty
_method
]
{
fn
parse_t
rait_methods
()
->
~
[
trait
_method
]
{
do
self
.parse_unspanned_seq
(
token
::
LBRACE
,
token
::
RBRACE
,
seq_sep_none
())
|
p
|
{
let
attrs
=
p
.parse_outer_attributes
();
...
...
@@ -284,12 +284,42 @@ fn parse_ty_methods() -> ~[ty_method] {
let
ident
=
p
.parse_method_name
();
let
tps
=
p
.parse_ty_params
();
let
d
=
p
.parse_ty_fn_decl
(
pur
),
fhi
=
p
.last_span.hi
;
self
.expect
(
token
::
SEMI
);
{
ident
:
ident
,
attrs
:
attrs
,
decl
:
{
purity
:
pur
with
d
},
tps
:
tps
,
span
:
mk_sp
(
flo
,
fhi
)}
#
debug
[
"parse_trait_methods(): trait method ends in %s"
,
token_to_str
(
self
.reader
,
self
.token
)];
alt
self
.token
{
token
::
SEMI
{
self
.bump
();
required
({
ident
:
ident
,
attrs
:
attrs
,
decl
:
{
purity
:
pur
with
d
},
tps
:
tps
,
span
:
mk_sp
(
flo
,
fhi
)})
}
token
::
LBRACE
{
self
.bump
();
let
(
inner_attrs
,
body
)
=
self
.parse_inner_attrs_and_block
(
true
);
let
attrs
=
vec
::
append
(
attrs
,
inner_attrs
);
self
.eat
(
token
::
RBRACE
);
provided
(
@
{
ident
:
ident
,
attrs
:
attrs
,
tps
:
tps
,
decl
:
d
,
body
:
body
,
id
:
self
.get_id
(),
span
:
mk_sp
(
flo
,
fhi
),
self_id
:
self
.get_id
(),
// Provided traits methods always public for now
vis
:
public
})
}
_
{
self
.fatal
(
"expected ';' or '}`
\
but found `"
+
token_to_str
(
self
.reader
,
self
.token
)
+
"`"
);
}
}
}
}
fn
parse_mt
()
->
mt
{
let
mutbl
=
self
.parse_mutability
();
let
t
=
self
.parse_ty
(
false
);
...
...
@@ -2127,7 +2157,7 @@ fn parse_item_trait() -> item_info {
let
ident
=
self
.parse_ident
();
self
.parse_region_param
();
let
tps
=
self
.parse_ty_params
();
let
meths
=
self
.parse_t
y
_methods
();
let
meths
=
self
.parse_t
rait
_methods
();
(
ident
,
item_trait
(
tps
,
meths
),
none
)
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
fc9c4c32
...
...
@@ -5,6 +5,7 @@
space
,
zerobreak
,
hardbreak
,
breaks
,
consistent
,
inconsistent
,
eof
};
import
diagnostic
;
import
ast
::{
required
,
provided
};
import
ast_util
::
operator_prec
;
import
dvec
::{
dvec
,
extensions
};
import
parse
::
classify
::
*
;
...
...
@@ -593,7 +594,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_type_params
(
s
,
tps
);
word
(
s
.s
,
" "
);
bopen
(
s
);
for
methods
.each
|
meth
|
{
print_t
y
_method
(
s
,
meth
);
}
for
methods
.each
|
meth
|
{
print_t
rait
_method
(
s
,
meth
);
}
bclose
(
s
,
item
.span
);
}
ast
::
item_mac
({
node
:
ast
::
mac_invoc_tt
(
pth
,
tts
),
_
})
{
...
...
@@ -647,6 +648,13 @@ fn print_ty_method(s: ps, m: ast::ty_method) {
word
(
s
.s
,
";"
);
}
fn
print_trait_method
(
s
:
ps
,
m
:
ast
::
trait_method
)
{
alt
m
{
required
(
ty_m
)
{
print_ty_method
(
s
,
ty_m
)
}
provided
(
m
)
{
print_method
(
s
,
m
)
}
}
}
fn
print_method
(
s
:
ps
,
meth
:
@
ast
::
method
)
{
hardbreak_if_not_bol
(
s
);
maybe_print_comment
(
s
,
meth
.span.lo
);
...
...
src/libsyntax/visit.rs
浏览文件 @
fc9c4c32
...
...
@@ -62,6 +62,7 @@ fn tps_of_fn(fk: fn_kind) -> ~[ty_param] {
visit_constr
:
fn
@
(
@
path
,
span
,
node_id
,
E
,
vt
<
E
>
),
visit_fn
:
fn
@
(
fn_kind
,
fn_decl
,
blk
,
span
,
node_id
,
E
,
vt
<
E
>
),
visit_ty_method
:
fn
@
(
ty_method
,
E
,
vt
<
E
>
),
visit_trait_method
:
fn
@
(
trait_method
,
E
,
vt
<
E
>
),
visit_class_item
:
fn
@
(
@
class_member
,
E
,
vt
<
E
>
)};
fn
default_visitor
<
E
>
()
->
visitor
<
E
>
{
...
...
@@ -81,6 +82,7 @@ fn default_visitor<E>() -> visitor<E> {
visit_constr
:
|
a
,
b
,
c
,
d
,
e
|
visit_constr
::
<
E
>
(
a
,
b
,
c
,
d
,
e
),
visit_fn
:
|
a
,
b
,
c
,
d
,
e
,
f
,
g
|
visit_fn
::
<
E
>
(
a
,
b
,
c
,
d
,
e
,
f
,
g
),
visit_ty_method
:
|
a
,
b
,
c
|
visit_ty_method
::
<
E
>
(
a
,
b
,
c
),
visit_trait_method
:
|
a
,
b
,
c
|
visit_trait_method
::
<
E
>
(
a
,
b
,
c
),
visit_class_item
:
|
a
,
b
,
c
|
visit_class_item
::
<
E
>
(
a
,
b
,
c
)};
}
...
...
@@ -160,7 +162,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
item_trait
(
tps
,
methods
)
{
v
.visit_ty_params
(
tps
,
e
,
v
);
for
methods
.each
|
m
|
{
v
.visit_t
y
_method
(
m
,
e
,
v
);
v
.visit_t
rait
_method
(
m
,
e
,
v
);
}
}
item_mac
(
m
)
{
visit_mac
(
m
,
e
,
v
)
}
...
...
@@ -317,6 +319,17 @@ fn visit_ty_method<E>(m: ty_method, e: E, v: vt<E>) {
v
.visit_ty
(
m
.decl.output
,
e
,
v
);
}
fn
visit_trait_method
<
E
>
(
m
:
trait_method
,
e
:
E
,
v
:
vt
<
E
>
)
{
alt
m
{
required
(
ty_m
)
{
v
.visit_ty_method
(
ty_m
,
e
,
v
)
}
provided
(
m
)
{
visit_method_helper
(
m
,
e
,
v
)
}
}
}
fn
visit_block
<
E
>
(
b
:
ast
::
blk
,
e
:
E
,
v
:
vt
<
E
>
)
{
for
b
.node.view_items.each
|
vi
|
{
v
.visit_view_item
(
vi
,
e
,
v
);
}
for
b
.node.stmts.each
|
s
|
{
v
.visit_stmt
(
s
,
e
,
v
);
}
...
...
@@ -465,6 +478,7 @@ fn visit_arm<E>(a: arm, e: E, v: vt<E>) {
visit_constr
:
fn
@
(
@
path
,
span
,
node_id
),
visit_fn
:
fn
@
(
fn_kind
,
fn_decl
,
blk
,
span
,
node_id
),
visit_ty_method
:
fn
@
(
ty_method
),
visit_trait_method
:
fn
@
(
trait_method
),
visit_class_item
:
fn
@
(
@
class_member
)};
fn
simple_ignore_ty
(
_
t
:
@
ty
)
{}
...
...
@@ -487,6 +501,7 @@ fn default_simple_visitor() -> simple_visitor {
visit_fn
:
fn
@
(
_
fk
:
fn_kind
,
_
d
:
fn_decl
,
_
b
:
blk
,
_
sp
:
span
,
_
id
:
node_id
)
{
},
visit_ty_method
:
fn
@
(
_
m
:
ty_method
)
{
},
visit_trait_method
:
fn
@
(
_
m
:
trait_method
)
{
},
visit_class_item
:
fn
@
(
_
c
:
@
class_member
)
{}
};
}
...
...
@@ -546,6 +561,11 @@ fn v_ty_method(f: fn@(ty_method), ty: ty_method, &&e: (), v: vt<()>) {
f
(
ty
);
visit_ty_method
(
ty
,
e
,
v
);
}
fn
v_trait_method
(
f
:
fn
@
(
trait_method
),
m
:
trait_method
,
&&
e
:
(),
v
:
vt
<
()
>
)
{
f
(
m
);
visit_trait_method
(
m
,
e
,
v
);
}
fn
v_ty_params
(
f
:
fn
@
(
~
[
ty_param
]),
ps
:
~
[
ty_param
],
&&
e
:
(),
v
:
vt
<
()
>
)
{
...
...
@@ -596,6 +616,8 @@ fn v_class_item(f: fn@(@class_member),
v_fn
(
v
.visit_fn
,
a
,
b
,
c
,
d
,
e
,
f
,
g
),
visit_ty_method
:
|
a
,
b
,
c
|
v_ty_method
(
v
.visit_ty_method
,
a
,
b
,
c
),
visit_trait_method
:
|
a
,
b
,
c
|
v_trait_method
(
v
.visit_trait_method
,
a
,
b
,
c
),
visit_class_item
:
|
a
,
b
,
c
|
v_class_item
(
v
.visit_class_item
,
a
,
b
,
c
)
});
...
...
src/rustc/metadata/encoder.rs
浏览文件 @
fc9c4c32
...
...
@@ -744,12 +744,21 @@ fn add_to_index_(item: @item, ebml_w: ebml::writer,
encode_name
(
ebml_w
,
item
.ident
);
let
mut
i
=
0u
;
for
vec
::
each
(
*
ty
::
trait_methods
(
tcx
,
local_def
(
item
.id
)))
|
mty
|
{
ebml_w
.start_tag
(
tag_item_trait_method
);
encode_name
(
ebml_w
,
mty
.ident
);
encode_type_param_bounds
(
ebml_w
,
ecx
,
ms
[
i
]
.tps
);
encode_type
(
ecx
,
ebml_w
,
ty
::
mk_fn
(
tcx
,
mty
.fty
));
encode_family
(
ebml_w
,
purity_fn_family
(
mty
.purity
));
ebml_w
.end_tag
();
alt
ms
[
i
]
{
required
(
ty_m
)
{
ebml_w
.start_tag
(
tag_item_trait_method
);
encode_name
(
ebml_w
,
mty
.ident
);
encode_type_param_bounds
(
ebml_w
,
ecx
,
ty_m
.tps
);
encode_type
(
ecx
,
ebml_w
,
ty
::
mk_fn
(
tcx
,
mty
.fty
));
encode_family
(
ebml_w
,
purity_fn_family
(
mty
.purity
));
ebml_w
.end_tag
();
}
provided
(
m
)
{
encode_info_for_method
(
ecx
,
ebml_w
,
path
,
should_inline
(
m
.attrs
),
item
.id
,
m
,
m
.tps
);
}
}
i
+=
1u
;
}
encode_path
(
ebml_w
,
path
,
ast_map
::
path_name
(
item
.ident
));
...
...
src/rustc/middle/resolve.rs
浏览文件 @
fc9c4c32
import
syntax
::{
ast
,
ast_util
,
codemap
,
ast_map
};
import
syntax
::
ast
::
*
;
import
ast
::{
ident
,
fn_ident
,
def
,
def_id
,
node_id
};
import
ast
::{
required
,
provided
};
import
syntax
::
ast_util
::{
local_def
,
def_id_of_def
,
new_def_hash
,
class_item_ident
,
path_to_ident
};
import
pat_util
::
*
;
...
...
@@ -566,12 +567,8 @@ fn visit_item_with_scope(e: @env, i: @ast::item,
}
ast
::
item_trait
(
tps
,
methods
)
{
v
.visit_ty_params
(
tps
,
sc
,
v
);
let
isc
=
@
cons
(
scope_method
(
i
.id
,
tps
),
sc
);
for
methods
.each
|
m
|
{
v
.visit_ty_params
(
m
.tps
,
isc
,
v
);
let
msc
=
@
cons
(
scope_method
(
i
.id
,
vec
::
append
(
tps
,
m
.tps
)),
sc
);
for
m
.decl.inputs.each
|
a
|
{
v
.visit_ty
(
a
.ty
,
msc
,
v
);
}
v
.visit_ty
(
m
.decl.output
,
msc
,
v
);
visit_trait_method
(
m
,
i
,
tps
,
sc
,
v
);
}
}
ast
::
item_class
(
tps
,
traits
,
members
,
ctor
,
m_dtor
)
{
...
...
@@ -618,6 +615,27 @@ fn visit_item_with_scope(e: @env, i: @ast::item,
e
.resolve_unexported
=
old_resolve_unexported
;
}
fn
visit_trait_method
(
m
:
trait_method
,
i
:
@
ast
::
item
,
tps
:
~
[
ast
::
ty_param
],
sc
:
scopes
,
v
:
vt
<
scopes
>
)
{
alt
m
{
required
(
ty_m
)
{
let
isc
=
@
cons
(
scope_method
(
i
.id
,
tps
),
sc
);
v
.visit_ty_params
(
ty_m
.tps
,
isc
,
v
);
let
msc
=
@
cons
(
scope_method
(
i
.id
,
vec
::
append
(
tps
,
ty_m
.tps
)),
sc
);
for
ty_m
.decl.inputs.each
|
a
|
{
v
.visit_ty
(
a
.ty
,
msc
,
v
);
}
v
.visit_ty
(
ty_m
.decl.output
,
msc
,
v
);
}
provided
(
m
)
{
v
.visit_ty_params
(
m
.tps
,
sc
,
v
);
let
msc
=
@
cons
(
scope_method
(
m
.self_id
,
vec
::
append
(
tps
,
m
.tps
)),
sc
);
v
.visit_fn
(
visit
::
fk_method
(
m
.ident
,
~
[],
m
),
m
.decl
,
m
.body
,
m
.span
,
m
.id
,
msc
,
v
);
}
}
}
fn
visit_foreign_item_with_scope
(
ni
:
@
ast
::
foreign_item
,
&&
sc
:
scopes
,
v
:
vt
<
scopes
>
)
{
visit
::
visit_foreign_item
(
ni
,
@
cons
(
scope_foreign_item
(
ni
),
sc
),
v
);
...
...
@@ -1785,7 +1803,16 @@ fn typaram_names(tps: ~[ast::ty_param]) -> ~[ident] {
"type parameter"
);
}
ast
::
item_trait
(
_
,
methods
)
{
ensure_unique
(
*
e
,
i
.span
,
methods
,
|
m
|
m
.ident
,
ensure_unique
(
*
e
,
i
.span
,
methods
,
|
m
|
{
alt
m
{
required
(
ty_m
)
{
ty_m
.ident
}
provided
(
m
)
{
m
.ident
}
}
},
"method"
);
}
ast
::
item_impl
(
_
,
_
,
_
,
methods
)
{
...
...
src/rustc/middle/resolve3.rs
浏览文件 @
fc9c4c32
...
...
@@ -26,6 +26,7 @@
import
syntax
::
ast
::{
ty_u8
,
ty_uint
,
variant
,
view_item
,
view_item_export
};
import
syntax
::
ast
::{
view_item_import
,
view_item_use
,
view_path_glob
};
import
syntax
::
ast
::{
view_path_list
,
view_path_simple
};
import
syntax
::
ast
::{
required
,
provided
};
import
syntax
::
ast_util
::{
def_id_of_def
,
dummy_sp
,
local_def
,
new_def_hash
};
import
syntax
::
ast_util
::{
walk_pat
};
import
syntax
::
attr
::{
attr_metas
,
contains_name
};
...
...
@@ -2928,21 +2929,33 @@ fn resolve_item(item: @item, visitor: ResolveVisitor) {
//
// XXX: Do we need a node ID here?
do
self
.with_type_parameter_rib
(
HasTypeParameters
(
&
method
.tps
,
alt
method
{
required
(
ty_m
)
{
do
self
.with_type_parameter_rib
(
HasTypeParameters
(
&
ty_m
.tps
,
item
.id
,
type_parameters
.len
(),
NormalRibKind
))
||
{
||
{
// Resolve the method-specific type parameters.
self
.resolve_type_parameters
(
method
.tps
,
visitor
);
// Resolve the method-specific type
// parameters.
self
.resolve_type_parameters
(
ty_m
.tps
,
visitor
);
for
method
.decl.inputs.each
|
argument
|
{
self
.resolve_type
(
argument
.ty
,
visitor
);
}
for
ty_m
.decl.inputs.each
|
argument
|
{
self
.resolve_type
(
argument
.ty
,
visitor
);
}
self
.resolve_type
(
method
.decl.output
,
visitor
);
self
.resolve_type
(
ty_m
.decl.output
,
visitor
);
}
}
provided
(
m
)
{
self
.resolve_method
(
NormalRibKind
,
m
,
type_parameters
.len
(),
visitor
)
}
}
}
}
...
...
@@ -3242,19 +3255,10 @@ fn resolve_class(id: node_id,
for
class_members
.each
|
class_member
|
{
alt
class_member
.node
{
class_method
(
method
)
{
let
borrowed_method_type_parameters
=
&
method
.tps
;
let
type_parameters
=
HasTypeParameters
(
borrowed_method_type_parameters
,
method
.id
,
outer_type_parameter_count
,
NormalRibKind
);
self
.resolve_function
(
NormalRibKind
,
some
(
@
method
.decl
),
type_parameters
,
method
.body
,
HasSelfBinding
(
method
.self_id
),
NoCaptureClause
,
visitor
);
self
.resolve_method
(
NormalRibKind
,
method
,
outer_type_parameter_count
,
visitor
);
}
instance_var
(
_
,
field_type
,
_
,
_
,
_
)
{
self
.resolve_type
(
field_type
,
visitor
);
...
...
@@ -3291,6 +3295,27 @@ fn resolve_class(id: node_id,
}
}
// Does this really need to take a RibKind or is it always going
// to be NormalRibKind?
fn
resolve_method
(
rib_kind
:
RibKind
,
method
:
@
method
,
outer_type_parameter_count
:
uint
,
visitor
:
ResolveVisitor
)
{
let
borrowed_method_type_parameters
=
&
method
.tps
;
let
type_parameters
=
HasTypeParameters
(
borrowed_method_type_parameters
,
method
.id
,
outer_type_parameter_count
,
rib_kind
);
self
.resolve_function
(
rib_kind
,
some
(
@
method
.decl
),
type_parameters
,
method
.body
,
HasSelfBinding
(
method
.self_id
),
NoCaptureClause
,
visitor
);
}
fn
resolve_implementation
(
id
:
node_id
,
span
:
span
,
type_parameters
:
~
[
ty_param
],
...
...
src/rustc/middle/typeck.rs
浏览文件 @
fc9c4c32
...
...
@@ -41,6 +41,7 @@
import
result
::{
result
,
extensions
};
import
syntax
::{
ast
,
ast_util
,
ast_map
};
import
ast
::
spanned
;
import
ast
::{
required
,
provided
};
import
syntax
::
ast_map
::
node_id_to_str
;
import
syntax
::
ast_util
::{
local_def
,
respan
,
split_class_items
};
import
syntax
::
visit
;
...
...
src/rustc/middle/typeck/collect.rs
浏览文件 @
fc9c4c32
...
...
@@ -147,8 +147,15 @@ fn store_methods<T>(ccx: @crate_ctxt, id: ast::node_id,
let
rp
=
tcx
.region_paramd_items
.contains_key
(
id
);
alt
check
tcx
.items
.get
(
id
)
{
ast_map
::
node_item
(
@
{
node
:
ast
::
item_trait
(
_
,
ms
),
_
},
_
)
{
store_methods
::
<
ast
::
ty_method
>
(
ccx
,
id
,
ms
,
|
m
|
{
ty_of_ty_method
(
ccx
,
m
,
rp
)
store_methods
::
<
ast
::
trait_method
>
(
ccx
,
id
,
ms
,
|
m
|
{
alt
m
{
required
(
ty_m
)
{
ty_of_ty_method
(
ccx
,
ty_m
,
rp
)
}
provided
(
m
)
{
ty_of_method
(
ccx
,
m
,
rp
)
}
}
});
}
ast_map
::
node_item
(
@
{
node
:
ast
::
item_class
(
_
,
_
,
its
,
_
,
_
),
_
},
_
)
{
...
...
src/rustdoc/attr_pass.rs
浏览文件 @
fc9c4c32
...
...
@@ -207,7 +207,14 @@ fn merge_method_attrs(
node
:
ast
::
item_trait
(
_
,
methods
),
_
},
_
)
{
par
::
seqmap
(
methods
,
|
method
|
{
(
*
method
.ident
,
attr_parser
::
parse_desc
(
method
.attrs
))
alt
method
{
ast
::
required
(
ty_m
)
{
(
*
ty_m
.ident
,
attr_parser
::
parse_desc
(
ty_m
.attrs
))
}
ast
::
provided
(
m
)
{
(
*
m
.ident
,
attr_parser
::
parse_desc
(
m
.attrs
))
}
}
})
}
ast_map
::
node_item
(
@
{
...
...
src/rustdoc/doc.rs
浏览文件 @
fc9c4c32
...
...
@@ -11,6 +11,11 @@ enum page {
itempage
(
itemtag
)
}
enum
implementation
{
required
,
provided
,
}
/**
* Most rustdocs can be parsed into 'sections' according to their markdown
* headers
...
...
@@ -91,7 +96,8 @@ enum itemtag {
brief
:
option
<
str
>
,
desc
:
option
<
str
>
,
sections
:
~
[
section
],
sig
:
option
<
str
>
sig
:
option
<
str
>
,
implementation
:
implementation
,
};
type
impldoc
=
{
...
...
src/rustdoc/extract.rs
浏览文件 @
fc9c4c32
...
...
@@ -185,17 +185,32 @@ fn should_extract_enum_variants() {
fn
traitdoc_from_trait
(
itemdoc
:
doc
::
itemdoc
,
methods
:
~
[
ast
::
t
y
_method
]
methods
:
~
[
ast
::
t
rait
_method
]
)
->
doc
::
traitdoc
{
{
item
:
itemdoc
,
methods
:
do
par
::
seqmap
(
methods
)
|
method
|
{
{
name
:
*
method
.ident
,
brief
:
none
,
desc
:
none
,
sections
:
~
[],
sig
:
none
alt
method
{
ast
::
required
(
ty_m
)
{
{
name
:
*
ty_m
.ident
,
brief
:
none
,
desc
:
none
,
sections
:
~
[],
sig
:
none
,
implementation
:
doc
::
required
,
}
}
ast
::
provided
(
m
)
{
{
name
:
*
m
.ident
,
brief
:
none
,
desc
:
none
,
sections
:
~
[],
sig
:
none
,
implementation
:
doc
::
provided
,
}
}
}
}
}
...
...
@@ -227,7 +242,8 @@ fn impldoc_from_impl(
brief
:
none
,
desc
:
none
,
sections
:
~
[],
sig
:
none
sig
:
none
,
implementation
:
doc
::
provided
,
}
}
}
...
...
src/rustdoc/tystr_pass.rs
浏览文件 @
fc9c4c32
...
...
@@ -171,14 +171,28 @@ fn get_method_sig(
node
:
ast
::
item_trait
(
_
,
methods
),
_
},
_
)
{
alt
check
vec
::
find
(
methods
,
|
method
|
{
*
method
.ident
==
method_name
alt
method
{
ast
::
required
(
ty_m
)
{
*
ty_m
.ident
==
method_name
}
ast
::
provided
(
m
)
{
*
m
.ident
==
method_name
}
}
})
{
some
(
method
)
{
some
(
pprust
::
fun_to_str
(
method
.decl
,
method
.ident
,
method
.tps
))
alt
method
{
ast
::
required
(
ty_m
)
{
some
(
pprust
::
fun_to_str
(
ty_m
.decl
,
ty_m
.ident
,
ty_m
.tps
))
}
ast
::
provided
(
m
)
{
some
(
pprust
::
fun_to_str
(
m
.decl
,
m
.ident
,
m
.tps
))
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录