Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
652fd2ef
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,发现更多精彩内容 >>
提交
652fd2ef
编写于
10月 30, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tests exercising `exists<'a> { forall<'b> { .. } }` pattern
Amazingly, this scenario was not tested for trait matching.
上级
b68fad67
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
163 addition
and
0 deletion
+163
-0
src/test/ui/hrtb/hrtb-exists-forall-fn.rs
src/test/ui/hrtb/hrtb-exists-forall-fn.rs
+23
-0
src/test/ui/hrtb/hrtb-exists-forall-fn.stderr
src/test/ui/hrtb/hrtb-exists-forall-fn.stderr
+24
-0
src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.rs
src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.rs
+35
-0
src/test/ui/hrtb/hrtb-exists-forall-trait-covariant.rs
src/test/ui/hrtb/hrtb-exists-forall-trait-covariant.rs
+37
-0
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.rs
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.rs
+29
-0
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr
+15
-0
未找到文件。
src/test/ui/hrtb/hrtb-exists-forall-fn.rs
0 → 100644
浏览文件 @
652fd2ef
// Test a `exists<'a> { forall<'b> { 'a = 'b } }` pattern -- which should not compile!
//
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
trait
Trait
<
T
>
{}
fn
foo
<
'a
>
()
->
fn
(
&
'a
u32
)
{
panic!
()
}
fn
main
()
{
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
//
// - The impl provides the clause `forall<'a> { (): Trait<fn(&'a u32)> }`
// - We instantiate `'a` existentially to get `(): Trait<fn(&?a u32)>`
// - We unify `fn(&?a u32)` with `for<'b> fn(&'b u32)`
// - This requires (among other things) instantiating `'b` universally,
// yielding `fn(&!b u32)`, in a fresh universe U1
// - So we get `?a = !b` but the universe U0 assigned to `?a` cannot name `!b`.
let
_
:
for
<
'b
>
fn
(
&
'b
u32
)
=
foo
();
//~ ERROR cannot infer
}
src/test/ui/hrtb/hrtb-exists-forall-fn.stderr
0 → 100644
浏览文件 @
652fd2ef
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/hrtb-exists-forall-fn.rs:22:34
|
LL | let _: for<'b> fn(&'b u32) = foo(); //~ ERROR cannot infer
| ^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:11), 'b) })...
= note: ...so that the expression is assignable:
expected for<'b> fn(&'b u32)
found fn(&u32)
note: but, the lifetime must be valid for the call at 22:34...
--> $DIR/hrtb-exists-forall-fn.rs:22:34
|
LL | let _: for<'b> fn(&'b u32) = foo(); //~ ERROR cannot infer
| ^^^^^
note: ...so type `fn(&u32)` of expression is valid during the expression
--> $DIR/hrtb-exists-forall-fn.rs:22:34
|
LL | let _: for<'b> fn(&'b u32) = foo(); //~ ERROR cannot infer
| ^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.
src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.rs
0 → 100644
浏览文件 @
652fd2ef
// Test a `exists<'a> { forall<'b> { 'a = 'b } }` pattern -- which should not compile!
//
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
//
// compile-pass
trait
Trait
<
T
>
{}
fn
foo
<
T
>
()
where
T
:
Trait
<
for
<
'b
>
fn
(
&
'b
u32
)
>
,
{
}
impl
<
'a
>
Trait
<
fn
(
&
'a
u32
)
>
for
()
{}
fn
main
()
{
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
//
// - The impl provides the clause `forall<'a> { (): Trait<fn(&'a u32)> }`
// - We instantiate `'a` existentially to get `(): Trait<fn(&?a u32)>`
// - We unify `fn(&?a u32)` with `for<'b> fn(&'b u32)` -- this does a
// "bidirectional" subtyping check, so we wind up with:
// - `fn(&?a u32) <: for<'b> fn(&'b u32)` :-
// - `&'!b u32 <: &?a u32`
// - `!'b: ?a` -- solveable if `?a` is inferred to `'empty`
// - `for<'b> fn(&'b u32) <: fn(&?a u32)` :-
// - `&?a u32 u32 <: &?b u32`
// - `?a: ?b` -- solveable if `?b` is also inferred to `'empty`
// - So the subtyping check succeeds, somewhat surprisingly.
// This is because we can use `'empty`.
foo
::
<
()
>
();
}
src/test/ui/hrtb/hrtb-exists-forall-trait-covariant.rs
0 → 100644
浏览文件 @
652fd2ef
// Test a `exists<'a> { forall<'b> { 'a = 'b } }` pattern -- which should not compile!
//
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
//
// compile-pass
trait
Trait
<
T
>
{}
fn
foo
<
T
>
()
where
T
:
Trait
<
for
<
'b
>
fn
(
fn
(
&
'b
u32
))
>
,
{
}
impl
<
'a
>
Trait
<
fn
(
fn
(
&
'a
u32
))
>
for
()
{}
fn
main
()
{
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
//
// - The impl provides the clause `forall<'a> { (): Trait<fn(fn(&'a u32))> }`
// - We instantiate `'a` existentially to get `(): Trait<fn(fn(&?a u32))>`
// - We unify `fn(fn(&?a u32))` with `for<'b> fn(fn(&'b u32))` -- this does a
// "bidirectional" subtyping check, so we wind up with:
// - `fn(fn(&?a u32)) <: for<'b> fn(fn(&'b u32))` :-
// - `fn(&!b u32) <: fn(&?a u32)`
// - `&?a u32 <: &!b u32`
// - `?a: !'b` -- solveable if `?a` is inferred to `'static`
// - `for<'b> fn(fn(&'b u32)) <: fn(fn(&?a u32))` :-
// - `fn(&?a u32) <: fn(&?b u32)`
// - `&?b u32 <: &?a u32`
// - `?b: ?a` -- solveable if `?b` is inferred to `'static`
// - So the subtyping check succeeds, somewhat surprisingly.
// This is because we can use `'static`.
foo
::
<
()
>
();
}
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.rs
0 → 100644
浏览文件 @
652fd2ef
// Test a `exists<'a> { forall<'b> { 'a = 'b } }` pattern -- which should not compile!
//
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
use
std
::
cell
::
Cell
;
trait
Trait
<
T
>
{}
fn
foo
<
T
>
()
where
T
:
Trait
<
for
<
'b
>
fn
(
Cell
<&
'b
u32
>
)
>
,
{
}
impl
<
'a
>
Trait
<
fn
(
Cell
<&
'a
u32
>
)
>
for
()
{}
fn
main
()
{
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
//
// - The impl provides the clause `forall<'a> { (): Trait<fn(&'a u32)> }`
// - We instantiate `'a` existentially to get `(): Trait<fn(&?a u32)>`
// - We unify `fn(&?a u32)` with `for<'b> fn(&'b u32)`
// - This requires (among other things) instantiating `'b` universally,
// yielding `fn(&!b u32)`, in a fresh universe U1
// - So we get `?a = !b` but the universe U0 assigned to `?a` cannot name `!b`.
foo
::
<
()
>
();
//~ ERROR cannot infer
}
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr
0 → 100644
浏览文件 @
652fd2ef
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:5
|
LL | foo::<()>(); //~ ERROR cannot infer
| ^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U3, name: BrNamed(crate0:DefIndex(1:11), 'b) })...
= note: ...but the lifetime must also be valid for lifetime RePlaceholder(Placeholder { universe: U3, name: BrNamed(crate0:DefIndex(1:11), 'b) })...
= note: ...so that the types are compatible:
expected Trait<for<'b> fn(std::cell::Cell<&'b u32>)>
found Trait<fn(std::cell::Cell<&u32>)>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录