Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
74f3a965
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,发现更多精彩内容 >>
提交
74f3a965
编写于
6月 22, 2022
作者:
D
David Wood
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
privacy: port "in public interface" diag
Signed-off-by:
N
David Wood
<
david.wood@huawei.com
>
上级
0557d02a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
12 deletion
+60
-12
compiler/rustc_error_messages/locales/en-US/privacy.ftl
compiler/rustc_error_messages/locales/en-US/privacy.ftl
+4
-0
compiler/rustc_privacy/src/errors.rs
compiler/rustc_privacy/src/errors.rs
+28
-0
compiler/rustc_privacy/src/lib.rs
compiler/rustc_privacy/src/lib.rs
+28
-12
未找到文件。
compiler/rustc_error_messages/locales/en-US/privacy.ftl
浏览文件 @
74f3a965
...
...
@@ -6,3 +6,7 @@ privacy-item-is-private = {$kind} `{$descr}` is private
.label = private {$kind}
privacy-unnamed-item-is-private = {$kind} is private
.label = private {$kind}
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
.label = can't leak {$vis_descr} {$kind}
.visibility-label = `{$descr}` declared as {$vis_descr}
compiler/rustc_privacy/src/errors.rs
浏览文件 @
74f3a965
...
...
@@ -45,3 +45,31 @@ pub struct UnnamedItemIsPrivate {
pub
span
:
Span
,
pub
kind
:
&
'static
str
,
}
// Duplicate of `InPublicInterface` but with a different error code, shares the same slug.
#[derive(SessionDiagnostic)]
#[error(privacy::in_public_interface,
code
=
"E0445"
)]
pub
struct
InPublicInterfaceTraits
<
'a
>
{
#[primary_span]
#[label]
pub
span
:
Span
,
pub
vis_descr
:
&
'static
str
,
pub
kind
:
&
'a
str
,
pub
descr
:
String
,
#[label(privacy::visibility_label)]
pub
vis_span
:
Span
,
}
// Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug.
#[derive(SessionDiagnostic)]
#[error(privacy::in_public_interface,
code
=
"E0446"
)]
pub
struct
InPublicInterface
<
'a
>
{
#[primary_span]
#[label]
pub
span
:
Span
,
pub
vis_descr
:
&
'static
str
,
pub
kind
:
&
'a
str
,
pub
descr
:
String
,
#[label(privacy::visibility_label)]
pub
vis_span
:
Span
,
}
compiler/rustc_privacy/src/lib.rs
浏览文件 @
74f3a965
...
...
@@ -11,7 +11,6 @@
use
rustc_attr
as
attr
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_data_structures
::
intern
::
Interned
;
use
rustc_errors
::
struct_span_err
;
use
rustc_hir
as
hir
;
use
rustc_hir
::
def
::{
DefKind
,
Res
};
use
rustc_hir
::
def_id
::{
DefId
,
LocalDefId
,
LocalDefIdSet
,
CRATE_DEF_ID
};
...
...
@@ -36,7 +35,10 @@
use
std
::
ops
::
ControlFlow
;
use
std
::{
cmp
,
fmt
,
mem
};
use
errors
::{
FieldIsPrivate
,
FieldIsPrivateLabel
,
ItemIsPrivate
,
UnnamedItemIsPrivate
};
use
errors
::{
FieldIsPrivate
,
FieldIsPrivateLabel
,
InPublicInterface
,
InPublicInterfaceTraits
,
ItemIsPrivate
,
UnnamedItemIsPrivate
,
};
////////////////////////////////////////////////////////////////////////////////
/// Generic infrastructure used to implement specific visitors below.
...
...
@@ -1748,22 +1750,31 @@ fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display)
}
}
};
let
make_msg
=
||
format!
(
"{} {} `{}` in public interface"
,
vis_descr
,
kind
,
descr
);
let
span
=
self
.tcx
.def_span
(
self
.item_def_id
.to_def_id
());
if
self
.has_old_errors
||
self
.in_assoc_ty
||
self
.tcx
.resolutions
(())
.has_pub_restricted
{
let
mut
err
=
if
kind
==
"trait"
{
struct_span_err!
(
self
.tcx.sess
,
span
,
E0445
,
"{}"
,
make_msg
())
}
else
{
struct_span_err!
(
self
.tcx.sess
,
span
,
E0446
,
"{}"
,
make_msg
())
};
let
descr
=
descr
.to_string
();
let
vis_span
=
self
.tcx.sess
.source_map
()
.guess_head_span
(
self
.tcx
.def_span
(
def_id
));
err
.span_label
(
span
,
format!
(
"can't leak {} {}"
,
vis_descr
,
kind
));
err
.span_label
(
vis_span
,
format!
(
"`{}` declared as {}"
,
descr
,
vis_descr
));
err
.emit
();
if
kind
==
"trait"
{
self
.tcx.sess
.emit_err
(
InPublicInterfaceTraits
{
span
,
vis_descr
,
kind
,
descr
,
vis_span
,
});
}
else
{
self
.tcx.sess
.emit_err
(
InPublicInterface
{
span
,
vis_descr
,
kind
,
descr
,
vis_span
,
});
}
}
else
{
let
err_code
=
if
kind
==
"trait"
{
"E0445"
}
else
{
"E0446"
};
self
.tcx
.struct_span_lint_hir
(
...
...
@@ -1771,7 +1782,12 @@ fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display)
hir_id
,
span
,
|
lint
|
{
lint
.build
(
&
format!
(
"{} (error {})"
,
make_msg
(),
err_code
))
.emit
();
lint
.build
(
&
format!
(
"{} (error {})"
,
format!
(
"{} {} `{}` in public interface"
,
vis_descr
,
kind
,
descr
),
err_code
))
.emit
();
},
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录