Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f97f2a47
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,发现更多精彩内容 >>
提交
f97f2a47
编写于
6月 28, 2022
作者:
M
Michael Goulet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate MutDeref, TransientMutBorrow diagnostics
上级
584e5d4c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
19 deletion
+69
-19
compiler/rustc_const_eval/src/errors.rs
compiler/rustc_const_eval/src/errors.rs
+24
-0
compiler/rustc_const_eval/src/transform/check_consts/ops.rs
compiler/rustc_const_eval/src/transform/check_consts/ops.rs
+16
-18
compiler/rustc_error_messages/locales/en-US/const_eval.ftl
compiler/rustc_error_messages/locales/en-US/const_eval.ftl
+19
-0
compiler/rustc_session/src/session.rs
compiler/rustc_session/src/session.rs
+10
-1
未找到文件。
compiler/rustc_const_eval/src/errors.rs
浏览文件 @
f97f2a47
...
...
@@ -63,3 +63,27 @@ pub(crate) struct PanicNonStrErr {
#[primary_span]
pub
span
:
Span
,
}
#[derive(SessionDiagnostic)]
#[error(const_eval::mut_deref,
code
=
"E0658"
)]
pub
(
crate
)
struct
MutDerefErr
{
#[primary_span]
pub
span
:
Span
,
pub
kind
:
ConstContext
,
}
#[derive(SessionDiagnostic)]
#[error(const_eval::transient_mut_borrow,
code
=
"E0658"
)]
pub
(
crate
)
struct
TransientMutBorrowErr
{
#[primary_span]
pub
span
:
Span
,
pub
kind
:
ConstContext
,
}
#[derive(SessionDiagnostic)]
#[error(const_eval::transient_mut_borrow_raw,
code
=
"E0658"
)]
pub
(
crate
)
struct
TransientMutBorrowErrRaw
{
#[primary_span]
pub
span
:
Span
,
pub
kind
:
ConstContext
,
}
compiler/rustc_const_eval/src/transform/check_consts/ops.rs
浏览文件 @
f97f2a47
...
...
@@ -23,7 +23,8 @@
use
super
::
ConstCx
;
use
crate
::
errors
::{
NonConstOpErr
,
PanicNonStrErr
,
RawPtrComparisonErr
,
RawPtrToIntErr
,
StaticAccessErr
,
MutDerefErr
,
NonConstOpErr
,
PanicNonStrErr
,
RawPtrComparisonErr
,
RawPtrToIntErr
,
StaticAccessErr
,
TransientMutBorrowErr
,
TransientMutBorrowErrRaw
,
};
use
crate
::
util
::{
call_kind
,
CallDesugaringKind
,
CallKind
};
...
...
@@ -595,17 +596,17 @@ fn build_error(
ccx
:
&
ConstCx
<
'_
,
'tcx
>
,
span
:
Span
,
)
->
DiagnosticBuilder
<
'tcx
,
ErrorGuaranteed
>
{
let
raw
=
match
self
.0
{
hir
::
BorrowKind
::
Raw
=>
"raw "
,
hir
::
BorrowKind
::
R
ef
=>
""
,
};
feature_err
(
&
ccx
.tcx.sess.parse_sess
,
sym
::
const_mut_refs
,
span
,
&
format!
(
"{}mutable references are not allowed in {}s"
,
raw
,
ccx
.const_kind
()
),
)
let
kind
=
ccx
.const_kind
();
match
self
.0
{
hir
::
BorrowKind
::
R
aw
=>
ccx
.tcx
.sess
.create_feature_err
(
TransientMutBorrowErrRaw
{
span
,
kind
},
sym
::
const_mut_refs
),
hir
::
BorrowKind
::
Ref
=>
ccx
.tcx
.sess
.create_feature_err
(
TransientMutBorrowErr
{
span
,
kind
},
sym
::
const_mut_refs
),
}
}
}
...
...
@@ -626,12 +627,9 @@ fn build_error(
ccx
:
&
ConstCx
<
'_
,
'tcx
>
,
span
:
Span
,
)
->
DiagnosticBuilder
<
'tcx
,
ErrorGuaranteed
>
{
feature_err
(
&
ccx
.tcx.sess.parse_sess
,
sym
::
const_mut_refs
,
span
,
&
format!
(
"mutation through a reference is not allowed in {}s"
,
ccx
.const_kind
()),
)
ccx
.tcx
.sess
.create_feature_err
(
MutDerefErr
{
span
,
kind
:
ccx
.const_kind
()
},
sym
::
const_mut_refs
)
}
}
...
...
compiler/rustc_error_messages/locales/en-US/const_eval.ftl
浏览文件 @
f97f2a47
...
...
@@ -26,3 +26,22 @@ const-eval-raw-ptr-comparison =
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
const-eval-panic-non-str = argument to `panic!()` in a const context must have type `&str`
const-eval-mut-deref =
mutation through a reference is not allowed in { $kind ->
[constant function] constant functions
[static] statics
*[constant] constants
}
const-eval-transient-mut-borrow = mutable references are not allowed in { $kind ->
[constant function] constant functions
[static] statics
*[constant] constants
}
const-eval-transient-mut-borrow-raw = raw mutable references are not allowed in { $kind ->
[constant function] constant functions
[static] statics
*[constant] constants
}
compiler/rustc_session/src/session.rs
浏览文件 @
f97f2a47
...
...
@@ -2,7 +2,7 @@
use
crate
::
code_stats
::
CodeStats
;
pub
use
crate
::
code_stats
::{
DataTypeKind
,
FieldInfo
,
SizeKind
,
VariantInfo
};
use
crate
::
config
::{
self
,
CrateType
,
OutputType
,
SwitchWithOptPath
};
use
crate
::
parse
::
ParseSess
;
use
crate
::
parse
::
{
add_feature_diagnostics
,
ParseSess
}
;
use
crate
::
search_paths
::{
PathKind
,
SearchPath
};
use
crate
::{
filesearch
,
lint
};
...
...
@@ -458,6 +458,15 @@ pub fn create_err<'a>(
)
->
DiagnosticBuilder
<
'a
,
ErrorGuaranteed
>
{
self
.parse_sess
.create_err
(
err
)
}
pub
fn
create_feature_err
<
'a
>
(
&
'a
self
,
err
:
impl
SessionDiagnostic
<
'a
>
,
feature
:
Symbol
,
)
->
DiagnosticBuilder
<
'a
,
ErrorGuaranteed
>
{
let
mut
err
=
self
.parse_sess
.create_err
(
err
);
add_feature_diagnostics
(
&
mut
err
,
&
self
.parse_sess
,
feature
);
err
}
pub
fn
emit_err
<
'a
>
(
&
'a
self
,
err
:
impl
SessionDiagnostic
<
'a
>
)
->
ErrorGuaranteed
{
self
.parse_sess
.emit_err
(
err
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录