Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
92df8a9a
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,发现更多精彩内容 >>
提交
92df8a9a
编写于
11月 09, 2015
作者:
M
Manish Goregaokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add E0517, E0518 for repr() errors
上级
2228bacd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
15 deletion
+87
-15
src/librustc/diagnostics.rs
src/librustc/diagnostics.rs
+73
-0
src/librustc/front/check_attr.rs
src/librustc/front/check_attr.rs
+14
-15
未找到文件。
src/librustc/diagnostics.rs
浏览文件 @
92df8a9a
...
...
@@ -2039,6 +2039,79 @@ fn foo() {}
Also, for now, it is not possible to write deprecation messages either.
"##
,
E0517
:
r##"
This error indicates that a `#[repr(..)]` attribute was placed on an unsupported
item.
Examples of erroneous code:
```
#[repr(C)]
type Foo = u8;
#[repr(packed)]
enum Foo {Bar, Baz}
#[repr(u8)]
struct Foo {bar: bool, baz: bool}
#[repr(C)]
impl Foo {
...
}
```
- The `#[repr(C)]` attribute can only be placed on structs and enums
- The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs
- The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums
These attributes do not work on typedefs, since typedefs are just aliases.
Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
discriminant size for C-like enums (when there is no associated data, e.g. `enum
Color {Red, Blue, Green}`), effectively setting the size of the enum to the size
of the provided type. Such an enum can be cast to a value of the same type as
well. In short, `#[repr(u8)]` makes the enum behave like an integer with a
constrained set of allowed values.
Only C-like enums can be cast to numerical primitives, so this attribute will
not apply to structs.
`#[repr(packed)]` reduces padding to make the struct size smaller. The
representation of enums isn't strictly defined in Rust, and this attribute won't
work on enums.
`#[repr(simd)]` will give a struct consisting of a homogenous series of machine
types (i.e. `u8`, `i32`, etc) a representation that permits vectorization via
SIMD. This doesn't make much sense for enums since they don't consist of a
single list of data.
"##
,
E0518
:
r##"
This error indicates that an `#[inline(..)]` attribute was incorrectly placed on
something other than a function or method.
Examples of erroneous code:
```
#[inline(always)]
struct Foo;
#[inline(never)]
impl Foo {
...
}
```
`#[inline]` hints the compiler whether or not to attempt to inline a method or
function. By default, the compiler does a pretty good job of figuring this out
itself, but if you feel the need for annotations, `#[inline(always)]` and
`#[inline(never)]` can override or force the compiler's decision.
If you wish to apply this attribute to all methods in an impl, manually annotate
each method; it is not possible to annotate the entire impl with an `#[inline]`
attribute.
"##
,
}
...
...
src/librustc/front/check_attr.rs
浏览文件 @
92df8a9a
...
...
@@ -41,9 +41,7 @@ struct CheckAttrVisitor<'a> {
impl
<
'a
>
CheckAttrVisitor
<
'a
>
{
fn
check_inline
(
&
self
,
attr
:
&
ast
::
Attribute
,
target
:
Target
)
{
if
target
!=
Target
::
Fn
{
self
.sess
.span_err
(
attr
.span
,
"attribute should be applied to function"
);
span_err!
(
self
.sess
,
attr
.span
,
E0518
,
"attribute should be applied to function"
);
}
}
...
...
@@ -56,33 +54,34 @@ fn check_repr(&self, attr: &ast::Attribute, target: Target) {
};
for
word
in
words
{
let
word
:
&
str
=
&
word
.name
();
match
word
{
let
message
=
match
word
{
"C"
=>
{
if
target
!=
Target
::
Struct
&&
target
!=
Target
::
Enum
{
self
.sess
.span_err
(
attr
.span
,
"attribute should be applied to struct or enum"
);
"attribute should be applied to struct or enum"
}
else
{
continue
}
}
"packed"
|
"simd"
=>
{
if
target
!=
Target
::
Struct
{
self
.sess
.span_err
(
attr
.span
,
"attribute should be applied to struct"
);
"attribute should be applied to struct"
}
else
{
continue
}
}
"i8"
|
"u8"
|
"i16"
|
"u16"
|
"i32"
|
"u32"
|
"i64"
|
"u64"
|
"isize"
|
"usize"
=>
{
if
target
!=
Target
::
Enum
{
self
.sess
.span_err
(
attr
.span
,
"attribute should be applied to enum"
);
"attribute should be applied to enum"
}
else
{
continue
}
}
_
=>
(),
}
_
=>
continue
,
};
span_err!
(
self
.sess
,
attr
.span
,
E0517
,
"{}"
,
message
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录