Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ed66fe48
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,发现更多精彩内容 >>
提交
ed66fe48
编写于
5月 05, 2016
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement RFC 1440 "Allow Drop types in statics/const functions".
上级
4f5900ae
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
23 deletion
+54
-23
src/librustc_mir/diagnostics.rs
src/librustc_mir/diagnostics.rs
+1
-1
src/librustc_mir/transform/qualify_consts.rs
src/librustc_mir/transform/qualify_consts.rs
+32
-5
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+4
-1
src/test/compile-fail/check-static-values-constraints.rs
src/test/compile-fail/check-static-values-constraints.rs
+13
-13
src/test/compile-fail/issue-9243.rs
src/test/compile-fail/issue-9243.rs
+3
-2
src/test/compile-fail/static-mut-not-constant.rs
src/test/compile-fail/static-mut-not-constant.rs
+1
-1
未找到文件。
src/librustc_mir/diagnostics.rs
浏览文件 @
ed66fe48
...
...
@@ -345,7 +345,7 @@ fn drop(&mut self) {}
const F : Foo = Foo { a : 0 };
// error: constants are not allowed to have destructors
static S : Foo = Foo { a : 0 };
// error:
statics are not allowed to have destructors
// error:
destructors in statics are an unstable feature
```
To solve this issue, please use a type which does allow the usage of type with
...
...
src/librustc_mir/transform/qualify_consts.rs
浏览文件 @
ed66fe48
...
...
@@ -222,13 +222,40 @@ fn nest<F: FnOnce(&mut Self)>(&mut self, f: F) {
}
/// Check for NEEDS_DROP (from an ADT or const fn call) and
/// error, unless we're in a function.
/// error, unless we're in a function, or the feature-gate
/// for globals with destructors is enabled.
fn
deny_drop
(
&
self
)
{
if
self
.mode
!=
Mode
::
Fn
&&
self
.qualif
.intersects
(
Qualif
::
NEEDS_DROP
)
{
span_err!
(
self
.tcx.sess
,
self
.span
,
E0493
,
"{}s are not allowed to have destructors"
,
self
.mode
);
if
self
.mode
==
Mode
::
Fn
||
!
self
.qualif
.intersects
(
Qualif
::
NEEDS_DROP
)
{
return
;
}
// Static and const fn's allow destructors, but they're feature-gated.
let
msg
=
if
self
.mode
!=
Mode
::
Const
{
// Feature-gate for globals with destructors is enabled.
if
self
.tcx.sess.features
.borrow
()
.drop_types_in_const
{
return
;
}
// This comes from a macro that has #[allow_internal_unstable].
if
self
.tcx.sess
.codemap
()
.span_allows_unstable
(
self
.span
)
{
return
;
}
format!
(
"destructors in {}s are an unstable feature"
,
self
.mode
)
}
else
{
format!
(
"{}s are not allowed to have destructors"
,
self
.mode
)
};
let
mut
err
=
struct_span_err!
(
self
.tcx.sess
,
self
.span
,
E0493
,
"{}"
,
msg
);
if
self
.mode
!=
Mode
::
Const
{
help!
(
&
mut
err
,
"in Nightly builds, add `#![feature(drop_types_in_const)]`
\
to the crate attributes to enable"
);
}
err
.emit
();
}
/// Check if an Lvalue with the current qualifications could
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
ed66fe48
...
...
@@ -266,7 +266,10 @@ pub fn new() -> Features {
(
active
,
specialization
,
"1.7.0"
,
Some
(
31844
)),
// pub(restricted) visibilities (RFC 1422)
(
active
,
pub_restricted
,
"1.9.0"
,
Some
(
32409
))
(
active
,
pub_restricted
,
"1.9.0"
,
Some
(
32409
)),
// Allow Drop types in statics/const functions (RFC 1440)
(
active
,
drop_types_in_const
,
"1.9.0"
,
Some
(
33156
))
);
declare_features!
(
...
...
src/test/compile-fail/check-static-values-constraints.rs
浏览文件 @
ed66fe48
...
...
@@ -37,7 +37,7 @@ enum SafeEnum {
// This one should fail
static
STATIC3
:
SafeEnum
=
SafeEnum
::
Variant3
(
WithDtor
);
//~^ ERROR
statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
// This enum will be used to test that variants
...
...
@@ -54,9 +54,9 @@ fn drop(&mut self) {}
static
STATIC4
:
UnsafeEnum
=
UnsafeEnum
::
Variant5
;
//~^ ERROR
statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
static
STATIC5
:
UnsafeEnum
=
UnsafeEnum
::
Variant6
(
0
);
//~^ ERROR
statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
struct
SafeStruct
{
...
...
@@ -71,7 +71,7 @@ struct SafeStruct {
// field2 has an unsafe value, hence this should fail
static
STATIC7
:
SafeStruct
=
SafeStruct
{
field1
:
SafeEnum
::
Variant1
,
field2
:
SafeEnum
::
Variant3
(
WithDtor
)};
//~^ ERROR
statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
// Test variadic constructor for structs. The base struct should be examined
// as well as every field present in the constructor.
...
...
@@ -84,7 +84,7 @@ struct SafeStruct {
static
STATIC9
:
SafeStruct
=
SafeStruct
{
field1
:
SafeEnum
::
Variant1
,
..
SafeStruct
{
field1
:
SafeEnum
::
Variant3
(
WithDtor
),
field2
:
SafeEnum
::
Variant1
}};
//~^^ ERROR
statics are not allowed to have destructors
//~^^ ERROR
destructors in statics are an unstable feature
struct
UnsafeStruct
;
...
...
@@ -94,7 +94,7 @@ fn drop(&mut self) {}
// Types with destructors are not allowed for statics
static
STATIC10
:
UnsafeStruct
=
UnsafeStruct
;
//~^ ERROR
statics are not allowed to have destructor
//~^ ERROR
destructors in statics are an unstable feature
struct
MyOwned
;
...
...
@@ -105,19 +105,19 @@ fn drop(&mut self) {}
// to have types with destructors
// These should fail
static
mut
STATIC12
:
UnsafeStruct
=
UnsafeStruct
;
//~^ ERROR
mutable statics are not allowed to have destructors
//~^^ ERROR
statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
//~^^ ERROR
destructors in statics are an unstable feature
static
mut
STATIC13
:
SafeStruct
=
SafeStruct
{
field1
:
SafeEnum
::
Variant1
,
//~^ ERROR
mutable statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
field2
:
SafeEnum
::
Variant3
(
WithDtor
)};
//~^ ERROR:
statics are not allowed to have destructors
//~^ ERROR:
destructors in statics are an unstable feature
static
mut
STATIC14
:
SafeStruct
=
SafeStruct
{
//~^ ERROR
mutable statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
field1
:
SafeEnum
::
Variant1
,
field2
:
SafeEnum
::
Variant4
(
"str"
.to_string
())
//~^ ERROR
method calls in statics are limited to constant inherent method
s
//~^ ERROR
calls in statics are limited to constant function
s
};
static
STATIC15
:
&
'static
[
Box
<
MyOwned
>
]
=
&
[
...
...
@@ -131,7 +131,7 @@ fn drop(&mut self) {}
);
static
mut
STATIC17
:
SafeEnum
=
SafeEnum
::
Variant1
;
//~^ ERROR
mutable statics are not allowed to have destructors
//~^ ERROR
destructors in statics are an unstable feature
static
STATIC19
:
Box
<
isize
>
=
box
3
;
...
...
src/test/compile-fail/issue-9243.rs
浏览文件 @
ed66fe48
...
...
@@ -10,11 +10,12 @@
// Regression test for issue 9243
struct
Test
{
pub
struct
Test
{
mem
:
isize
,
}
pub
static
g_test
:
Test
=
Test
{
mem
:
0
};
//~ ERROR statics are not allowed to have destructors
pub
static
g_test
:
Test
=
Test
{
mem
:
0
};
//~^ ERROR destructors in statics are an unstable feature
impl
Drop
for
Test
{
fn
drop
(
&
mut
self
)
{}
...
...
src/test/compile-fail/static-mut-not-constant.rs
浏览文件 @
ed66fe48
...
...
@@ -12,6 +12,6 @@
static
mut
a
:
Box
<
isize
>
=
box
3
;
//~^ ERROR allocations are not allowed in statics
//~^^ ERROR
mutable statics are not allowed to have boxes
//~^^ ERROR
destructors in statics are an unstable feature
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录