Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8b060e25
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,发现更多精彩内容 >>
提交
8b060e25
编写于
1月 20, 2017
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement compatibility lint for legacy constructor visibilities
上级
962d88b5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
2 deletion
+64
-2
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+7
-0
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+4
-0
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+3
-0
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+22
-2
src/test/compile-fail/privacy/legacy-ctor-visibility.rs
src/test/compile-fail/privacy/legacy-ctor-visibility.rs
+28
-0
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
8b060e25
...
...
@@ -223,6 +223,12 @@
"detects names that resolve to ambiguous glob imports with RFC 1560"
}
declare_lint!
{
pub
LEGACY_CONSTRUCTOR_VISIBILITY
,
Deny
,
"detects use of struct constructors that would be invisible with new visibility rules"
}
declare_lint!
{
pub
DEPRECATED
,
Warn
,
...
...
@@ -271,6 +277,7 @@ fn get_lints(&self) -> LintArray {
EXTRA_REQUIREMENT_IN_IMPL
,
LEGACY_DIRECTORY_OWNERSHIP
,
LEGACY_IMPORTS
,
LEGACY_CONSTRUCTOR_VISIBILITY
,
DEPRECATED
)
}
...
...
src/librustc_lint/lib.rs
浏览文件 @
8b060e25
...
...
@@ -240,6 +240,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id
:
LintId
::
of
(
LEGACY_IMPORTS
),
reference
:
"issue #38260 <https://github.com/rust-lang/rust/issues/38260>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
LEGACY_CONSTRUCTOR_VISIBILITY
),
reference
:
"issue #39207 <https://github.com/rust-lang/rust/issues/39207>"
,
},
]);
// Register renamed and removed lints
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
8b060e25
...
...
@@ -345,6 +345,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
let
ctor_def
=
Def
::
StructCtor
(
self
.definitions
.local_def_id
(
struct_def
.id
()),
CtorKind
::
from_ast
(
struct_def
));
self
.define
(
parent
,
ident
,
ValueNS
,
(
ctor_def
,
ctor_vis
,
sp
,
expansion
));
if
!
ctor_vis
.is_at_least
(
vis
,
&*
self
)
{
self
.legacy_ctor_visibilities
.insert
(
def
.def_id
(),
(
ctor_def
,
ctor_vis
));
}
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
8b060e25
...
...
@@ -45,7 +45,7 @@
use
rustc
::
hir
::
def_id
::{
CrateNum
,
CRATE_DEF_INDEX
,
LOCAL_CRATE
,
DefId
};
use
rustc
::
ty
;
use
rustc
::
hir
::{
Freevar
,
FreevarMap
,
TraitCandidate
,
TraitMap
,
GlobMap
};
use
rustc
::
util
::
nodemap
::{
NodeMap
,
NodeSet
,
FxHashMap
,
FxHashSet
};
use
rustc
::
util
::
nodemap
::{
NodeMap
,
NodeSet
,
FxHashMap
,
FxHashSet
,
DefIdMap
};
use
syntax
::
ext
::
hygiene
::{
Mark
,
SyntaxContext
};
use
syntax
::
ast
::{
self
,
Name
,
NodeId
,
Ident
,
SpannedIdent
,
FloatTy
,
IntTy
,
UintTy
};
...
...
@@ -1131,6 +1131,9 @@ pub struct Resolver<'a> {
warned_proc_macros
:
FxHashSet
<
Name
>
,
potentially_unused_imports
:
Vec
<&
'a
ImportDirective
<
'a
>>
,
// Auxiliary map used only for reporting `legacy_constructor_visibility` lint.
legacy_ctor_visibilities
:
DefIdMap
<
(
Def
,
ty
::
Visibility
)
>
,
}
pub
struct
ResolverArenas
<
'a
>
{
...
...
@@ -1310,6 +1313,7 @@ pub fn new(session: &'a Session,
proc_macro_enabled
:
features
.proc_macro
,
warned_proc_macros
:
FxHashSet
(),
potentially_unused_imports
:
Vec
::
new
(),
legacy_ctor_visibilities
:
DefIdMap
(),
}
}
...
...
@@ -2235,7 +2239,23 @@ fn smart_resolve_path_fragment(&mut self,
if
is_expected
(
resolution
.base_def
)
||
resolution
.base_def
==
Def
::
Err
{
resolution
}
else
{
report_errors
(
self
,
Some
(
resolution
.base_def
))
// Add a temporary hack to smooth the transition to new struct ctor
// visibility rules. See #38932 for more details.
let
mut
res
=
None
;
if
let
Def
::
Struct
(
def_id
)
=
resolution
.base_def
{
if
let
Some
((
ctor_def
,
ctor_vis
))
=
self
.legacy_ctor_visibilities
.get
(
&
def_id
)
.cloned
()
{
if
is_expected
(
ctor_def
)
&&
self
.is_accessible
(
ctor_vis
)
{
let
lint
=
lint
::
builtin
::
LEGACY_CONSTRUCTOR_VISIBILITY
;
self
.session
.add_lint
(
lint
,
id
,
span
,
"private struct constructors are not usable through
\
reexports in outer modules"
.to_string
());
res
=
Some
(
PathResolution
::
new
(
ctor_def
));
}
}
}
res
.unwrap_or_else
(||
report_errors
(
self
,
Some
(
resolution
.base_def
)))
}
}
Some
(
resolution
)
if
source
.defer_to_typeck
()
=>
{
...
...
src/test/compile-fail/privacy/legacy-ctor-visibility.rs
0 → 100644
浏览文件 @
8b060e25
// Copyright 2017 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.
#![allow(unused)]
use
m
::
S
;
mod
m
{
pub
struct
S
(
u8
);
mod
n
{
use
S
;
fn
f
()
{
S
(
10
);
//~^ ERROR private struct constructors are not usable through reexports in outer modules
//~| WARN this was previously accepted
}
}
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录