Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7a3054f5
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,发现更多精彩内容 >>
提交
7a3054f5
编写于
2月 11, 2015
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_resolve: remove the distinction between DefStaticMethod and DefMethod.
上级
0f49254b
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
89 addition
and
159 deletion
+89
-159
src/librustc/metadata/csearch.rs
src/librustc/metadata/csearch.rs
+2
-5
src/librustc/metadata/decoder.rs
src/librustc/metadata/decoder.rs
+4
-18
src/librustc/middle/astencode.rs
src/librustc/middle/astencode.rs
+2
-7
src/librustc/middle/check_const.rs
src/librustc/middle/check_const.rs
+1
-2
src/librustc/middle/def.rs
src/librustc/middle/def.rs
+3
-26
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+1
-1
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+1
-1
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+0
-2
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+17
-48
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+39
-30
src/librustc_trans/save/mod.rs
src/librustc_trans/save/mod.rs
+9
-4
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/callee.rs
+2
-4
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+1
-1
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/expr.rs
+3
-5
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+2
-3
src/test/compile-fail/issue-13641.rs
src/test/compile-fail/issue-13641.rs
+2
-2
未找到文件。
src/librustc/metadata/csearch.rs
浏览文件 @
7a3054f5
...
...
@@ -150,12 +150,9 @@ pub fn get_trait_name(cstore: &cstore::CStore, def: ast::DefId) -> ast::Name {
def
.node
)
}
pub
fn
get_trait_item_name_and_kind
(
cstore
:
&
cstore
::
CStore
,
def
:
ast
::
DefId
)
->
(
ast
::
Name
,
def
::
TraitItemKind
)
{
pub
fn
is_static_method
(
cstore
:
&
cstore
::
CStore
,
def
:
ast
::
DefId
)
->
bool
{
let
cdata
=
cstore
.get_crate_data
(
def
.krate
);
decoder
::
get_trait_item_name_and_kind
(
cstore
.intr
.clone
(),
&*
cdata
,
def
.node
)
decoder
::
is_static_method
(
&*
cdata
,
def
.node
)
}
pub
fn
get_trait_item_def_ids
(
cstore
:
&
cstore
::
CStore
,
def
:
ast
::
DefId
)
...
...
src/librustc/metadata/decoder.rs
浏览文件 @
7a3054f5
...
...
@@ -334,12 +334,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
def
::
FromImpl
(
item_reqd_and_translated_parent_item
(
cnum
,
item
))
};
match
fam
{
// We don't bother to get encode/decode the trait id, we don't need it.
Method
=>
DlDef
(
def
::
DefMethod
(
did
,
None
,
provenance
)),
StaticMethod
=>
DlDef
(
def
::
DefStaticMethod
(
did
,
provenance
)),
_
=>
panic!
()
}
DlDef
(
def
::
DefMethod
(
did
,
provenance
))
}
Type
=>
{
if
item_sort
(
item
)
==
Some
(
't'
)
{
...
...
@@ -853,22 +848,13 @@ pub fn get_trait_name(intr: Rc<IdentInterner>,
item_name
(
&*
intr
,
doc
)
}
pub
fn
get_trait_item_name_and_kind
(
intr
:
Rc
<
IdentInterner
>
,
cdata
:
Cmd
,
id
:
ast
::
NodeId
)
->
(
ast
::
Name
,
def
::
TraitItemKind
)
{
pub
fn
is_static_method
(
cdata
:
Cmd
,
id
:
ast
::
NodeId
)
->
bool
{
let
doc
=
lookup_item
(
id
,
cdata
.data
());
let
name
=
item_name
(
&*
intr
,
doc
);
match
item_sort
(
doc
)
{
Some
(
'r'
)
|
Some
(
'p'
)
=>
{
let
explicit_self
=
get_explicit_self
(
doc
);
(
name
,
def
::
TraitItemKind
::
from_explicit_self_category
(
explicit_self
))
}
Some
(
't'
)
=>
(
name
,
def
::
TypeTraitItemKind
),
c
=>
{
panic!
(
"get_trait_item_name_and_kind(): unknown trait item kind
\
in metadata: `{:?}`"
,
c
)
get_explicit_self
(
doc
)
==
ty
::
StaticExplicitSelfCategory
}
_
=>
false
}
}
...
...
src/librustc/middle/astencode.rs
浏览文件 @
7a3054f5
...
...
@@ -423,13 +423,8 @@ impl tr for def::Def {
fn
tr
(
&
self
,
dcx
:
&
DecodeContext
)
->
def
::
Def
{
match
*
self
{
def
::
DefFn
(
did
,
is_ctor
)
=>
def
::
DefFn
(
did
.tr
(
dcx
),
is_ctor
),
def
::
DefStaticMethod
(
did
,
p
)
=>
{
def
::
DefStaticMethod
(
did
.tr
(
dcx
),
p
.map
(|
did2
|
did2
.tr
(
dcx
)))
}
def
::
DefMethod
(
did0
,
did1
,
p
)
=>
{
def
::
DefMethod
(
did0
.tr
(
dcx
),
did1
.map
(|
did1
|
did1
.tr
(
dcx
)),
p
.map
(|
did2
|
did2
.tr
(
dcx
)))
def
::
DefMethod
(
did
,
p
)
=>
{
def
::
DefMethod
(
did
.tr
(
dcx
),
p
.map
(|
did2
|
did2
.tr
(
dcx
)))
}
def
::
DefSelfTy
(
nid
)
=>
{
def
::
DefSelfTy
(
dcx
.tr_id
(
nid
))
}
def
::
DefMod
(
did
)
=>
{
def
::
DefMod
(
did
.tr
(
dcx
))
}
...
...
src/librustc/middle/check_const.rs
浏览文件 @
7a3054f5
...
...
@@ -452,8 +452,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
v
.add_qualif
(
NON_ZERO_SIZED
);
}
}
Some
(
def
::
DefFn
(
..
))
|
Some
(
def
::
DefStaticMethod
(
..
))
|
Some
(
def
::
DefMethod
(
..
))
=>
{
Some
(
def
::
DefFn
(
..
))
|
Some
(
def
::
DefMethod
(
..
))
=>
{
// Count the function pointer.
v
.add_qualif
(
NON_ZERO_SIZED
);
}
...
...
src/librustc/middle/def.rs
浏览文件 @
7a3054f5
...
...
@@ -10,10 +10,8 @@
pub
use
self
::
Def
::
*
;
pub
use
self
::
MethodProvenance
::
*
;
pub
use
self
::
TraitItemKind
::
*
;
use
middle
::
subst
::
ParamSpace
;
use
middle
::
ty
::{
ExplicitSelfCategory
,
StaticExplicitSelfCategory
};
use
util
::
nodemap
::
NodeMap
;
use
syntax
::
ast
;
use
syntax
::
ast_util
::
local_def
;
...
...
@@ -23,7 +21,6 @@
#[derive(Clone,
Copy,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
pub
enum
Def
{
DefFn
(
ast
::
DefId
,
bool
/* is_ctor */
),
DefStaticMethod
(
/* method */
ast
::
DefId
,
MethodProvenance
),
DefSelfTy
(
/* trait id */
ast
::
NodeId
),
DefMod
(
ast
::
DefId
),
DefForeignMod
(
ast
::
DefId
),
...
...
@@ -51,7 +48,7 @@ pub enum Def {
DefStruct
(
ast
::
DefId
),
DefRegion
(
ast
::
NodeId
),
DefLabel
(
ast
::
NodeId
),
DefMethod
(
ast
::
DefId
/* method */
,
Option
<
ast
::
DefId
>
/* trait */
,
MethodProvenance
),
DefMethod
(
ast
::
DefId
/* method */
,
MethodProvenance
),
}
/// The result of resolving the prefix of a path to a type:
...
...
@@ -99,25 +96,6 @@ pub fn map<F>(self, f: F) -> MethodProvenance where
}
}
#[derive(Clone,
Copy,
Eq,
PartialEq)]
pub
enum
TraitItemKind
{
NonstaticMethodTraitItemKind
,
StaticMethodTraitItemKind
,
TypeTraitItemKind
,
}
impl
TraitItemKind
{
pub
fn
from_explicit_self_category
(
explicit_self_category
:
ExplicitSelfCategory
)
->
TraitItemKind
{
if
explicit_self_category
==
StaticExplicitSelfCategory
{
StaticMethodTraitItemKind
}
else
{
NonstaticMethodTraitItemKind
}
}
}
impl
Def
{
pub
fn
local_node_id
(
&
self
)
->
ast
::
NodeId
{
let
def_id
=
self
.def_id
();
...
...
@@ -127,11 +105,10 @@ pub fn local_node_id(&self) -> ast::NodeId {
pub
fn
def_id
(
&
self
)
->
ast
::
DefId
{
match
*
self
{
DefFn
(
id
,
_
)
|
DefStaticMethod
(
id
,
_
)
|
DefMod
(
id
)
|
DefForeignMod
(
id
)
|
DefStatic
(
id
,
_
)
|
DefFn
(
id
,
_
)
|
DefMod
(
id
)
|
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/mem_categorization.rs
浏览文件 @
7a3054f5
...
...
@@ -575,7 +575,7 @@ pub fn cat_def(&self,
match
def
{
def
::
DefStruct
(
..
)
|
def
::
DefVariant
(
..
)
|
def
::
DefConst
(
..
)
|
def
::
DefFn
(
..
)
|
def
::
Def
StaticMethod
(
..
)
|
def
::
Def
Method
(
..
)
=>
{
def
::
DefFn
(
..
)
|
def
::
DefMethod
(
..
)
=>
{
Ok
(
self
.cat_rvalue_node
(
id
,
span
,
expr_ty
))
}
def
::
DefMod
(
_
)
|
def
::
DefForeignMod
(
_
)
|
def
::
DefUse
(
_
)
|
...
...
src/librustc/middle/ty.rs
浏览文件 @
7a3054f5
...
...
@@ -4584,7 +4584,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
def
::
DefFn
(
_
,
true
)
=>
RvalueDpsExpr
,
// Fn pointers are just scalar values.
def
::
DefFn
(
..
)
|
def
::
Def
StaticMethod
(
..
)
|
def
::
Def
Method
(
..
)
=>
RvalueDatumExpr
,
def
::
DefFn
(
..
)
|
def
::
DefMethod
(
..
)
=>
RvalueDatumExpr
,
// Note: there is actually a good case to be made that
// DefArg's, particularly those of immediate type, ought to
...
...
src/librustc_privacy/lib.rs
浏览文件 @
7a3054f5
...
...
@@ -795,7 +795,6 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
// be accurate and we can get slightly wonky error messages (but type
// checking is always correct).
match
self
.tcx.def_map
.borrow
()[
path_id
]
.clone
()
{
def
::
DefStaticMethod
(
..
)
=>
ck
(
"static method"
),
def
::
DefFn
(
..
)
=>
ck
(
"function"
),
def
::
DefStatic
(
..
)
=>
ck
(
"static"
),
def
::
DefConst
(
..
)
=>
ck
(
"const"
),
...
...
@@ -804,7 +803,6 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
def
::
DefTy
(
_
,
true
)
=>
ck
(
"enum"
),
def
::
DefTrait
(
..
)
=>
ck
(
"trait"
),
def
::
DefStruct
(
..
)
=>
ck
(
"struct"
),
def
::
DefMethod
(
_
,
Some
(
..
),
_
)
=>
ck
(
"trait method"
),
def
::
DefMethod
(
..
)
=>
ck
(
"method"
),
def
::
DefMod
(
..
)
=>
ck
(
"module"
),
_
=>
{}
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
7a3054f5
...
...
@@ -40,8 +40,7 @@
use
syntax
::
ast
::{
ItemForeignMod
,
ItemImpl
,
ItemMac
,
ItemMod
,
ItemStatic
,
ItemDefaultImpl
};
use
syntax
::
ast
::{
ItemStruct
,
ItemTrait
,
ItemTy
,
ItemUse
};
use
syntax
::
ast
::{
MethodImplItem
,
Name
,
NamedField
,
NodeId
};
use
syntax
::
ast
::{
PathListIdent
,
PathListMod
};
use
syntax
::
ast
::{
Public
,
SelfStatic
};
use
syntax
::
ast
::{
PathListIdent
,
PathListMod
,
Public
};
use
syntax
::
ast
::
StmtDecl
;
use
syntax
::
ast
::
StructVariantKind
;
use
syntax
::
ast
::
TupleVariantKind
;
...
...
@@ -598,22 +597,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
&
new_parent
,
ForbidDuplicateValues
,
method
.span
);
let
def
=
match
method
.pe_explicit_self
()
.node
{
SelfStatic
=>
{
// Static methods become
// `DefStaticMethod`s.
DefStaticMethod
(
local_def
(
method
.id
),
FromImpl
(
local_def
(
item
.id
)))
}
_
=>
{
// Non-static methods become
// `DefMethod`s.
DefMethod
(
local_def
(
method
.id
),
None
,
FromImpl
(
local_def
(
item
.id
)))
}
};
let
def
=
DefMethod
(
local_def
(
method
.id
),
FromImpl
(
local_def
(
item
.id
)));
// NB: not IMPORTABLE
let
modifiers
=
if
method
.pe_vis
()
==
ast
::
Public
{
...
...
@@ -674,7 +659,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
// Add the names of all the items to the trait info.
for
trait_item
in
items
{
let
(
name
,
kin
d
)
=
match
*
trait_item
{
let
(
name
,
trait_item_i
d
)
=
match
*
trait_item
{
ast
::
RequiredMethod
(
_
)
|
ast
::
ProvidedMethod
(
_
)
=>
{
let
ty_m
=
ast_util
::
trait_item_to_ty_method
(
trait_item
);
...
...
@@ -682,23 +667,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
let
name
=
ty_m
.ident.name
;
// Add it as a name in the trait module.
let
(
def
,
static_flag
)
=
match
ty_m
.explicit_self
.node
{
SelfStatic
=>
{
// Static methods become `DefStaticMethod`s.
(
DefStaticMethod
(
local_def
(
ty_m
.id
),
FromTrait
(
local_def
(
item
.id
))),
StaticMethodTraitItemKind
)
}
_
=>
{
// Non-static methods become `DefMethod`s.
(
DefMethod
(
local_def
(
ty_m
.id
),
Some
(
local_def
(
item
.id
)),
FromTrait
(
local_def
(
item
.id
))),
NonstaticMethodTraitItemKind
)
}
};
let
def
=
DefMethod
(
local_def
(
ty_m
.id
),
FromTrait
(
local_def
(
item
.id
)));
let
method_name_bindings
=
self
.add_child
(
name
,
...
...
@@ -710,7 +680,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
ty_m
.span
,
PUBLIC
);
(
name
,
static_flag
)
(
name
,
local_def
(
ty_m
.id
)
)
}
ast
::
TypeTraitItem
(
ref
associated_type
)
=>
{
let
def
=
DefAssociatedTy
(
local_def
(
item
.id
),
...
...
@@ -726,11 +696,12 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
associated_type
.ty_param.span
,
PUBLIC
);
(
associated_type
.ty_param.ident.name
,
TypeTraitItemKind
)
(
associated_type
.ty_param.ident.name
,
local_def
(
associated_type
.ty_param.id
))
}
};
self
.trait_item_map
.insert
((
name
,
def_id
),
kin
d
);
self
.trait_item_map
.insert
((
name
,
def_id
),
trait_item_i
d
);
}
name_bindings
.define_type
(
DefTrait
(
def_id
),
sp
,
modifiers
);
...
...
@@ -889,7 +860,7 @@ fn handle_external_def(&mut self,
csearch
::
get_tuple_struct_definition_if_ctor
(
&
self
.session.cstore
,
ctor_id
)
.map_or
(
def
,
|
_
|
DefStruct
(
ctor_id
)),
DUMMY_SP
,
modifiers
);
}
DefFn
(
..
)
|
DefStatic
Method
(
..
)
|
DefStatic
(
..
)
|
DefConst
(
..
)
|
DefMethod
(
..
)
=>
{
DefFn
(
..
)
|
DefStatic
(
..
)
|
DefConst
(
..
)
|
DefMethod
(
..
)
=>
{
debug!
(
"(building reduced graph for external
\
crate) building value (fn/static) {}"
,
final_ident
);
// impl methods have already been defined with the correct importability modifier
...
...
@@ -911,21 +882,19 @@ fn handle_external_def(&mut self,
let
trait_item_def_ids
=
csearch
::
get_trait_item_def_ids
(
&
self
.session.cstore
,
def_id
);
for
trait_item_def_id
in
&
trait_item_def_ids
{
let
(
trait_item_name
,
trait_item_kind
)
=
csearch
::
get_trait_item_name_and_kind
(
&
self
.session.cstore
,
trait_item_def_id
.def_id
());
for
trait_item_def
in
&
trait_item_def_ids
{
let
trait_item_name
=
csearch
::
get_trait_name
(
&
self
.session.cstore
,
trait_item_def
.def_id
());
debug!
(
"(building reduced graph for external crate) ...
\
adding trait item '{}'"
,
token
::
get_name
(
trait_item_name
));
self
.trait_item_map
.insert
((
trait_item_name
,
def_id
),
trait_item_kind
);
self
.trait_item_map
.insert
((
trait_item_name
,
def_id
),
trait_item_def
.def_id
());
if
is_exported
{
self
.external_exports
.insert
(
trait_item_def_id
.def_id
());
self
.external_exports
.insert
(
trait_item_def
.def_id
());
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
7a3054f5
...
...
@@ -900,7 +900,7 @@ struct Resolver<'a, 'tcx:'a> {
graph_root
:
NameBindings
,
trait_item_map
:
FnvHashMap
<
(
Name
,
DefId
),
TraitItemKin
d
>
,
trait_item_map
:
FnvHashMap
<
(
Name
,
DefId
),
DefI
d
>
,
structs
:
FnvHashMap
<
DefId
,
Vec
<
Name
>>
,
...
...
@@ -3128,7 +3128,7 @@ fn resolve_implementation(&mut self,
fn
check_trait_item
(
&
self
,
name
:
Name
,
span
:
Span
)
{
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
if
let
Some
((
did
,
ref
trait_ref
))
=
self
.current_trait_ref
{
if
self
.trait_item_map
.get
(
&
(
name
,
did
))
.is_none
(
)
{
if
!
self
.trait_item_map
.contains_key
(
&
(
name
,
did
)
)
{
let
path_str
=
self
.path_names_to_string
(
&
trait_ref
.path
,
0
);
self
.resolve_error
(
span
,
&
format!
(
"method `{}` is not a member of trait `{}`"
,
...
...
@@ -3958,6 +3958,26 @@ fn get_module(this: &mut Resolver, span: Span, name_path: &[ast::Name])
}
}
fn
is_static_method
(
this
:
&
Resolver
,
did
:
DefId
)
->
bool
{
if
did
.krate
==
ast
::
LOCAL_CRATE
{
let
explicit_self
=
match
this
.ast_map
.get
(
did
.node
)
{
ast_map
::
NodeTraitItem
(
m
)
=>
match
*
m
{
ast
::
RequiredMethod
(
ref
m
)
=>
&
m
.explicit_self
,
ast
::
ProvidedMethod
(
ref
m
)
=>
m
.pe_explicit_self
(),
_
=>
return
false
},
ast_map
::
NodeImplItem
(
m
)
=>
match
*
m
{
ast
::
MethodImplItem
(
ref
m
)
=>
m
.pe_explicit_self
(),
_
=>
return
false
},
_
=>
return
false
};
explicit_self
.node
==
ast
::
SelfStatic
}
else
{
csearch
::
is_static_method
(
&
this
.session.cstore
,
did
)
}
}
let
(
path
,
node_id
,
allowed
)
=
match
self
.current_self_type
{
Some
(
ref
ty
)
=>
match
extract_path_and_node_id
(
ty
,
Everything
)
{
Some
(
x
)
=>
x
,
...
...
@@ -3986,41 +4006,30 @@ fn get_module(this: &mut Resolver, span: Span, name_path: &[ast::Name])
let
name_path
=
path
.segments
.iter
()
.map
(|
seg
|
seg
.identifier.name
)
.collect
::
<
Vec
<
_
>>
();
// Look for a method in the current self type's impl module.
match
get_module
(
self
,
path
.span
,
&
name_path
[
..
])
{
Some
(
module
)
=>
match
module
.children
.borrow
()
.get
(
&
name
)
{
Some
(
binding
)
=>
{
let
p_str
=
self
.path_names_to_string
(
&
path
,
0
);
match
binding
.def_for_namespace
(
ValueNS
)
{
Some
(
DefStaticMethod
(
_
,
provenance
))
=>
{
match
provenance
{
FromImpl
(
_
)
=>
return
StaticMethod
(
p_str
),
FromTrait
(
_
)
=>
unreachable!
()
}
}
Some
(
DefMethod
(
_
,
None
,
_
))
if
allowed
==
Everything
=>
return
Method
,
Some
(
DefMethod
(
_
,
Some
(
_
),
_
))
=>
return
TraitItem
,
_
=>
()
if
let
Some
(
module
)
=
get_module
(
self
,
path
.span
,
&
name_path
)
{
if
let
Some
(
binding
)
=
module
.children
.borrow
()
.get
(
&
name
)
{
if
let
Some
(
DefMethod
(
did
,
_
))
=
binding
.def_for_namespace
(
ValueNS
)
{
if
is_static_method
(
self
,
did
)
{
return
StaticMethod
(
self
.path_names_to_string
(
&
path
,
0
))
}
if
self
.current_trait_ref
.is_some
()
{
return
TraitItem
;
}
else
if
allowed
==
Everything
{
return
Method
;
}
}
None
=>
{}
},
None
=>
{}
}
}
// Look for a method in the current trait.
match
self
.current_trait_ref
{
Some
((
did
,
ref
trait_ref
))
=>
{
let
path_str
=
self
.path_names_to_string
(
&
trait_ref
.path
,
0
);
match
self
.trait_item_map
.get
(
&
(
name
,
did
))
{
Some
(
&
StaticMethodTraitItemKind
)
=>
{
return
TraitMethod
(
path_str
)
}
Some
(
_
)
=>
return
TraitItem
,
None
=>
{}
if
let
Some
((
trait_did
,
ref
trait_ref
))
=
self
.current_trait_ref
{
if
let
Some
(
&
did
)
=
self
.trait_item_map
.get
(
&
(
name
,
trait_did
))
{
if
is_static_method
(
self
,
did
)
{
return
TraitMethod
(
self
.path_names_to_string
(
&
trait_ref
.path
,
0
));
}
else
{
return
TraitItem
;
}
}
None
=>
{}
}
NoSuggestion
...
...
src/librustc_trans/save/mod.rs
浏览文件 @
7a3054f5
...
...
@@ -250,7 +250,6 @@ fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
def
::
DefSelfTy
(
_
)
|
def
::
DefRegion
(
_
)
|
def
::
DefLabel
(
_
)
|
def
::
DefStaticMethod
(
..
)
|
def
::
DefTyParam
(
..
)
|
def
::
DefUse
(
_
)
|
def
::
DefMethod
(
..
)
|
...
...
@@ -815,8 +814,7 @@ fn process_path(&mut self,
sub_span
,
def_id
,
self
.cur_scope
),
def
::
DefStaticMethod
(
declid
,
provenence
)
|
def
::
DefMethod
(
declid
,
_
,
provenence
)
=>
{
def
::
DefMethod
(
declid
,
provenence
)
=>
{
let
sub_span
=
self
.span
.sub_span_for_meth_name
(
span
);
let
defid
=
if
declid
.krate
==
ast
::
LOCAL_CRATE
{
let
ti
=
ty
::
impl_or_trait_item
(
&
self
.analysis.ty_cx
,
...
...
@@ -872,7 +870,14 @@ fn process_path(&mut self,
}
// modules or types in the path prefix
match
*
def
{
def
::
DefStaticMethod
(
..
)
=>
self
.write_sub_path_trait_truncated
(
path
),
def
::
DefMethod
(
did
,
_
)
=>
{
let
ti
=
ty
::
impl_or_trait_item
(
&
self
.analysis.ty_cx
,
did
);
if
let
ty
::
MethodTraitItem
(
m
)
=
ti
{
if
m
.explicit_self
==
ty
::
StaticExplicitSelfCategory
{
self
.write_sub_path_trait_truncated
(
path
);
}
}
}
def
::
DefLocal
(
_
)
|
def
::
DefStatic
(
_
,
_
)
|
def
::
DefConst
(
..
)
|
...
...
src/librustc_trans/trans/callee.rs
浏览文件 @
7a3054f5
...
...
@@ -165,13 +165,11 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
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
::
FromImpl
(
_
))
|
def
::
DefStaticMethod
(
did
,
def
::
FromImpl
(
_
))
=>
{
def
::
DefFn
(
did
,
_
)
|
def
::
DefMethod
(
did
,
def
::
FromImpl
(
_
))
=>
{
fn_callee
(
bcx
,
trans_fn_ref
(
bcx
.ccx
(),
did
,
ExprId
(
ref_expr
.id
),
bcx
.fcx.param_substs
)
.val
)
}
def
::
DefStaticMethod
(
meth_did
,
def
::
FromTrait
(
trait_did
))
|
def
::
DefMethod
(
meth_did
,
_
,
def
::
FromTrait
(
trait_did
))
=>
{
def
::
DefMethod
(
meth_did
,
def
::
FromTrait
(
trait_did
))
=>
{
fn_callee
(
bcx
,
meth
::
trans_static_method_callee
(
bcx
.ccx
(),
meth_did
,
trait_did
,
...
...
src/librustc_trans/trans/consts.rs
浏览文件 @
7a3054f5
...
...
@@ -666,7 +666,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ast
::
ExprPath
(
_
)
|
ast
::
ExprQPath
(
_
)
=>
{
let
def
=
cx
.tcx
()
.def_map
.borrow
()[
e
.id
];
match
def
{
def
::
DefFn
(
..
)
|
def
::
Def
StaticMethod
(
..
)
|
def
::
Def
Method
(
..
)
=>
{
def
::
DefFn
(
..
)
|
def
::
DefMethod
(
..
)
=>
{
expr
::
trans_def_fn_unadjusted
(
cx
,
e
,
def
,
param_substs
)
.val
}
def
::
DefConst
(
def_id
)
=>
{
...
...
src/librustc_trans/trans/expr.rs
浏览文件 @
7a3054f5
...
...
@@ -875,7 +875,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
_
icx
=
push_ctxt
(
"trans_def_lvalue"
);
match
def
{
def
::
DefFn
(
..
)
|
def
::
Def
StaticMethod
(
..
)
|
def
::
Def
Method
(
..
)
|
def
::
DefFn
(
..
)
|
def
::
DefMethod
(
..
)
|
def
::
DefStruct
(
_
)
|
def
::
DefVariant
(
..
)
=>
{
let
datum
=
trans_def_fn_unadjusted
(
bcx
.ccx
(),
ref_expr
,
def
,
bcx
.fcx.param_substs
);
...
...
@@ -1275,12 +1275,10 @@ pub fn trans_def_fn_unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
match
def
{
def
::
DefFn
(
did
,
_
)
|
def
::
DefStruct
(
did
)
|
def
::
DefVariant
(
_
,
did
,
_
)
|
def
::
DefStaticMethod
(
did
,
def
::
FromImpl
(
_
))
|
def
::
DefMethod
(
did
,
_
,
def
::
FromImpl
(
_
))
=>
{
def
::
DefMethod
(
did
,
def
::
FromImpl
(
_
))
=>
{
callee
::
trans_fn_ref
(
ccx
,
did
,
ExprId
(
ref_expr
.id
),
param_substs
)
}
def
::
DefStaticMethod
(
impl_did
,
def
::
FromTrait
(
trait_did
))
|
def
::
DefMethod
(
impl_did
,
_
,
def
::
FromTrait
(
trait_did
))
=>
{
def
::
DefMethod
(
impl_did
,
def
::
FromTrait
(
trait_did
))
=>
{
meth
::
trans_static_method_callee
(
ccx
,
impl_did
,
trait_did
,
ref_expr
.id
,
param_substs
)
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
7a3054f5
...
...
@@ -4627,7 +4627,7 @@ fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
(
ty
::
TypeScheme
{
generics
:
ty
::
Generics
::
empty
(),
ty
:
typ
},
ty
::
GenericPredicates
::
empty
())
}
def
::
DefFn
(
id
,
_
)
|
def
::
Def
StaticMethod
(
id
,
_
)
|
def
::
DefMethod
(
id
,
_
,
_
)
|
def
::
DefFn
(
id
,
_
)
|
def
::
Def
Method
(
id
,
_
)
|
def
::
DefStatic
(
id
,
_
)
|
def
::
DefVariant
(
_
,
id
,
_
)
|
def
::
DefStruct
(
id
)
|
def
::
DefConst
(
id
)
=>
{
(
ty
::
lookup_item_type
(
fcx
.tcx
(),
id
),
ty
::
lookup_predicates
(
fcx
.tcx
(),
id
))
...
...
@@ -4751,8 +4751,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}
// Case 3. Reference to a method.
def
::
DefStaticMethod
(
_
,
providence
)
|
def
::
DefMethod
(
_
,
_
,
providence
)
=>
{
def
::
DefMethod
(
_
,
providence
)
=>
{
assert
!
(
path
.segments
.len
()
>=
2
);
match
providence
{
...
...
src/test/compile-fail/issue-13641.rs
浏览文件 @
7a3054f5
...
...
@@ -17,9 +17,9 @@ impl Bar { pub fn new() {} }
fn
main
()
{
a
::
Foo
::
new
();
//~^ ERROR:
static
method `new` is inaccessible
//~^ ERROR: method `new` is inaccessible
//~^^ NOTE: struct `Foo` is private
a
::
Bar
::
new
();
//~^ ERROR:
static
method `new` is inaccessible
//~^ ERROR: method `new` is inaccessible
//~^^ NOTE: enum `Bar` is private
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录