Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a2f21790
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
a2f21790
编写于
3月 26, 2021
作者:
O
Oli Scherer
提交者:
Felix S. Klock II
4月 20, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add an attribute to be able to configure the limit
上级
e9696c8b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
65 addition
and
11 deletion
+65
-11
compiler/rustc_feature/src/active.rs
compiler/rustc_feature/src/active.rs
+3
-0
compiler/rustc_feature/src/builtin_attrs.rs
compiler/rustc_feature/src/builtin_attrs.rs
+4
-0
compiler/rustc_lint_defs/src/builtin.rs
compiler/rustc_lint_defs/src/builtin.rs
+1
-1
compiler/rustc_middle/src/middle/limits.rs
compiler/rustc_middle/src/middle/limits.rs
+10
-5
compiler/rustc_mir/src/monomorphize/collector.rs
compiler/rustc_mir/src/monomorphize/collector.rs
+6
-1
compiler/rustc_session/src/session.rs
compiler/rustc_session/src/session.rs
+16
-0
compiler/rustc_span/src/symbol.rs
compiler/rustc_span/src/symbol.rs
+2
-0
src/test/ui/async-await/large_moves.rs
src/test/ui/async-await/large_moves.rs
+2
-0
src/test/ui/async-await/large_moves.stderr
src/test/ui/async-await/large_moves.stderr
+4
-4
src/test/ui/feature-gates/feature-gate-large-assignments.rs
src/test/ui/feature-gates/feature-gate-large-assignments.rs
+5
-0
src/test/ui/feature-gates/feature-gate-large-assignments.stderr
...st/ui/feature-gates/feature-gate-large-assignments.stderr
+12
-0
未找到文件。
compiler/rustc_feature/src/active.rs
浏览文件 @
a2f21790
...
...
@@ -633,6 +633,9 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// Allows associated types in inherent impls.
(
active
,
inherent_associated_types
,
"1.52.0"
,
Some
(
8995
),
None
),
// Allows setting the threshold for the `large_assignments` lint.
(
active
,
large_assignments
,
"1.52.0"
,
Some
(
83518
),
None
),
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
(
active
,
c_unwind
,
"1.52.0"
,
Some
(
74990
),
None
),
...
...
compiler/rustc_feature/src/builtin_attrs.rs
浏览文件 @
a2f21790
...
...
@@ -241,6 +241,10 @@ pub struct AttributeTemplate {
const_eval_limit
,
CrateLevel
,
template!
(
NameValueStr
:
"N"
),
const_eval_limit
,
experimental!
(
const_eval_limit
)
),
gated!
(
move_size_limit
,
CrateLevel
,
template!
(
NameValueStr
:
"N"
),
large_assignments
,
experimental!
(
move_size_limit
)
),
// Entry point:
ungated!
(
main
,
Normal
,
template!
(
Word
)),
...
...
compiler/rustc_lint_defs/src/builtin.rs
浏览文件 @
a2f21790
...
...
@@ -2906,7 +2906,7 @@
/// This lint will trigger on all sites of large moves and thus allow the
/// user to resolve them in code.
pub
LARGE_ASSIGNMENTS
,
Allow
,
Warn
,
"detects large moves or copies"
,
}
...
...
compiler/rustc_middle/src/middle/limits.rs
浏览文件 @
a2f21790
//! Registering limits, recursion_limit, type_length_limit and const_eval_limit
//! Registering limits:
//! * recursion_limit,
//! * move_size_limit,
//! * type_length_limit, and
//! * const_eval_limit
//!
//! There are various parts of the compiler that must impose arbitrary limits
//! on how deeply they recurse to prevent stack overflow. Users can override
...
...
@@ -8,13 +12,14 @@
use
crate
::
bug
;
use
rustc_ast
as
ast
;
use
rustc_data_structures
::
sync
::
OnceCell
;
use
rustc_session
::
{
Limit
,
Session
}
;
use
rustc_session
::
Session
;
use
rustc_span
::
symbol
::{
sym
,
Symbol
};
use
std
::
num
::
IntErrorKind
;
pub
fn
update_limits
(
sess
:
&
Session
,
krate
:
&
ast
::
Crate
)
{
update_limit
(
sess
,
krate
,
&
sess
.recursion_limit
,
sym
::
recursion_limit
,
128
);
update_limit
(
sess
,
krate
,
&
sess
.move_size_limit
,
sym
::
move_size_limit
,
0
);
update_limit
(
sess
,
krate
,
&
sess
.type_length_limit
,
sym
::
type_length_limit
,
1048576
);
update_limit
(
sess
,
krate
,
&
sess
.const_eval_limit
,
sym
::
const_eval_limit
,
1_000_000
);
}
...
...
@@ -22,7 +27,7 @@ pub fn update_limits(sess: &Session, krate: &ast::Crate) {
fn
update_limit
(
sess
:
&
Session
,
krate
:
&
ast
::
Crate
,
limit
:
&
OnceCell
<
Limit
>
,
limit
:
&
OnceCell
<
impl
From
<
usize
>
+
std
::
fmt
::
Debug
>
,
name
:
Symbol
,
default
:
usize
,
)
{
...
...
@@ -34,7 +39,7 @@ fn update_limit(
if
let
Some
(
s
)
=
attr
.value_str
()
{
match
s
.as_str
()
.parse
()
{
Ok
(
n
)
=>
{
limit
.set
(
Limit
::
new
(
n
))
.unwrap
();
limit
.set
(
From
::
from
(
n
))
.unwrap
();
return
;
}
Err
(
e
)
=>
{
...
...
@@ -63,5 +68,5 @@ fn update_limit(
}
}
}
limit
.set
(
Limit
::
new
(
default
))
.unwrap
();
limit
.set
(
From
::
from
(
default
))
.unwrap
();
}
compiler/rustc_mir/src/monomorphize/collector.rs
浏览文件 @
a2f21790
...
...
@@ -757,11 +757,16 @@ fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Loc
fn
visit_operand
(
&
mut
self
,
operand
:
&
mir
::
Operand
<
'tcx
>
,
location
:
Location
)
{
self
.super_operand
(
operand
,
location
);
let
limit
=
self
.tcx.sess
.move_size_limit
();
if
limit
==
0
{
return
;
}
let
limit
=
Size
::
from_bytes
(
limit
);
let
ty
=
operand
.ty
(
self
.body
,
self
.tcx
);
let
ty
=
self
.monomorphize
(
ty
);
let
layout
=
self
.tcx
.layout_of
(
ty
::
ParamEnv
::
reveal_all
()
.and
(
ty
));
if
let
Ok
(
layout
)
=
layout
{
if
layout
.size
>
Size
::
from_bytes
(
1000
)
{
if
layout
.size
>
limit
{
debug!
(
?
layout
);
let
source_info
=
self
.body
.source_info
(
location
);
debug!
(
?
source_info
);
...
...
compiler/rustc_session/src/session.rs
浏览文件 @
a2f21790
...
...
@@ -83,6 +83,12 @@ pub fn value_within_limit(&self, value: usize) -> bool {
}
}
impl
From
<
usize
>
for
Limit
{
fn
from
(
value
:
usize
)
->
Self
{
Self
::
new
(
value
)
}
}
impl
fmt
::
Display
for
Limit
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
write!
(
f
,
"{}"
,
self
.0
)
...
...
@@ -143,6 +149,10 @@ pub struct Session {
/// operations such as auto-dereference and monomorphization.
pub
recursion_limit
:
OnceCell
<
Limit
>
,
/// The size at which the `large_assignments` lint starts
/// being emitted.
pub
move_size_limit
:
OnceCell
<
usize
>
,
/// The maximum length of types during monomorphization.
pub
type_length_limit
:
OnceCell
<
Limit
>
,
...
...
@@ -352,6 +362,11 @@ pub fn recursion_limit(&self) -> Limit {
self
.recursion_limit
.get
()
.copied
()
.unwrap
()
}
#[inline]
pub
fn
move_size_limit
(
&
self
)
->
usize
{
self
.move_size_limit
.get
()
.copied
()
.unwrap
()
}
#[inline]
pub
fn
type_length_limit
(
&
self
)
->
Limit
{
self
.type_length_limit
.get
()
.copied
()
.unwrap
()
...
...
@@ -1414,6 +1429,7 @@ pub fn build_session(
features
:
OnceCell
::
new
(),
lint_store
:
OnceCell
::
new
(),
recursion_limit
:
OnceCell
::
new
(),
move_size_limit
:
OnceCell
::
new
(),
type_length_limit
:
OnceCell
::
new
(),
const_eval_limit
:
OnceCell
::
new
(),
incr_comp_session
:
OneThread
::
new
(
RefCell
::
new
(
IncrCompSession
::
NotInitialized
)),
...
...
compiler/rustc_span/src/symbol.rs
浏览文件 @
a2f21790
...
...
@@ -669,6 +669,7 @@
label_break_value
,
lang
,
lang_items
,
large_assignments
,
lateout
,
lazy_normalization_consts
,
le
,
...
...
@@ -749,6 +750,7 @@
more_struct_aliases
,
movbe_target_feature
,
move_ref_pattern
,
move_size_limit
,
mul
,
mul_assign
,
mul_with_overflow
,
...
...
src/test/ui/async-await/large_moves.rs
浏览文件 @
a2f21790
#![deny(large_assignments)]
#![feature(large_assignments)]
#![move_size_limit
=
"1000"
]
// build-fail
// edition:2018
...
...
src/test/ui/async-await/large_moves.stderr
浏览文件 @
a2f21790
error: moving 10024 bytes
--> $DIR/large_moves.rs:
7
:13
--> $DIR/large_moves.rs:
9
:13
|
LL | let x = async {
| _____________^
...
...
@@ -17,19 +17,19 @@ LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^
error: moving 10024 bytes
--> $DIR/large_moves.rs:1
3
:14
--> $DIR/large_moves.rs:1
5
:14
|
LL | let z = (x, 42);
| ^ value moved from here
error: moving 10024 bytes
--> $DIR/large_moves.rs:1
3
:13
--> $DIR/large_moves.rs:1
5
:13
|
LL | let z = (x, 42);
| ^^^^^^^ value moved from here
error: moving 10024 bytes
--> $DIR/large_moves.rs:1
5
:13
--> $DIR/large_moves.rs:1
7
:13
|
LL | let a = z.0;
| ^^^ value moved from here
...
...
src/test/ui/feature-gates/feature-gate-large-assignments.rs
0 → 100644
浏览文件 @
a2f21790
// check that `move_size_limit is feature-gated
#![move_size_limit
=
"42"
]
//~ ERROR the `#[move_size_limit]` attribute is an experimental feature
fn
main
()
{}
src/test/ui/feature-gates/feature-gate-large-assignments.stderr
0 → 100644
浏览文件 @
a2f21790
error[E0658]: the `#[move_size_limit]` attribute is an experimental feature
--> $DIR/feature-gate-large-assignments.rs:3:1
|
LL | #![move_size_limit = "42"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #83518 <https://github.com/rust-lang/rust/issues/83518> for more information
= help: add `#![feature(large_assignments)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录