Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
57445567
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,发现更多精彩内容 >>
提交
57445567
编写于
3月 23, 2014
作者:
M
Michael Darakananda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added lint for #[deriving] structs and enums with unsafe pointers. #13032.
上级
c83994e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
0 deletion
+77
-0
src/librustc/middle/lint.rs
src/librustc/middle/lint.rs
+41
-0
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+1
-0
src/test/compile-fail/lint-raw-ptr-deriving.rs
src/test/compile-fail/lint-raw-ptr-deriving.rs
+35
-0
未找到文件。
src/librustc/middle/lint.rs
浏览文件 @
57445567
...
...
@@ -115,6 +115,8 @@ pub enum Lint {
DeprecatedOwnedVector
,
Warnings
,
RawPointerDeriving
,
}
pub
fn
level_to_str
(
lv
:
level
)
->
&
'static
str
{
...
...
@@ -406,6 +408,13 @@ enum LintSource {
desc
:
"use of a `~[T]` vector"
,
default
:
allow
,
}),
(
"raw_pointer_deriving"
,
LintSpec
{
lint
:
RawPointerDeriving
,
desc
:
"uses of #[deriving] with raw pointers are rarely correct"
,
default
:
warn
,
}),
];
/*
...
...
@@ -959,6 +968,37 @@ fn check_heap_item(cx: &Context, it: &ast::Item) {
}
}
struct
RawPtrDerivingVisitor
<
'a
>
{
cx
:
&
'a
Context
<
'a
>
}
impl
<
'a
>
Visitor
<
()
>
for
RawPtrDerivingVisitor
<
'a
>
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
ast
::
Ty
,
_
:
())
{
static
MSG
:
&
'static
str
=
"use of `#[deriving]` with a raw pointer"
;
match
ty
.node
{
ast
::
TyPtr
(
..
)
=>
self
.cx
.span_lint
(
RawPointerDeriving
,
ty
.span
,
MSG
),
_
=>
{}
}
visit
::
walk_ty
(
self
,
ty
,
());
}
// explicit override to a no-op to reduce code bloat
fn
visit_expr
(
&
mut
self
,
_
:
&
ast
::
Expr
,
_
:
())
{}
fn
visit_block
(
&
mut
self
,
_
:
&
ast
::
Block
,
_
:
())
{}
}
fn
check_raw_ptr_deriving
(
cx
:
&
Context
,
item
:
&
ast
::
Item
)
{
if
!
attr
::
contains_name
(
item
.attrs
.as_slice
(),
"deriving"
)
{
return
}
match
item
.node
{
ast
::
ItemStruct
(
..
)
|
ast
::
ItemEnum
(
..
)
=>
{
let
mut
visitor
=
RawPtrDerivingVisitor
{
cx
:
cx
};
visit
::
walk_item
(
&
mut
visitor
,
item
,
());
}
_
=>
{}
}
}
static
crate_attrs
:
&
'static
[
&
'static
str
]
=
&
[
"crate_type"
,
"feature"
,
"no_start"
,
"no_main"
,
"no_std"
,
"crate_id"
,
"desc"
,
"comment"
,
"license"
,
"copyright"
,
// not used in rustc now
...
...
@@ -1585,6 +1625,7 @@ fn visit_item(&mut self, it: &ast::Item, _: ()) {
check_heap_item
(
cx
,
it
);
check_missing_doc_item
(
cx
,
it
);
check_attrs_usage
(
cx
,
it
.attrs
.as_slice
());
check_raw_ptr_deriving
(
cx
,
it
);
cx
.visit_ids
(|
v
|
v
.visit_item
(
it
,
()));
...
...
src/librustc/middle/ty.rs
浏览文件 @
57445567
...
...
@@ -384,6 +384,7 @@ pub struct t_box_ {
// alive, and using ty::get is unsafe when the ctxt is no longer alive.
enum
t_opaque
{}
#[allow(raw_pointer_deriving)]
#[deriving(Clone,
Eq,
TotalEq,
Hash)]
pub
struct
t
{
priv
inner
:
*
t_opaque
}
...
...
src/test/compile-fail/lint-raw-ptr-deriving.rs
0 → 100644
浏览文件 @
57445567
// Copyright 2013 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(struct_variant)]
;
#[allow(dead_code)]
;
#[deny(raw_pointer_deriving)]
;
#[deriving(Clone)]
struct
Foo
{
x
:
*
int
//~ ERROR use of `#[deriving]` with a raw pointer
}
#[deriving(Clone)]
struct
Bar
(
*
mut
int
);
//~ ERROR use of `#[deriving]` with a raw pointer
#[deriving(Clone)]
enum
Baz
{
A
(
*
int
),
//~ ERROR use of `#[deriving]` with a raw pointer
B
{
x
:
*
mut
int
}
//~ ERROR use of `#[deriving]` with a raw pointer
}
#[deriving(Clone)]
struct
Buzz
{
x
:
(
*
int
,
//~ ERROR use of `#[deriving]` with a raw pointer
*
uint
)
//~ ERROR use of `#[deriving]` with a raw pointer
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录