Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a8710539
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,发现更多精彩内容 >>
提交
a8710539
编写于
9月 10, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expand the patterns test with a bunch more scenarios
上级
2f6628ec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
172 addition
and
5 deletion
+172
-5
src/test/ui/nll/user-annotations/patterns.rs
src/test/ui/nll/user-annotations/patterns.rs
+79
-1
src/test/ui/nll/user-annotations/patterns.stderr
src/test/ui/nll/user-annotations/patterns.stderr
+93
-4
未找到文件。
src/test/ui/nll/user-annotations/patterns.rs
浏览文件 @
a8710539
...
...
@@ -2,7 +2,23 @@
#![feature(nll)]
fn
main
()
{
fn
variable_no_initializer
()
{
// FIXME: It is unclear to me whether this should be an error or not.
let
x
=
22
;
let
y
:
&
'static
u32
;
y
=
&
x
;
}
fn
variable_with_initializer
()
{
let
x
=
22
;
let
y
:
&
'static
u32
=
&
x
;
//~ ERROR
}
fn
underscore_with_initializer
()
{
let
x
=
22
;
let
_
:
&
'static
u32
=
&
x
;
//~ ERROR
let
_
:
Vec
<&
'static
String
>
=
vec!
[
&
String
::
new
()];
//~^ ERROR borrowed value does not live long enough [E0597]
...
...
@@ -12,3 +28,65 @@ fn main() {
let
(
_
a
,
b
):
(
Vec
<&
'static
String
>
,
_
)
=
(
vec!
[
&
String
::
new
()],
44
);
//~^ ERROR borrowed value does not live long enough [E0597]
}
fn
pair_underscores_with_initializer
()
{
let
x
=
22
;
let
(
_
,
_
):
(
&
'static
u32
,
u32
)
=
(
&
x
,
44
);
//~ ERROR
}
fn
pair_variable_with_initializer
()
{
let
x
=
22
;
let
(
y
,
_
):
(
&
'static
u32
,
u32
)
=
(
&
x
,
44
);
//~ ERROR
}
struct
Single
<
T
>
{
value
:
T
}
fn
struct_single_field_variable_with_initializer
()
{
let
x
=
22
;
let
Single
{
value
:
y
}:
Single
<&
'static
u32
>
=
Single
{
value
:
&
x
};
//~ ERROR
}
fn
struct_single_field_underscore_with_initializer
()
{
let
x
=
22
;
let
Single
{
value
:
_
}:
Single
<&
'static
u32
>
=
Single
{
value
:
&
x
};
//~ ERROR
}
struct
Double
<
T
>
{
value1
:
T
,
value2
:
T
}
fn
struct_double_field_underscore_with_initializer
()
{
let
x
=
22
;
let
Double
{
value1
:
_
,
value2
:
_
}:
Double
<&
'static
u32
>
=
Double
{
value1
:
&
x
,
//~ ERROR
value2
:
&
44
,
};
}
fn
static_to_a_to_static_through_variable
<
'a
>
(
x
:
&
'a
u32
)
->
&
'static
u32
{
// The error in this test is inconsistency with
// `static_to_a_to_static_through_tuple`, but "feels right" to
// me. It occurs because we special case the single binding case
// and force the type of `y` to be `&'a u32`, even though the
// right-hand side has type `&'static u32`.
let
y
:
&
'a
u32
=
&
22
;
y
//~ ERROR
}
fn
static_to_a_to_static_through_tuple
<
'a
>
(
x
:
&
'a
u32
)
->
&
'static
u32
{
// FIXME: The fact that this type-checks is perhaps surprising.
// What happens is that the right-hand side is constrained to have
// type `&'a u32`, which is possible, because it has type
// `&'static u32`. The variable `y` is then forced to have type
// `&'static u32`, but it is constrained only by the right-hand
// side, not the ascribed type, and hence it passes.
let
(
y
,
_
z
):
(
&
'a
u32
,
u32
)
=
(
&
22
,
44
);
y
}
fn
a_to_static_then_static
<
'a
>
(
x
:
&
'a
u32
)
->
&
'static
u32
{
let
(
y
,
_
z
):
(
&
'static
u32
,
u32
)
=
(
x
,
44
);
//~ ERROR
y
}
fn
main
()
{
}
src/test/ui/nll/user-annotations/patterns.stderr
浏览文件 @
a8710539
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:15:27
|
LL | let y: &'static u32 = &x; //~ ERROR
| ^^ borrowed value does not live long enough
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:20:27
|
LL | let _: &'static u32 = &x; //~ ERROR
| ^^ borrowed value does not live long enough
...
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/patterns.rs:
6
:41
--> $DIR/patterns.rs:
22
:41
|
LL | let _: Vec<&'static String> = vec![&String::new()];
| ^^^^^^^^^^^^^ - temporary value only lives until here
...
...
@@ -9,7 +30,7 @@ LL | let _: Vec<&'static String> = vec![&String::new()];
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/patterns.rs:
9
:52
--> $DIR/patterns.rs:
25
:52
|
LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ^^^^^^^^^^^^^ - temporary value only lives until here
...
...
@@ -19,7 +40,7 @@ LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/patterns.rs:
12
:53
--> $DIR/patterns.rs:
28
:53
|
LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ^^^^^^^^^^^^^ - temporary value only lives until here
...
...
@@ -28,6 +49,74 @@ LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 3 previous errors
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:34:40
|
LL | let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ^^ borrowed value does not live long enough
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:39:40
|
LL | let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ^^ borrowed value does not live long enough
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:46:69
|
LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| ^^ borrowed value does not live long enough
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:51:69
|
LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| ^^ borrowed value does not live long enough
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `x` does not live long enough
--> $DIR/patterns.rs:59:17
|
LL | value1: &x, //~ ERROR
| ^^ borrowed value does not live long enough
...
LL | }
| - `x` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error: unsatisfied lifetime constraints
--> $DIR/patterns.rs:72:5
|
LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
...
LL | y //~ ERROR
| ^ returning this value requires that `'a` must outlive `'static`
error: unsatisfied lifetime constraints
--> $DIR/patterns.rs:88:40
|
LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
| ^^^^^^^ requires that `'a` must outlive `'static`
error: aborting due to 12 previous errors
For more information about this error, try `rustc --explain E0597`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录