Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
eb598e53
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,发现更多精彩内容 >>
提交
eb598e53
编写于
10月 15, 2014
作者:
N
Nick Cameron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow self as an arg in extension methods
上级
db640d53
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
51 addition
and
96 deletion
+51
-96
src/librustc/metadata/encoder.rs
src/librustc/metadata/encoder.rs
+8
-14
src/librustc/middle/astencode.rs
src/librustc/middle/astencode.rs
+2
-2
src/librustc/middle/def.rs
src/librustc/middle/def.rs
+2
-2
src/librustc/middle/privacy.rs
src/librustc/middle/privacy.rs
+1
-1
src/librustc/middle/resolve.rs
src/librustc/middle/resolve.rs
+21
-41
src/librustc/middle/save/mod.rs
src/librustc/middle/save/mod.rs
+1
-1
src/librustc/middle/trans/callee.rs
src/librustc/middle/trans/callee.rs
+7
-6
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/mod.rs
+3
-5
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/collect.rs
+6
-7
src/test/compile-fail/call-extern-trait-as-function.rs
src/test/compile-fail/call-extern-trait-as-function.rs
+0
-17
未找到文件。
src/librustc/metadata/encoder.rs
浏览文件 @
eb598e53
...
...
@@ -407,13 +407,10 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
method_did
.def_id
());
match
impl_item
{
ty
::
MethodTraitItem
(
ref
m
)
=>
{
if
m
.explicit_self
==
ty
::
StaticExplicitSelfCategory
{
encode_reexported_static_method
(
rbml_w
,
exp
,
m
.def_id
,
m
.ident
);
}
encode_reexported_static_method
(
rbml_w
,
exp
,
m
.def_id
,
m
.ident
);
}
ty
::
TypeTraitItem
(
_
)
=>
{}
}
...
...
@@ -434,8 +431,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
Some
(
trait_items
)
=>
{
for
trait_item
in
trait_items
.iter
()
{
match
*
trait_item
{
ty
::
MethodTraitItem
(
ref
m
)
if
m
.explicit_self
==
ty
::
StaticExplicitSelfCategory
=>
{
ty
::
MethodTraitItem
(
ref
m
)
=>
{
encode_reexported_static_method
(
rbml_w
,
exp
,
m
.def_id
,
...
...
@@ -1408,18 +1404,16 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
encode_family
(
rbml_w
,
fn_style_static_method_family
(
method_ty
.fty.fn_style
));
let
pty
=
ty
::
lookup_item_type
(
tcx
,
method_def_id
);
encode_bounds_and_type
(
rbml_w
,
ecx
,
&
pty
);
}
_
=>
{
encode_family
(
rbml_w
,
style_fn_family
(
method_ty
.fty.fn_style
));
}
}
let
pty
=
ty
::
lookup_item_type
(
tcx
,
method_def_id
);
encode_bounds_and_type
(
rbml_w
,
ecx
,
&
pty
);
is_nonstatic_method
=
method_ty
.explicit_self
!=
ty
::
StaticExplicitSelfCategory
;
...
...
src/librustc/middle/astencode.rs
浏览文件 @
eb598e53
...
...
@@ -453,8 +453,8 @@ fn tr(&self, dcx: &DecodeContext) -> def::Def {
},
p
)
}
def
::
DefMethod
(
did0
,
did1
)
=>
{
def
::
DefMethod
(
did0
.tr
(
dcx
),
did1
.map
(|
did1
|
did1
.tr
(
dcx
)))
def
::
DefMethod
(
did0
,
did1
,
p
)
=>
{
def
::
DefMethod
(
did0
.tr
(
dcx
),
did1
.map
(|
did1
|
did1
.tr
(
dcx
))
,
p
)
}
def
::
DefSelfTy
(
nid
)
=>
{
def
::
DefSelfTy
(
dcx
.tr_id
(
nid
))
}
def
::
DefMod
(
did
)
=>
{
def
::
DefMod
(
did
.tr
(
dcx
))
}
...
...
src/librustc/middle/def.rs
浏览文件 @
eb598e53
...
...
@@ -46,7 +46,7 @@ pub enum Def {
DefTyParamBinder
(
ast
::
NodeId
),
/* struct, impl or trait with ty params */
DefRegion
(
ast
::
NodeId
),
DefLabel
(
ast
::
NodeId
),
DefMethod
(
ast
::
DefId
/* method */
,
Option
<
ast
::
DefId
>
/* trait */
),
DefMethod
(
ast
::
DefId
/* method */
,
Option
<
ast
::
DefId
>
/* trait */
,
MethodProvenance
),
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
...
...
@@ -62,7 +62,7 @@ pub fn def_id(&self) -> ast::DefId {
DefForeignMod
(
id
)
|
DefStatic
(
id
,
_
)
|
DefVariant
(
_
,
id
,
_
)
|
DefTy
(
id
,
_
)
|
DefAssociatedTy
(
id
)
|
DefTyParam
(
_
,
id
,
_
)
|
DefUse
(
id
)
|
DefStruct
(
id
)
|
DefTrait
(
id
)
|
DefMethod
(
id
,
_
)
|
DefConst
(
id
)
=>
{
DefMethod
(
id
,
_
,
_
)
|
DefConst
(
id
)
=>
{
id
}
DefLocal
(
id
)
|
...
...
src/librustc/middle/privacy.rs
浏览文件 @
eb598e53
...
...
@@ -811,7 +811,7 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
def
::
DefTy
(
_
,
true
)
=>
ck
(
"enum"
),
def
::
DefTrait
(
..
)
=>
ck
(
"trait"
),
def
::
DefStruct
(
..
)
=>
ck
(
"struct"
),
def
::
DefMethod
(
_
,
Some
(
..
))
=>
ck
(
"trait method"
),
def
::
DefMethod
(
_
,
Some
(
..
)
,
_
)
=>
ck
(
"trait method"
),
def
::
DefMethod
(
..
)
=>
ck
(
"method"
),
def
::
DefMod
(
..
)
=>
ck
(
"module"
),
_
=>
{}
...
...
src/librustc/middle/resolve.rs
浏览文件 @
eb598e53
...
...
@@ -250,7 +250,7 @@ enum FallbackSuggestion {
Method
,
TraitItem
,
StaticMethod
(
String
),
Static
TraitMethod
(
String
),
TraitMethod
(
String
),
}
enum
TypeParameters
<
'a
>
{
...
...
@@ -1386,17 +1386,17 @@ fn build_reduced_graph_for_item(&mut self,
.node
{
SelfStatic
=>
{
// Static methods become
// `def_static_method`s.
DefStaticMethod
(
local_def
(
method
.id
),
FromImpl
(
local_def
(
item
.id
)),
method
.pe_fn_style
())
// `DefStaticMethod`s.
DefStaticMethod
(
local_def
(
method
.id
),
FromImpl
(
local_def
(
item
.id
)),
method
.pe_fn_style
())
}
_
=>
{
// Non-static methods become
// `
def_m
ethod`s.
// `
DefM
ethod`s.
DefMethod
(
local_def
(
method
.id
),
None
)
None
,
FromImpl
(
local_def
(
item
.id
)))
}
};
...
...
@@ -1476,8 +1476,7 @@ fn build_reduced_graph_for_item(&mut self,
let
(
def
,
static_flag
)
=
match
ty_m
.explicit_self
.node
{
SelfStatic
=>
{
// Static methods become
// `def_static_method`s.
// Static methods become `DefStaticMethod`s.
(
DefStaticMethod
(
local_def
(
ty_m
.id
),
FromTrait
(
local_def
(
item
.id
)),
...
...
@@ -1485,10 +1484,10 @@ fn build_reduced_graph_for_item(&mut self,
StaticMethodTraitItemKind
)
}
_
=>
{
// Non-static methods become
// `def_method`s.
// Non-static methods become `DefMethod`s.
(
DefMethod
(
local_def
(
ty_m
.id
),
Some
(
local_def
(
item
.id
))),
Some
(
local_def
(
item
.id
)),
FromTrait
(
local_def
(
item
.id
))),
NonstaticMethodTraitItemKind
)
}
};
...
...
@@ -4607,8 +4606,7 @@ fn resolve_implementation(&mut self,
// We also need a new scope for the method-
// specific type parameters.
this
.resolve_method
(
MethodRibKind
(
id
,
ProvidedMethod
(
method
.id
)),
MethodRibKind
(
id
,
ProvidedMethod
(
method
.id
)),
&**
method
);
}
TypeImplItem
(
ref
typedef
)
=>
{
...
...
@@ -5393,8 +5391,8 @@ fn resolve_module_relative_path(&mut self,
let
ident
=
path
.segments
.last
()
.unwrap
()
.identifier
;
let
def
=
match
self
.resolve_definition_of_name_in_module
(
containing_module
.clone
(),
ident
.name
,
namespace
)
{
ident
.name
,
namespace
)
{
NoNameDefinition
=>
{
// We failed to resolve the name. Report an error.
return
None
;
...
...
@@ -5403,26 +5401,6 @@ fn resolve_module_relative_path(&mut self,
(
def
,
last_private
.or
(
lp
))
}
};
match
containing_module
.kind
.get
()
{
TraitModuleKind
|
ImplModuleKind
=>
{
match
containing_module
.def_id
.get
()
{
Some
(
def_id
)
=>
{
match
self
.trait_item_map
.find
(
&
(
ident
.name
,
def_id
))
{
Some
(
&
StaticMethodTraitItemKind
)
=>
(),
Some
(
&
TypeTraitItemKind
)
=>
(),
None
=>
(),
Some
(
&
NonstaticMethodTraitItemKind
)
=>
{
debug!
(
"containing module was a trait or impl
\
and name was a method -> not resolved"
);
return
None
;
}
}
},
_
=>
(),
}
},
_
=>
(),
}
match
containing_module
.def_id
.get
()
{
Some
(
DefId
{
krate
:
kid
,
..
})
=>
{
self
.used_crates
.insert
(
kid
);
},
_
=>
{}
...
...
@@ -5668,8 +5646,8 @@ fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
FromTrait
(
_
)
=>
unreachable!
()
}
}
Some
(
DefMethod
(
_
,
None
))
if
allowed
==
Everything
=>
return
Method
,
Some
(
DefMethod
(
_
,
Some
(
_
)))
=>
return
TraitItem
,
Some
(
DefMethod
(
_
,
None
,
_
))
if
allowed
==
Everything
=>
return
Method
,
Some
(
DefMethod
(
_
,
Some
(
_
)
,
_
))
=>
return
TraitItem
,
_
=>
()
}
}
...
...
@@ -5684,7 +5662,9 @@ fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
let
path_str
=
self
.path_idents_to_string
(
&
trait_ref
.path
);
match
self
.trait_item_map
.find
(
&
(
name
,
did
))
{
Some
(
&
StaticMethodTraitItemKind
)
=>
return
StaticTraitMethod
(
path_str
),
Some
(
&
StaticMethodTraitItemKind
)
=>
{
return
TraitMethod
(
path_str
)
}
Some
(
_
)
=>
return
TraitItem
,
None
=>
{}
}
...
...
@@ -5810,7 +5790,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
Method
|
TraitItem
=>
format!
(
"to call `self.{}`"
,
wrong_name
),
Static
TraitMethod
(
path_str
)
TraitMethod
(
path_str
)
|
StaticMethod
(
path_str
)
=>
format!
(
"to call `{}::{}`"
,
path_str
,
wrong_name
)
};
...
...
src/librustc/middle/save/mod.rs
浏览文件 @
eb598e53
...
...
@@ -244,7 +244,7 @@ fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
def
::
DefStaticMethod
(
_
,
_
,
_
)
|
def
::
DefTyParam
(
..
)
|
def
::
DefUse
(
_
)
|
def
::
DefMethod
(
_
,
_
)
|
def
::
DefMethod
(
..
)
|
def
::
DefPrimTy
(
_
)
=>
{
self
.sess
.span_bug
(
span
,
format!
(
"lookup_def_kind for unexpected item: {:?}"
,
def
)
.as_slice
());
...
...
src/librustc/middle/trans/callee.rs
浏览文件 @
eb598e53
...
...
@@ -137,7 +137,9 @@ fn fn_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llfn: ValueRef)
};
}
fn
trans_def
<
'blk
,
'tcx
>
(
bcx
:
Block
<
'blk
,
'tcx
>
,
def
:
def
::
Def
,
ref_expr
:
&
ast
::
Expr
)
fn
trans_def
<
'blk
,
'tcx
>
(
bcx
:
Block
<
'blk
,
'tcx
>
,
def
:
def
::
Def
,
ref_expr
:
&
ast
::
Expr
)
->
Callee
<
'blk
,
'tcx
>
{
debug!
(
"trans_def(def={}, ref_expr={})"
,
def
.repr
(
bcx
.tcx
()),
ref_expr
.repr
(
bcx
.tcx
()));
let
expr_ty
=
node_id_type
(
bcx
,
ref_expr
.id
);
...
...
@@ -165,14 +167,13 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, def: def::Def, ref_expr: &ast::
let
def_id
=
inline
::
maybe_instantiate_inline
(
bcx
.ccx
(),
did
);
Callee
{
bcx
:
bcx
,
data
:
Intrinsic
(
def_id
.node
,
substs
)
}
}
def
::
DefFn
(
did
,
_
,
_
)
|
def
::
DefMethod
(
did
,
_
)
|
def
::
DefFn
(
did
,
_
,
_
)
|
def
::
DefMethod
(
did
,
_
,
def
::
FromImpl
(
_
)
)
|
def
::
DefStaticMethod
(
did
,
def
::
FromImpl
(
_
),
_
)
=>
{
fn_callee
(
bcx
,
trans_fn_ref
(
bcx
,
did
,
ExprId
(
ref_expr
.id
)))
}
def
::
DefStaticMethod
(
impl_did
,
def
::
FromTrait
(
trait_did
),
_
)
=>
{
fn_callee
(
bcx
,
meth
::
trans_static_method_callee
(
bcx
,
impl_did
,
def
::
DefStaticMethod
(
meth_did
,
def
::
FromTrait
(
trait_did
),
_
)
|
def
::
DefMethod
(
meth_did
,
_
,
def
::
FromTrait
(
trait_did
))
=>
{
fn_callee
(
bcx
,
meth
::
trans_static_method_callee
(
bcx
,
meth_did
,
trait_did
,
ref_expr
.id
))
}
...
...
src/librustc/middle/typeck/check/mod.rs
浏览文件 @
eb598e53
...
...
@@ -5027,10 +5027,9 @@ pub fn polytype_for_def(fcx: &FnCtxt,
let
typ
=
fcx
.local_ty
(
sp
,
nid
);
return
no_params
(
typ
);
}
def
::
DefFn
(
id
,
_
,
_
)
|
def
::
DefStaticMethod
(
id
,
_
,
_
)
|
def
::
DefFn
(
id
,
_
,
_
)
|
def
::
DefStaticMethod
(
id
,
_
,
_
)
|
def
::
DefMethod
(
id
,
_
,
_
)
|
def
::
DefStatic
(
id
,
_
)
|
def
::
DefVariant
(
_
,
id
,
_
)
|
def
::
DefStruct
(
id
)
|
def
::
DefConst
(
id
)
|
def
::
DefMethod
(
id
,
_
)
=>
{
def
::
DefStruct
(
id
)
|
def
::
DefConst
(
id
)
=>
{
return
ty
::
lookup_item_type
(
fcx
.ccx.tcx
,
id
);
}
def
::
DefTrait
(
_
)
|
...
...
@@ -5229,8 +5228,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
}
fcx
.add_obligations_for_parameters
(
traits
::
ObligationCause
::
new
(
span
,
traits
::
ItemObligation
(
def
.def_id
())),
traits
::
ObligationCause
::
new
(
span
,
traits
::
ItemObligation
(
def
.def_id
())),
&
substs
,
&
polytype
.generics
);
...
...
src/librustc/middle/typeck/collect.rs
浏览文件 @
eb598e53
...
...
@@ -77,10 +77,12 @@ fn collect_intrinsic_type(ccx: &CrateCtxt,
}
match
ccx
.tcx.lang_items
.ty_desc
()
{
Some
(
id
)
=>
{
collect_intrinsic_type
(
ccx
,
id
);
}
None
=>
{}
Some
(
id
)
=>
{
collect_intrinsic_type
(
ccx
,
id
);
}
None
=>
{}
}
match
ccx
.tcx.lang_items
.opaque
()
{
Some
(
id
)
=>
{
collect_intrinsic_type
(
ccx
,
id
);
}
None
=>
{}
Some
(
id
)
=>
{
collect_intrinsic_type
(
ccx
,
id
);
}
None
=>
{}
}
let
mut
visitor
=
CollectTraitDefVisitor
{
ccx
:
ccx
};
...
...
@@ -306,10 +308,7 @@ fn collect_trait_methods(ccx: &CrateCtxt,
}
});
if
ty_method
.explicit_self
==
ty
::
StaticExplicitSelfCategory
{
make_static_method_ty
(
ccx
,
&*
ty_method
);
}
make_method_ty
(
ccx
,
&*
ty_method
);
tcx
.impl_or_trait_items
.borrow_mut
()
...
...
@@ -364,7 +363,7 @@ fn collect_trait_methods(ccx: &CrateCtxt,
_
=>
{
/* Ignore things that aren't traits */
}
}
fn
make_
static_
method_ty
(
ccx
:
&
CrateCtxt
,
m
:
&
ty
::
Method
)
{
fn
make_method_ty
(
ccx
:
&
CrateCtxt
,
m
:
&
ty
::
Method
)
{
ccx
.tcx.tcache
.borrow_mut
()
.insert
(
m
.def_id
,
Polytype
{
...
...
src/test/compile-fail/call-extern-trait-as-function.rs
已删除
100644 → 0
浏览文件 @
db640d53
// 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.
// issue #6698
fn
V
()
->
bool
{
std
::
clone
::
Clone
::
clone
(
true
)
//~ ERROR error: unresolved name `std::clone::Clone::clone`.
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录