Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
563f6d82
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,发现更多精彩内容 >>
提交
563f6d82
编写于
1月 05, 2015
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
差异文件
rollup merge of #20608: nikomatsakis/assoc-types-method-dispatch
上级
384e2187
e58f1bdc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
153 addition
and
13 deletion
+153
-13
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/method/probe.rs
+46
-13
src/test/run-pass/method-normalize-bounds-issue-20604.rs
src/test/run-pass/method-normalize-bounds-issue-20604.rs
+65
-0
src/test/run-pass/method-where-clause.rs
src/test/run-pass/method-where-clause.rs
+42
-0
未找到文件。
src/librustc_typeck/check/method/probe.rs
浏览文件 @
563f6d82
...
...
@@ -442,7 +442,7 @@ fn assemble_extension_candidates_for_traits_in_scope(&mut self,
fn
assemble_extension_candidates_for_trait
(
&
mut
self
,
trait_def_id
:
ast
::
DefId
)
{
debug!
(
"assemble_extension_candidates_for_trait
: trait_def_id={}
"
,
debug!
(
"assemble_extension_candidates_for_trait
(trait_def_id={})
"
,
trait_def_id
.repr
(
self
.tcx
()));
// Check whether `trait_def_id` defines a method with suitable name:
...
...
@@ -471,8 +471,12 @@ fn assemble_extension_candidates_for_trait(&mut self,
matching_index
);
self
.assemble_unboxed_closure_candidates
(
trait_def_id
,
method
,
method
.clone
()
,
matching_index
);
self
.assemble_where_clause_candidates
(
trait_def_id
,
method
,
matching_index
);
}
fn
assemble_extension_candidates_for_trait_impls
(
&
mut
self
,
...
...
@@ -599,6 +603,35 @@ fn assemble_unboxed_closure_candidates(&mut self,
}
}
fn
assemble_where_clause_candidates
(
&
mut
self
,
trait_def_id
:
ast
::
DefId
,
method_ty
:
Rc
<
ty
::
Method
<
'tcx
>>
,
method_index
:
uint
)
{
debug!
(
"assemble_where_clause_candidates(trait_def_id={})"
,
trait_def_id
.repr
(
self
.tcx
()));
// Check whether there are any where-clauses pertaining to this trait.
let
caller_predicates
=
self
.fcx.inh.param_env.caller_bounds.predicates
.as_slice
()
.to_vec
();
for
bound
in
traits
::
elaborate_predicates
(
self
.tcx
(),
caller_predicates
)
.filter_map
(|
p
|
p
.to_opt_poly_trait_ref
())
.filter
(|
b
|
b
.def_id
()
==
trait_def_id
)
{
let
xform_self_ty
=
self
.xform_self_ty
(
&
method_ty
,
bound
.substs
());
debug!
(
"assemble_where_clause_candidates: bound={} xform_self_ty={}"
,
bound
.repr
(
self
.tcx
()),
xform_self_ty
.repr
(
self
.tcx
()));
self
.extension_candidates
.push
(
Candidate
{
xform_self_ty
:
xform_self_ty
,
method_ty
:
method_ty
.clone
(),
kind
:
WhereClauseCandidate
(
bound
,
method_index
)
});
}
}
///////////////////////////////////////////////////////////////////////////
// THE ACTUAL SEARCH
...
...
@@ -774,26 +807,26 @@ fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>) -> bool {
match
probe
.kind
{
InherentImplCandidate
(
impl_def_id
,
ref
substs
)
|
ExtensionImplCandidate
(
impl_def_id
,
_
,
ref
substs
,
_
)
=>
{
let
selcx
=
&
mut
traits
::
SelectionContext
::
new
(
self
.infcx
(),
self
.fcx
);
let
cause
=
traits
::
ObligationCause
::
misc
(
self
.span
,
self
.fcx.body_id
);
// Check whether the impl imposes obligations we have to worry about.
let
impl_generics
=
ty
::
lookup_item_type
(
self
.tcx
(),
impl_def_id
)
.generics
;
let
impl_bounds
=
impl_generics
.to_bounds
(
self
.tcx
(),
substs
);
// FIXME(#20378) assoc type normalization here?
// Erase any late-bound regions bound in the impl
// which appear in the bounds.
let
impl_bounds
=
self
.erase_late_bound_regions
(
&
ty
::
Binder
(
impl_bounds
));
let
traits
::
Normalized
{
value
:
impl_bounds
,
obligations
:
norm_obligations
}
=
traits
::
normalize
(
selcx
,
cause
.clone
(),
&
impl_bounds
);
// Convert the bounds into obligations.
let
obligations
=
traits
::
predicates_for_generics
(
self
.tcx
(),
traits
::
ObligationCause
::
misc
(
self
.span
,
self
.fcx.body_id
),
&
impl_bounds
);
traits
::
predicates_for_generics
(
self
.tcx
(),
cause
.clone
(),
&
impl_bounds
);
debug!
(
"impl_obligations={}"
,
obligations
.repr
(
self
.tcx
()));
// Evaluate those obligations to see if they might possibly hold.
let
mut
selcx
=
traits
::
SelectionContext
::
new
(
self
.infcx
(),
self
.fcx
);
obligations
.all
(|
o
|
selcx
.evaluate_obligation
(
o
))
obligations
.all
(|
o
|
selcx
.evaluate_obligation
(
o
))
&&
norm_obligations
.iter
()
.all
(|
o
|
selcx
.evaluate_obligation
(
o
))
}
ObjectCandidate
(
..
)
|
...
...
src/test/run-pass/method-normalize-bounds-issue-20604.rs
0 → 100644
浏览文件 @
563f6d82
// Copyright 2015 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 that we handle projection types which wind up important for
// resolving methods. This test was reduced from a larger example; the
// call to `foo()` at the end was failing to resolve because the
// winnowing stage of method resolution failed to handle an associated
// type projection.
#![feature(associated_types)]
trait
Hasher
{
type
Output
;
fn
finish
(
&
self
)
->
Self
::
Output
;
}
trait
Hash
<
H
:
Hasher
>
{
fn
hash
(
&
self
,
h
:
&
mut
H
);
}
trait
HashState
{
type
Wut
:
Hasher
;
fn
hasher
(
&
self
)
->
Self
::
Wut
;
}
struct
SipHasher
;
impl
Hasher
for
SipHasher
{
type
Output
=
u64
;
fn
finish
(
&
self
)
->
u64
{
4
}
}
impl
Hash
<
SipHasher
>
for
int
{
fn
hash
(
&
self
,
h
:
&
mut
SipHasher
)
{}
}
struct
SipState
;
impl
HashState
for
SipState
{
type
Wut
=
SipHasher
;
fn
hasher
(
&
self
)
->
SipHasher
{
SipHasher
}
}
struct
Map
<
S
>
{
s
:
S
,
}
impl
<
S
>
Map
<
S
>
where
S
:
HashState
,
<
S
as
HashState
>
::
Wut
:
Hasher
<
Output
=
u64
>
,
{
fn
foo
<
K
>
(
&
self
,
k
:
K
)
where
K
:
Hash
<
<
S
as
HashState
>
::
Wut
>
{}
}
fn
foo
<
K
:
Hash
<
SipHasher
>>
(
map
:
&
Map
<
SipState
>
)
{
map
.foo
(
22
);
}
fn
main
()
{}
src/test/run-pass/method-where-clause.rs
0 → 100644
浏览文件 @
563f6d82
// Copyright 2014 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 that we can use method notation to call methods based on a
// where clause type, and not only type parameters.
trait
Foo
{
fn
foo
(
&
self
)
->
int
;
}
impl
Foo
for
Option
<
int
>
{
fn
foo
(
&
self
)
->
int
{
self
.unwrap_or
(
22
)
}
}
impl
Foo
for
Option
<
uint
>
{
fn
foo
(
&
self
)
->
int
{
self
.unwrap_or
(
22
)
as
int
}
}
fn
check
<
T
>
(
x
:
Option
<
T
>
)
->
(
int
,
int
)
where
Option
<
T
>
:
Foo
{
let
y
:
Option
<
T
>
=
None
;
(
x
.foo
(),
y
.foo
())
}
fn
main
()
{
assert_eq!
(
check
(
Some
(
23u
)),
(
23
i
,
22
i
));
assert_eq!
(
check
(
Some
(
23
i
)),
(
23
i
,
22
i
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录