Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
34575e69
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,发现更多精彩内容 >>
提交
34575e69
编写于
8月 31, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
now that we can handle subtyping, fix higher-ranked equality
上级
07e21b1e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
22 deletion
+28
-22
src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
+27
-10
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.rs
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.rs
+1
-4
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.stderr
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.stderr
+0
-8
未找到文件。
src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
浏览文件 @
34575e69
...
...
@@ -458,19 +458,30 @@ fn binders<T>(
self
.b_scopes
.push
(
b_scope
);
self
.a_scopes
.push
(
a_scope
);
// FIXME -- to be fully correct, we would set the ambient
// variance to Covariant here. As is, we will sometimes
// propagate down an ambient variance of Equal -- this in
// turn causes us to report errors in some cases where
// types perhaps *ought* to be equal. See the
// `hr-fn-aau-eq-abu.rs` test for an example. Fixing this
// though is a bit nontrivial: in particular, it would
// require a more involved handling of canonical
// variables, since we would no longer be able to rely on
// having an `==` relationship for canonical variables.
// Reset the ambient variance to covariant. This is needed
// to correctly handle cases like
//
// for<'a> fn(&'a u32, &'a u3) == for<'b, 'c> fn(&'b u32, &'c u32)
//
// Somewhat surprisingly, these two types are actually
// **equal**, even though the one on the right looks more
// polymorphic. The reason is due to subtyping. To see it,
// consider that each function can call the other:
//
// - The left function can call the right with `'b` and
// `'c` both equal to `'a`
//
// - The right function can call the left with `'a` set to
// `{P}`, where P is the point in the CFG where the call
// itself occurs. Note that `'b` and `'c` must both
// include P. At the point, the call works because of
// subtyping (i.e., `&'b u32 <: &{P} u32`).
let
variance
=
::
std
::
mem
::
replace
(
&
mut
self
.ambient_variance
,
ty
::
Variance
::
Covariant
);
self
.relate
(
a
.skip_binder
(),
b
.skip_binder
())
?
;
self
.ambient_variance
=
variance
;
self
.b_scopes
.pop
()
.unwrap
();
self
.a_scopes
.pop
()
.unwrap
();
}
...
...
@@ -491,8 +502,14 @@ fn binders<T>(
self
.a_scopes
.push
(
a_scope
);
self
.b_scopes
.push
(
b_scope
);
// Reset ambient variance to contravariance. See the
// covariant case above for an explanation.
let
variance
=
::
std
::
mem
::
replace
(
&
mut
self
.ambient_variance
,
ty
::
Variance
::
Contravariant
);
self
.relate
(
a
.skip_binder
(),
b
.skip_binder
())
?
;
self
.ambient_variance
=
variance
;
self
.b_scopes
.pop
()
.unwrap
();
self
.a_scopes
.pop
()
.unwrap
();
}
...
...
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.rs
浏览文件 @
34575e69
...
...
@@ -16,9 +16,7 @@
// another -- effectively, the single lifetime `'a` is just inferred
// to be the intersection of the two distinct lifetimes.
//
// FIXME: However, we currently reject this example with an error,
// because of how we handle binders and equality in `relate_tys`.
//
// compile-pass
// compile-flags:-Zno-leak-check
#![feature(nll)]
...
...
@@ -31,7 +29,6 @@ fn make_cell_aa() -> Cell<for<'a> fn(&'a u32, &'a u32)> {
fn
aa_eq_ab
()
{
let
a
:
Cell
<
for
<
'a
,
'b
>
fn
(
&
'a
u32
,
&
'b
u32
)
>
=
make_cell_aa
();
//~^ ERROR higher-ranked subtype error
drop
(
a
);
}
...
...
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.stderr
已删除
100644 → 0
浏览文件 @
07e21b1e
error: higher-ranked subtype error
--> $DIR/hr-fn-aau-eq-abu.rs:33:53
|
LL | let a: Cell<for<'a, 'b> fn(&'a u32, &'b u32)> = make_cell_aa();
| ^^^^^^^^^^^^^^
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录