Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
349d53c2
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,发现更多精彩内容 >>
提交
349d53c2
编写于
5月 29, 2018
作者:
A
Alexander Regueiro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added miri error for evaluating foreign statics.
Updated tests accordingly.
上级
13931762
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
27 addition
and
23 deletion
+27
-23
src/librustc/ich/impls_ty.rs
src/librustc/ich/impls_ty.rs
+1
-0
src/librustc/mir/interpret/error.rs
src/librustc/mir/interpret/error.rs
+3
-0
src/librustc/ty/structural_impls.rs
src/librustc/ty/structural_impls.rs
+1
-0
src/librustc_mir/interpret/const_eval.rs
src/librustc_mir/interpret/const_eval.rs
+2
-2
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/memory.rs
+3
-0
src/test/compile-fail/const-fn-not-safe-for-const.rs
src/test/compile-fail/const-fn-not-safe-for-const.rs
+1
-3
src/test/compile-fail/issue-14227.rs
src/test/compile-fail/issue-14227.rs
+2
-1
src/test/compile-fail/issue-17718-references.rs
src/test/compile-fail/issue-17718-references.rs
+3
-4
src/test/compile-fail/issue-28324.rs
src/test/compile-fail/issue-28324.rs
+1
-1
src/test/compile-fail/thread-local-in-ctfe.rs
src/test/compile-fail/thread-local-in-ctfe.rs
+0
-3
src/test/run-pass/issue-17450.rs
src/test/run-pass/issue-17450.rs
+1
-4
src/test/run-pass/issue-17718-borrow-interior.rs
src/test/run-pass/issue-17718-borrow-interior.rs
+8
-2
src/test/run-pass/issue-34194.rs
src/test/run-pass/issue-34194.rs
+0
-1
src/test/run-pass/issue-6991.rs
src/test/run-pass/issue-6991.rs
+1
-2
未找到文件。
src/librustc/ich/impls_ty.rs
浏览文件 @
349d53c2
...
...
@@ -521,6 +521,7 @@ fn hash_stable<W: StableHasherResult>(&self,
InvalidNullPointerUsage
|
ReadPointerAsBytes
|
ReadBytesAsPointer
|
ReadForeignStatic
|
InvalidPointerMath
|
ReadUndefBytes
|
DeadLocal
|
...
...
src/librustc/mir/interpret/error.rs
浏览文件 @
349d53c2
...
...
@@ -188,6 +188,7 @@ pub enum EvalErrorKind<'tcx, O> {
InvalidNullPointerUsage
,
ReadPointerAsBytes
,
ReadBytesAsPointer
,
ReadForeignStatic
,
InvalidPointerMath
,
ReadUndefBytes
,
DeadLocal
,
...
...
@@ -304,6 +305,8 @@ pub fn description(&self) -> &str {
"a raw memory access tried to access part of a pointer value as raw bytes"
,
ReadBytesAsPointer
=>
"a memory access tried to interpret some bytes as a pointer"
,
ReadForeignStatic
=>
"tried to read foreign (extern) static"
,
InvalidPointerMath
=>
"attempted to do invalid arithmetic on pointers that would leak base addresses, e.g. comparing pointers into different allocations"
,
ReadUndefBytes
=>
...
...
src/librustc/ty/structural_impls.rs
浏览文件 @
349d53c2
...
...
@@ -506,6 +506,7 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
InvalidNullPointerUsage
=>
InvalidNullPointerUsage
,
ReadPointerAsBytes
=>
ReadPointerAsBytes
,
ReadBytesAsPointer
=>
ReadBytesAsPointer
,
ReadForeignStatic
=>
ReadForeignStatic
,
InvalidPointerMath
=>
InvalidPointerMath
,
ReadUndefBytes
=>
ReadUndefBytes
,
DeadLocal
=>
DeadLocal
,
...
...
src/librustc_mir/interpret/const_eval.rs
浏览文件 @
349d53c2
...
...
@@ -374,7 +374,7 @@ fn try_ptr_op<'a>(
Ok
(
None
)
}
else
{
Err
(
ConstEvalError
::
NeedsRfc
(
"
P
ointer arithmetic or comparison"
.to_string
())
.into
(),
ConstEvalError
::
NeedsRfc
(
"
p
ointer arithmetic or comparison"
.to_string
())
.into
(),
)
}
}
...
...
@@ -404,7 +404,7 @@ fn box_alloc<'a>(
_
dest
:
Place
,
)
->
EvalResult
<
'tcx
>
{
Err
(
ConstEvalError
::
NeedsRfc
(
"
H
eap allocations via `box` keyword"
.to_string
())
.into
(),
ConstEvalError
::
NeedsRfc
(
"
h
eap allocations via `box` keyword"
.to_string
())
.into
(),
)
}
...
...
src/librustc_mir/interpret/memory.rs
浏览文件 @
349d53c2
...
...
@@ -279,6 +279,9 @@ pub fn check_bounds(&self, ptr: Pointer, access: bool) -> EvalResult<'tcx> {
/// Allocation accessors
impl
<
'a
,
'mir
,
'tcx
,
M
:
Machine
<
'mir
,
'tcx
>>
Memory
<
'a
,
'mir
,
'tcx
,
M
>
{
fn
const_eval_static
(
&
self
,
def_id
:
DefId
)
->
EvalResult
<
'tcx
,
&
'tcx
Allocation
>
{
if
self
.tcx
.is_foreign_item
(
def_id
)
{
return
err!
(
ReadForeignStatic
);
}
let
instance
=
Instance
::
mono
(
self
.tcx.tcx
,
def_id
);
let
gid
=
GlobalId
{
instance
,
...
...
src/test/compile-fail/const-fn-not-safe-for-const.rs
浏览文件 @
349d53c2
...
...
@@ -29,7 +29,6 @@ const fn sub1() -> u32 {
const
fn
get_Y
()
->
u32
{
Y
//~^ ERROR E0013
//~| ERROR cannot refer to statics by value
}
const
fn
get_Y_addr
()
->
&
'static
u32
{
...
...
@@ -49,5 +48,4 @@ const fn get() -> u32 {
//~| ERROR let bindings in constant functions are unstable
}
fn
main
()
{
}
fn
main
()
{}
src/test/compile-fail/issue-14227.rs
浏览文件 @
349d53c2
...
...
@@ -13,6 +13,7 @@
extern
{
pub
static
symbol
:
();
}
static
CRASH
:
()
=
symbol
;
//~ cannot refer to other statics by value
static
CRASH
:
()
=
symbol
;
//~^ ERROR constant evaluation error
fn
main
()
{}
src/test/compile-fail/issue-17718-references.rs
浏览文件 @
349d53c2
...
...
@@ -22,14 +22,13 @@ struct Struct { a: usize }
const
T5
:
usize
=
C
;
const
T6
:
usize
=
S
;
//~ ERROR: constants cannot refer to statics
//~^ cannot refer to statics
static
T7
:
usize
=
C
;
static
T8
:
usize
=
S
;
//~ ERROR: cannot refer to other statics by value
static
T8
:
usize
=
S
;
const
T9
:
Struct
=
Struct
{
a
:
C
};
const
T10
:
Struct
=
Struct
{
a
:
S
};
//~ ERROR: cannot refer to statics by value
const
T10
:
Struct
=
Struct
{
a
:
S
};
//~^ ERROR: constants cannot refer to statics
static
T11
:
Struct
=
Struct
{
a
:
C
};
static
T12
:
Struct
=
Struct
{
a
:
S
};
//~ ERROR: cannot refer to other statics by value
static
T12
:
Struct
=
Struct
{
a
:
S
};
fn
main
()
{}
src/test/compile-fail/issue-28324.rs
浏览文件 @
349d53c2
...
...
@@ -15,6 +15,6 @@
}
pub
static
BAZ
:
u32
=
*&
error_message_count
;
//~^ ERROR c
annot refer to other statics by value
//~^ ERROR c
onstant evaluation error
fn
main
()
{}
src/test/compile-fail/thread-local-in-ctfe.rs
浏览文件 @
349d53c2
...
...
@@ -15,14 +15,12 @@
static
B
:
u32
=
A
;
//~^ ERROR thread-local statics cannot be accessed at compile-time
//~| ERROR cannot refer to other statics by value
static
C
:
&
u32
=
&
A
;
//~^ ERROR thread-local statics cannot be accessed at compile-time
const
D
:
u32
=
A
;
//~^ ERROR thread-local statics cannot be accessed at compile-time
//~| ERROR cannot refer to statics by value
const
E
:
&
u32
=
&
A
;
//~^ ERROR thread-local statics cannot be accessed at compile-time
...
...
@@ -30,7 +28,6 @@
const
fn
f
()
->
u32
{
A
//~^ ERROR thread-local statics cannot be accessed at compile-time
//~| ERROR cannot refer to statics by value
}
fn
main
()
{}
src/test/
compile-fail
/issue-17450.rs
→
src/test/
run-pass
/issue-17450.rs
浏览文件 @
349d53c2
...
...
@@ -11,9 +11,6 @@
#![allow(dead_code,
warnings)]
static
mut
x
:
isize
=
3
;
static
mut
y
:
isize
=
unsafe
{
x
//~^ ERROR cannot refer to other statics by value, use the address-of operator or a constant instea
};
static
mut
y
:
isize
=
unsafe
{
x
};
fn
main
()
{}
src/test/run-pass/issue-17718-borrow-interior.rs
浏览文件 @
349d53c2
...
...
@@ -10,7 +10,7 @@
struct
S
{
a
:
usize
}
static
A
:
S
=
S
{
a
:
3
};
static
A
:
S
=
S
{
a
:
3
};
static
B
:
&
'static
usize
=
&
A
.a
;
static
C
:
&
'static
usize
=
&
(
A
.a
);
...
...
@@ -18,4 +18,10 @@ struct S { a: usize }
static
E
:
usize
=
D
[
0
];
static
F
:
&
'static
usize
=
&
D
[
0
];
fn
main
()
{}
fn
main
()
{
assert_eq!
(
*
B
,
A
.a
);
assert_eq!
(
*
B
,
A
.a
);
assert_eq!
(
E
,
D
[
0
]);
assert_eq!
(
*
F
,
D
[
0
]);
}
src/test/
compile-fail
/issue-34194.rs
→
src/test/
run-pass
/issue-34194.rs
浏览文件 @
349d53c2
...
...
@@ -16,6 +16,5 @@ struct A {
static
B
:
&
'static
A
=
&
A
{
a
:
&
()
};
static
C
:
&
'static
A
=
&
B
;
//~^ ERROR cannot refer to other statics by value
fn
main
()
{}
src/test/
compile-fail
/issue-6991.rs
→
src/test/
run-pass
/issue-6991.rs
浏览文件 @
349d53c2
...
...
@@ -10,6 +10,5 @@
static
x
:
&
'static
usize
=
&
1
;
static
y
:
usize
=
*
x
;
//~^ ERROR cannot refer to other statics by value,
// use the address-of operator or a constant instead
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录