Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
44df3656
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,发现更多精彩内容 >>
提交
44df3656
编写于
7月 26, 2018
作者:
T
toidiu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature gate for inferring 'static lifetimes
上级
45b48b9b
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
110 addition
and
7 deletion
+110
-7
src/librustc_typeck/outlives/utils.rs
src/librustc_typeck/outlives/utils.rs
+24
-7
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+9
-0
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.rs
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.rs
+23
-0
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr
+17
-0
src/test/ui/rfc-2093-infer-outlives/infer-static.rs
src/test/ui/rfc-2093-infer-outlives/infer-static.rs
+25
-0
src/test/ui/rfc-2093-infer-outlives/infer-static.stderr
src/test/ui/rfc-2093-infer-outlives/infer-static.stderr
+12
-0
未找到文件。
src/librustc_typeck/outlives/utils.rs
浏览文件 @
44df3656
...
...
@@ -27,7 +27,7 @@ pub fn insert_outlives_predicate<'tcx>(
)
{
// If the `'a` region is bound within the field type itself, we
// don't want to propagate this constraint to the header.
if
!
is_free_region
(
outlived_region
)
{
if
!
is_free_region
(
tcx
,
outlived_region
)
{
return
;
}
...
...
@@ -120,7 +120,7 @@ pub fn insert_outlives_predicate<'tcx>(
}
UnpackedKind
::
Lifetime
(
r
)
=>
{
if
!
is_free_region
(
r
)
{
if
!
is_free_region
(
tcx
,
r
)
{
return
;
}
required_predicates
.insert
(
ty
::
OutlivesPredicate
(
kind
,
outlived_region
));
...
...
@@ -128,19 +128,36 @@ pub fn insert_outlives_predicate<'tcx>(
}
}
fn
is_free_region
(
region
:
Region
<
'_
>
)
->
bool
{
fn
is_free_region
<
'tcx
>
(
tcx
:
TyCtxt
<
'_
,
'tcx
,
'tcx
>
,
region
:
Region
<
'_
>
)
->
bool
{
// First, screen for regions that might appear in a type header.
match
region
{
// *These* correspond to `T: 'a` relationships where `'a` is
// either declared on the type or `'static`:
// These correspond to `T: 'a` relationships:
//
// struct Foo<'a, T> {
// field: &'a T, // this would generate a ReEarlyBound referencing `'a`
// field2: &'static T, // this would generate a ReStatic
// }
//
// We care about these, so fall through.
RegionKind
::
ReStatic
|
RegionKind
::
ReEarlyBound
(
_
)
=>
true
,
RegionKind
::
ReEarlyBound
(
_
)
=>
true
,
// These correspond to `T: 'static` relationships which can be
// rather surprising. We are therefore putting this behind a
// feature flag:
//
// struct Foo<'a, T> {
// field: &'static T, // this would generate a ReStatic
// }
RegionKind
::
ReStatic
=>
{
if
tcx
.sess
.features_untracked
()
.infer_static_outlives_requirements
{
true
}
else
{
false
}
}
// Late-bound regions can appear in `fn` types:
//
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
44df3656
...
...
@@ -396,6 +396,9 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// Infer outlives requirements; RFC 2093
(
active
,
infer_outlives_requirements
,
"1.26.0"
,
Some
(
44493
),
None
),
// Infer outlives requirements; RFC 2093
(
active
,
infer_static_outlives_requirements
,
"1.26.0"
,
Some
(
44493
),
None
),
// Multiple patterns with `|` in `if let` and `while let`
(
active
,
if_while_or_patterns
,
"1.26.0"
,
Some
(
48215
),
None
),
...
...
@@ -1057,6 +1060,12 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
"infer outlives requirements is an experimental feature"
,
cfg_fn!
(
infer_outlives_requirements
))),
// RFC #2093
(
"infer_static_outlives_requirements"
,
Normal
,
Gated
(
Stability
::
Unstable
,
"infer_static_outlives_requirements"
,
"infer 'static lifetime requirements"
,
cfg_fn!
(
infer_static_outlives_requirements
))),
// RFC 2070
(
"panic_implementation"
,
Normal
,
Gated
(
Stability
::
Unstable
,
"panic_implementation"
,
...
...
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.rs
0 → 100644
浏览文件 @
44df3656
// 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.
// ignore-tidy-linelength
#![feature(infer_outlives_requirements)]
struct
Foo
<
U
>
{
bar
:
Bar
<
U
>
//~ ERROR 16:5: 16:16: the parameter type `U` may not live long enough [E0310]
}
struct
Bar
<
T
:
'static
>
{
x
:
T
,
}
fn
main
()
{}
src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr
0 → 100644
浏览文件 @
44df3656
error[E0310]: the parameter type `U` may not live long enough
--> $DIR/dont-infer-static.rs:16:5
|
LL | struct Foo<U> {
| - help: consider adding an explicit lifetime bound `U: 'static`...
LL | bar: Bar<U> //~ ERROR 16:5: 16:16: the parameter type `U` may not live long enough [E0310]
| ^^^^^^^^^^^
|
note: ...so that the type `U` will meet its required lifetime bounds
--> $DIR/dont-infer-static.rs:16:5
|
LL | bar: Bar<U> //~ ERROR 16:5: 16:16: the parameter type `U` may not live long enough [E0310]
| ^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0310`.
src/test/ui/rfc-2093-infer-outlives/infer-static.rs
0 → 100644
浏览文件 @
44df3656
// 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.
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
#![feature(infer_static_outlives_requirements)]
#[rustc_outlives]
struct
Foo
<
U
>
{
//~ ERROR 16:1: 18:2: rustc_outlives
bar
:
Bar
<
U
>
}
struct
Bar
<
T
:
'static
>
{
x
:
T
,
}
fn
main
()
{}
src/test/ui/rfc-2093-infer-outlives/infer-static.stderr
0 → 100644
浏览文件 @
44df3656
error: rustc_outlives
--> $DIR/infer-static.rs:16:1
|
LL | / struct Foo<U> { //~ ERROR 16:1: 18:2: rustc_outlives
LL | | bar: Bar<U>
LL | | }
| |_^
|
= note: U : 'static
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录