Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
23bfa600
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,发现更多精彩内容 >>
提交
23bfa600
编写于
8月 22, 2013
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #8659 : msullivan/rust/default-methods, r=alexcrichton
上级
f8584523
7b08b2c8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
92 addition
and
21 deletion
+92
-21
src/librustc/middle/liveness.rs
src/librustc/middle/liveness.rs
+1
-1
src/librustc/middle/trans/meth.rs
src/librustc/middle/trans/meth.rs
+11
-8
src/librustc/middle/typeck/check/method.rs
src/librustc/middle/typeck/check/method.rs
+12
-3
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/mod.rs
+2
-2
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/collect.rs
+8
-2
src/librustpkg/tests.rs
src/librustpkg/tests.rs
+1
-0
src/libsyntax/ast_map.rs
src/libsyntax/ast_map.rs
+11
-5
src/test/run-pass/trait-object-generics.rs
src/test/run-pass/trait-object-generics.rs
+46
-0
未找到文件。
src/librustc/middle/liveness.rs
浏览文件 @
23bfa600
...
...
@@ -1617,7 +1617,7 @@ pub fn report_illegal_read(&self,
pub
fn
should_warn
(
&
self
,
var
:
Variable
)
->
Option
<@
str
>
{
let
name
=
self
.ir
.variable_name
(
var
);
if
name
[
0
]
==
(
'_'
as
u8
)
{
None
}
else
{
Some
(
name
)
}
if
name
.len
()
==
0
||
name
[
0
]
==
(
'_'
as
u8
)
{
None
}
else
{
Some
(
name
)
}
}
pub
fn
warn_about_unused_args
(
&
self
,
decl
:
&
fn_decl
,
entry_ln
:
LiveNode
)
{
...
...
src/librustc/middle/trans/meth.rs
浏览文件 @
23bfa600
...
...
@@ -577,20 +577,23 @@ fn emit_vtable_methods(bcx: @mut Block,
let
trait_method_def_ids
=
ty
::
trait_method_def_ids
(
tcx
,
trt_id
);
do
trait_method_def_ids
.map
|
method_def_id
|
{
let
im
=
ty
::
method
(
tcx
,
*
method_def_id
);
let
ident
=
ty
::
method
(
tcx
,
*
method_def_id
)
.ident
;
// The substitutions we have are on the impl, so we grab
// the method type from the impl to substitute into.
let
m_id
=
method_with_name
(
ccx
,
impl_id
,
ident
);
let
m
=
ty
::
method
(
tcx
,
m_id
);
debug!
(
"(making impl vtable) emitting method %s at subst %s"
,
m
.repr
(
tcx
),
substs
.repr
(
tcx
));
let
fty
=
ty
::
subst_tps
(
tcx
,
substs
,
None
,
ty
::
mk_bare_fn
(
tcx
,
i
m
.fty
.clone
()));
if
i
m
.generics
.has_type_params
()
||
ty
::
type_has_self
(
fty
)
{
ty
::
mk_bare_fn
(
tcx
,
m
.fty
.clone
()));
if
m
.generics
.has_type_params
()
||
ty
::
type_has_self
(
fty
)
{
debug!
(
"(making impl vtable) method has self or type params: %s"
,
tcx
.sess
.str_of
(
i
m
.i
dent
));
tcx
.sess
.str_of
(
ident
));
C_null
(
Type
::
nil
()
.ptr_to
())
}
else
{
debug!
(
"(making impl vtable) adding method to vtable: %s"
,
tcx
.sess
.str_of
(
im
.ident
));
let
m_id
=
method_with_name
(
ccx
,
impl_id
,
im
.ident
);
trans_fn_ref_with_vtables
(
bcx
,
m_id
,
0
,
substs
,
Some
(
vtables
))
.llfn
}
...
...
src/librustc/middle/typeck/check/method.rs
浏览文件 @
23bfa600
...
...
@@ -938,9 +938,18 @@ fn confirm_candidate(&self, rcvr_ty: ty::t, candidate: &Candidate)
// static methods should never have gotten this far:
assert
!
(
candidate
.method_ty.explicit_self
!=
sty_static
);
let
transformed_self_ty
=
ty
::
subst
(
tcx
,
&
candidate
.rcvr_substs
,
candidate
.method_ty.transformed_self_ty
.unwrap
());
let
transformed_self_ty
=
match
candidate
.origin
{
method_object
(
*
)
=>
{
// For annoying reasons, we've already handled the
// substitution for object calls.
candidate
.method_ty.transformed_self_ty
.unwrap
()
}
_
=>
{
ty
::
subst
(
tcx
,
&
candidate
.rcvr_substs
,
candidate
.method_ty.transformed_self_ty
.unwrap
())
}
};
// Determine the values for the type parameters of the method.
// If they were not explicitly supplied, just construct fresh
...
...
src/librustc/middle/typeck/check/mod.rs
浏览文件 @
23bfa600
...
...
@@ -3092,7 +3092,6 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt,
sp
:
span
,
defn
:
ast
::
def
)
->
ty_param_bounds_and_ty
{
match
defn
{
ast
::
def_arg
(
nid
,
_
)
|
ast
::
def_local
(
nid
,
_
)
|
ast
::
def_self
(
nid
,
_
)
|
ast
::
def_binding
(
nid
,
_
)
=>
{
...
...
@@ -3149,7 +3148,8 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
let
ty_param_count
=
tpt
.generics.type_param_defs
.len
();
let
ty_substs_len
=
pth
.types
.len
();
debug!
(
"ty_param_count=%? ty_substs_len=%?"
,
debug!
(
"tpt=%s ty_param_count=%? ty_substs_len=%?"
,
tpt
.repr
(
fcx
.tcx
()),
ty_param_count
,
ty_substs_len
);
...
...
src/librustc/middle/typeck/collect.rs
浏览文件 @
23bfa600
...
...
@@ -346,9 +346,10 @@ fn make_static_method_ty(ccx: &CrateCtxt,
let
substd_type_param_defs
=
m
.generics.type_param_defs
.subst
(
tcx
,
&
substs
);
new_type_param_defs
.push_all
(
*
substd_type_param_defs
);
debug!
(
"static method %s type_param_defs=%s substs=%s"
,
debug!
(
"static method %s type_param_defs=%s
ty=%s,
substs=%s"
,
m
.def_id
.repr
(
tcx
),
new_type_param_defs
.repr
(
tcx
),
ty
.repr
(
tcx
),
substs
.repr
(
tcx
));
tcx
.tcache
.insert
(
m
.def_id
,
...
...
@@ -893,8 +894,8 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
}
ast
::
item_trait
(
ref
generics
,
_
,
ref
trait_methods
)
=>
{
let
_
trait_def
=
trait_def_of_item
(
ccx
,
it
);
ensure_trait_methods
(
ccx
,
it
.id
);
// Run convert_methods on the provided methods.
let
(
_
,
provided_methods
)
=
split_trait_methods
(
*
trait_methods
);
let
untransformed_rcvr_ty
=
ty
::
mk_self
(
tcx
,
local_def
(
it
.id
));
...
...
@@ -904,6 +905,11 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
untransformed_rcvr_ty
,
&
ty_generics
,
generics
,
it
.vis
);
// We need to do this *after* converting methods, since
// convert_methods produces a tcache entry that is wrong for
// static trait methods. This is somewhat unfortunate.
ensure_trait_methods
(
ccx
,
it
.id
);
}
ast
::
item_struct
(
struct_def
,
ref
generics
)
=>
{
ensure_no_ty_param_bounds
(
ccx
,
it
.span
,
generics
,
"structure"
);
...
...
src/librustpkg/tests.rs
浏览文件 @
23bfa600
...
...
@@ -678,6 +678,7 @@ fn rustpkg_local_pkg() {
}
#[test]
#[ignore
(reason
=
"test makes bogus assumptions about build directory layout: issue #8690"
)]
fn
package_script_with_default_build
()
{
let
dir
=
create_local_package
(
&
PkgId
::
new
(
"fancy-lib"
));
debug!
(
"dir = %s"
,
dir
.to_str
());
...
...
src/libsyntax/ast_map.rs
浏览文件 @
23bfa600
...
...
@@ -238,12 +238,18 @@ fn visit_item(&mut self, i: @item, _: ()) {
self
.map
.insert
(
p
.ref_id
,
node_item
(
i
,
item_path
));
}
for
tm
in
methods
.iter
()
{
let
id
=
ast_util
::
trait_method_to_ty_method
(
tm
)
.id
;
let
ext
=
{
self
.extend
(
i
.ident
)
}
;
let
d_id
=
ast_util
::
local_def
(
i
.id
);
self
.map
.insert
(
id
,
node_trait_method
(
@
(
*
tm
)
.clone
(),
d_id
,
item_path
));
match
*
tm
{
required
(
ref
m
)
=>
{
let
entry
=
node_trait_method
(
@
(
*
tm
)
.clone
(),
d_id
,
ext
);
self
.map
.insert
(
m
.id
,
entry
);
}
provided
(
m
)
=>
{
self
.map_method
(
d_id
,
ext
,
m
,
true
);
}
}
}
}
_
=>
{}
...
...
src/test/run-pass/trait-object-generics.rs
0 → 100644
浏览文件 @
23bfa600
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// test for #8664
pub
trait
Trait2
<
A
>
{
fn
doit
(
&
self
);
}
pub
struct
Impl
<
A1
,
A2
,
A3
>
{
/*
* With A2 we get the ICE:
* task <unnamed> failed at 'index out of bounds: the len is 1 but the index is 1', /home/tortue/rust_compiler_newest/src/librustc/middle/subst.rs:58
*/
t
:
~
Trait2
<
A2
>
}
impl
<
A1
,
A2
,
A3
>
Impl
<
A1
,
A2
,
A3
>
{
pub
fn
step
(
&
self
)
{
self
.t
.doit
()
}
}
// test for #8601
enum
Type
<
T
>
{
Constant
}
trait
Trait
<
K
,
V
>
{
fn
method
(
&
self
,
Type
<
(
K
,
V
)
>
)
->
int
;
}
impl
<
V
>
Trait
<
u8
,
V
>
for
()
{
fn
method
(
&
self
,
_
x
:
Type
<
(
u8
,
V
)
>
)
->
int
{
0
}
}
fn
main
()
{
let
a
=
@
()
as
@
Trait
<
u8
,
u8
>
;
assert_eq!
(
a
.method
(
Constant
),
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录