Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
02aacaba
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
02aacaba
编写于
1月 13, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix DeBruijn accounting. It used to be that all trait-refs were binders,
but now only poly-trait-refs are binders. Fixes #20831.
上级
e94a9f03
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
119 addition
and
29 deletion
+119
-29
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+45
-29
src/test/compile-fail/issue-20831-debruijn.rs
src/test/compile-fail/issue-20831-debruijn.rs
+49
-0
src/test/run-pass/regions-debruijn-of-object.rs
src/test/run-pass/regions-debruijn-of-object.rs
+25
-0
未找到文件。
src/librustc_typeck/astconv.rs
浏览文件 @
02aacaba
...
...
@@ -516,8 +516,15 @@ pub fn instantiate_poly_trait_ref<'tcx>(
{
let
mut
projections
=
Vec
::
new
();
// the trait reference introduces a binding level here, so
// we need to shift the `rscope`. It'd be nice if we could
// do away with this rscope stuff and work this knowledge
// into resolve_lifetimes, as we do with non-omitted
// lifetimes. Oh well, not there yet.
let
shifted_rscope
=
ShiftedRscope
::
new
(
rscope
);
let
trait_ref
=
instantiate_trait_ref
(
this
,
rscope
,
&
ast_trait_ref
.trait_ref
,
instantiate_trait_ref
(
this
,
&
shifted_
rscope
,
&
ast_trait_ref
.trait_ref
,
self_ty
,
Some
(
&
mut
projections
));
for
projection
in
projections
.into_iter
()
{
...
...
@@ -561,6 +568,29 @@ pub fn instantiate_trait_ref<'tcx>(
}
}
fn
object_path_to_poly_trait_ref
<
'a
,
'tcx
>
(
this
:
&
AstConv
<
'tcx
>
,
rscope
:
&
RegionScope
,
trait_def_id
:
ast
::
DefId
,
path
:
&
ast
::
Path
,
mut
projections
:
&
mut
Vec
<
ty
::
PolyProjectionPredicate
<
'tcx
>>
)
->
ty
::
PolyTraitRef
<
'tcx
>
{
// we are introducing a binder here, so shift the
// anonymous regions depth to account for that
let
shifted_rscope
=
ShiftedRscope
::
new
(
rscope
);
let
mut
tmp
=
Vec
::
new
();
let
trait_ref
=
ty
::
Binder
(
ast_path_to_trait_ref
(
this
,
&
shifted_rscope
,
trait_def_id
,
None
,
path
,
Some
(
&
mut
tmp
)));
projections
.extend
(
tmp
.into_iter
()
.map
(
ty
::
Binder
));
trait_ref
}
fn
ast_path_to_trait_ref
<
'a
,
'tcx
>
(
this
:
&
AstConv
<
'tcx
>
,
rscope
:
&
RegionScope
,
...
...
@@ -573,13 +603,6 @@ fn ast_path_to_trait_ref<'a,'tcx>(
debug!
(
"ast_path_to_trait_ref {:?}"
,
path
);
let
trait_def
=
this
.get_trait_def
(
trait_def_id
);
// the trait reference introduces a binding level here, so
// we need to shift the `rscope`. It'd be nice if we could
// do away with this rscope stuff and work this knowledge
// into resolve_lifetimes, as we do with non-omitted
// lifetimes. Oh well, not there yet.
let
shifted_rscope
=
ShiftedRscope
::
new
(
rscope
);
let
(
regions
,
types
,
assoc_bindings
)
=
match
path
.segments
.last
()
.unwrap
()
.parameters
{
ast
::
AngleBracketedParameters
(
ref
data
)
=>
{
// For now, require that parenthetical notation be used
...
...
@@ -595,7 +618,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
the crate attributes to enable"
);
}
convert_angle_bracketed_parameters
(
this
,
&
shifted_
rscope
,
data
)
convert_angle_bracketed_parameters
(
this
,
rscope
,
data
)
}
ast
::
ParenthesizedParameters
(
ref
data
)
=>
{
// For now, require that parenthetical notation be used
...
...
@@ -616,7 +639,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
};
let
substs
=
create_substs_for_ast_path
(
this
,
&
shifted_
rscope
,
rscope
,
path
.span
,
&
trait_def
.generics
,
self_ty
,
...
...
@@ -851,15 +874,11 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
match
this
.tcx
()
.def_map
.borrow
()
.get
(
&
id
)
{
Some
(
&
def
::
DefTrait
(
trait_def_id
))
=>
{
let
mut
projection_bounds
=
Vec
::
new
();
let
trait_ref
=
ty
::
Binder
(
ast_path_to
_trait_ref
(
this
,
let
trait_ref
=
object_path_to_poly
_trait_ref
(
this
,
rscope
,
trait_def_id
,
None
,
path
,
Some
(
&
mut
projection_bounds
)));
let
projection_bounds
=
projection_bounds
.into_iter
()
.map
(
ty
::
Binder
)
.collect
();
&
mut
projection_bounds
);
Ok
((
trait_ref
,
projection_bounds
))
}
_
=>
{
...
...
@@ -1095,16 +1114,13 @@ pub fn ast_ty_to_ty<'tcx>(
// N.B. this case overlaps somewhat with
// TyObjectSum, see that fn for details
let
mut
projection_bounds
=
Vec
::
new
();
let
trait_ref
=
ast_path_to_trait_ref
(
this
,
let
trait_ref
=
object_path_to_poly_trait_ref
(
this
,
rscope
,
trait_def_id
,
None
,
path
,
Some
(
&
mut
projection_bounds
));
let
trait_ref
=
ty
::
Binder
(
trait_ref
);
let
projection_bounds
=
projection_bounds
.into_iter
()
.map
(
ty
::
Binder
)
.collect
();
&
mut
projection_bounds
);
trait_ref_to_object_type
(
this
,
rscope
,
path
.span
,
trait_ref
,
projection_bounds
,
&
[])
}
...
...
src/test/compile-fail/issue-20831-debruijn.rs
0 → 100644
浏览文件 @
02aacaba
// 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.
// Regression test for #20831: debruijn index account was thrown off
// by the (anonymous) lifetime in `<Self as Publisher>::Output`
// below. Note that changing to a named lifetime made the problem go
// away.
use
std
::
ops
::{
Shl
,
Shr
};
use
std
::
cell
::
RefCell
;
pub
trait
Subscriber
{
type
Input
;
}
pub
trait
Publisher
<
'a
>
{
type
Output
;
fn
subscribe
(
&
mut
self
,
Box
<
Subscriber
<
Input
=
Self
::
Output
>
+
'a
>
);
}
pub
trait
Processor
<
'a
>
:
Subscriber
+
Publisher
<
'a
>
{
}
impl
<
'a
,
P
>
Processor
<
'a
>
for
P
where
P
:
Subscriber
+
Publisher
<
'a
>
{
}
struct
MyStruct
<
'a
>
{
sub
:
Box
<
Subscriber
<
Input
=
u64
>
+
'a
>
}
impl
<
'a
>
Publisher
<
'a
>
for
MyStruct
<
'a
>
{
type
Output
=
u64
;
fn
subscribe
(
&
mut
self
,
t
:
Box
<
Subscriber
<
Input
=<
Self
as
Publisher
>
::
Output
>
+
'a
>
)
{
// Not obvious, but there is an implicit lifetime here -------^
//~^^ ERROR cannot infer
//
// The fact that `Publisher` is using an implicit lifetime is
// what was causing the debruijn accounting to be off, so
// leave it that way!
self
.sub
=
t
;
}
}
fn
main
()
{}
src/test/run-pass/regions-debruijn-of-object.rs
0 → 100644
浏览文件 @
02aacaba
// 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.
struct
ctxt
<
'tcx
>
{
x
:
&
'tcx
i32
}
trait
AstConv
<
'tcx
>
{
fn
tcx
<
'a
>
(
&
'a
self
)
->
&
'a
ctxt
<
'tcx
>
;
}
fn
foo
(
conv
:
&
AstConv
)
{
}
fn
bar
<
'tcx
>
(
conv
:
&
AstConv
<
'tcx
>
)
{
foo
(
conv
)
}
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录