Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1eb42f1c
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,发现更多精彩内容 >>
提交
1eb42f1c
编写于
9月 18, 2015
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add feature gate
上级
605a4729
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
52 addition
and
2 deletion
+52
-2
src/doc/reference.md
src/doc/reference.md
+4
-1
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+20
-1
src/test/compile-fail/empty-struct-with-braces-1.rs
src/test/compile-fail/empty-struct-with-braces-1.rs
+2
-0
src/test/compile-fail/empty-struct-with-braces-2.rs
src/test/compile-fail/empty-struct-with-braces-2.rs
+1
-0
src/test/compile-fail/empty-struct-with-braces-3.rs
src/test/compile-fail/empty-struct-with-braces-3.rs
+21
-0
src/test/run-pass/empty-struct-with-braces.rs
src/test/run-pass/empty-struct-with-braces.rs
+2
-0
src/test/run-pass/issue-16819.rs
src/test/run-pass/issue-16819.rs
+2
-0
未找到文件。
src/doc/reference.md
浏览文件 @
1eb42f1c
...
...
@@ -1178,10 +1178,11 @@ let px: i32 = match p { Point(x, _) => x };
```
A _unit-like struct_ is a structure without any fields, defined by leaving off
the list of fields entirely. Such structure implicitly defines a constant of
the list of fields entirely. Such
a
structure implicitly defines a constant of
its type with the same name. For example:
```
# #![feature(braced_empty_structs)]
struct Cookie;
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
```
...
...
@@ -1189,6 +1190,7 @@ let c = [Cookie, Cookie {}, Cookie, Cookie {}];
is equivalent to
```
# #![feature(braced_empty_structs)]
struct Cookie {}
const Cookie: Cookie = Cookie {};
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
...
...
@@ -2420,6 +2422,7 @@ The currently implemented features of the reference compiler are:
terms of encapsulation).
* - `default_type_parameter_fallback` - Allows type parameter defaults to
influence type inference.
* - `braced_empty_structs` - Allows use of empty structs with braces.
If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about `#![feature]` directives which enabled
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
1eb42f1c
...
...
@@ -191,6 +191,9 @@
// allow `#[unwind]`
(
"unwind_attributes"
,
"1.4.0"
,
None
,
Active
),
// allow empty structs/enum variants with braces
(
"braced_empty_structs"
,
"1.5.0"
,
None
,
Active
),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
...
...
@@ -775,7 +778,7 @@ fn visit_item(&mut self, i: &ast::Item) {
}
}
ast
::
ItemStruct
(
..
)
=>
{
ast
::
ItemStruct
(
ref
def
,
_
)
=>
{
if
attr
::
contains_name
(
&
i
.attrs
[
..
],
"simd"
)
{
self
.gate_feature
(
"simd"
,
i
.span
,
"SIMD types are experimental and possibly buggy"
);
...
...
@@ -794,6 +797,10 @@ fn visit_item(&mut self, i: &ast::Item) {
}
}
}
if
def
.fields
.is_empty
()
&&
def
.ctor_id
.is_none
()
{
self
.gate_feature
(
"braced_empty_structs"
,
i
.span
,
"empty structs with braces are unstable"
);
}
}
ast
::
ItemDefaultImpl
(
..
)
=>
{
...
...
@@ -843,6 +850,12 @@ fn visit_expr(&mut self, e: &ast::Expr) {
"box expression syntax is experimental;
\
you can call `Box::new` instead."
);
}
ast
::
ExprStruct
(
_
,
ref
fields
,
ref
expr
)
=>
{
if
fields
.is_empty
()
&&
expr
.is_none
()
{
self
.gate_feature
(
"braced_empty_structs"
,
e
.span
,
"empty structs with braces are unstable"
);
}
}
_
=>
{}
}
visit
::
walk_expr
(
self
,
e
);
...
...
@@ -867,6 +880,12 @@ fn visit_pat(&mut self, pattern: &ast::Pat) {
pattern
.span
,
"box pattern syntax is experimental"
);
}
ast
::
PatStruct
(
_
,
ref
fields
,
dotdot
)
=>
{
if
fields
.is_empty
()
&&
!
dotdot
{
self
.gate_feature
(
"braced_empty_structs"
,
pattern
.span
,
"empty structs with braces are unstable"
);
}
}
_
=>
{}
}
visit
::
walk_pat
(
self
,
pattern
)
...
...
src/test/compile-fail/empty-struct-with-braces-1.rs
浏览文件 @
1eb42f1c
...
...
@@ -10,6 +10,8 @@
// Empty struct defined with braces shouldn't add names into value namespace
#![feature(braced_empty_structs)]
struct
Empty
{}
fn
main
()
{
...
...
src/test/compile-fail/empty-struct-with-braces-2.rs
浏览文件 @
1eb42f1c
...
...
@@ -10,6 +10,7 @@
// Empty struct defined with braces shouldn't add names into value namespace
#![feature(braced_empty_structs)]
#![deny(warnings)]
struct
Empty
{}
...
...
src/test/compile-fail/empty-struct-with-braces-3.rs
0 → 100644
浏览文件 @
1eb42f1c
// 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 gate test for empty struct with braces
struct
Empty
{}
//~ ERROR empty structs with braces are unstable
fn
main
()
{
let
e
=
Empty
{};
//~ ERROR empty structs with braces are unstable
match
e
{
Empty
{}
=>
{}
//~ ERROR empty structs with braces are unstable
}
}
src/test/run-pass/empty-struct-with-braces.rs
浏览文件 @
1eb42f1c
...
...
@@ -11,6 +11,8 @@
// Empty struct defined with braces add names into type namespace
// Empty struct defined without braces add names into both type and value namespaces
#![feature(braced_empty_structs)]
struct
Empty1
{}
struct
Empty2
;
struct
Empty3
{}
...
...
src/test/run-pass/issue-16819.rs
浏览文件 @
1eb42f1c
...
...
@@ -10,6 +10,8 @@
//`#[cfg]` on struct field permits empty unusable struct
#![feature(braced_empty_structs)]
struct
S
{
#[cfg(untrue)]
a
:
int
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录