Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9bab0f09
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,发现更多精彩内容 >>
提交
9bab0f09
编写于
12月 31, 2017
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Hide suggestion to use struct ctor when it is not visible
上级
bb345a0b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
14 deletion
+13
-14
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+11
-5
src/test/ui/resolve/privacy-struct-ctor.stderr
src/test/ui/resolve/privacy-struct-ctor.stderr
+2
-9
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
9bab0f09
...
...
@@ -2568,7 +2568,8 @@ fn smart_resolve_path_fragment(&mut self,
let
code
=
source
.error_code
(
def
.is_some
());
let
(
base_msg
,
fallback_label
,
base_span
)
=
if
let
Some
(
def
)
=
def
{
(
format!
(
"expected {}, found {} `{}`"
,
expected
,
def
.kind_name
(),
path_str
),
format!
(
"not a {}"
,
expected
),
span
)
format!
(
"not a {}"
,
expected
),
span
)
}
else
{
let
item_str
=
path
[
path
.len
()
-
1
]
.node
;
let
item_span
=
path
[
path
.len
()
-
1
]
.span
;
...
...
@@ -2585,7 +2586,8 @@ fn smart_resolve_path_fragment(&mut self,
(
mod_prefix
,
format!
(
"`{}`"
,
names_to_string
(
mod_path
)))
};
(
format!
(
"cannot find {} `{}` in {}{}"
,
expected
,
item_str
,
mod_prefix
,
mod_str
),
format!
(
"not found in {}"
,
mod_str
),
item_span
)
format!
(
"not found in {}"
,
mod_str
),
item_span
)
};
let
code
=
DiagnosticId
::
Error
(
code
.into
());
let
mut
err
=
this
.session
.struct_span_err_with_code
(
base_span
,
&
base_msg
,
code
);
...
...
@@ -2701,17 +2703,21 @@ fn smart_resolve_path_fragment(&mut self,
return
(
err
,
candidates
);
},
_
if
ns
==
ValueNS
&&
is_struct_like
(
def
)
=>
{
let
mut
accessible_ctor
=
true
;
if
let
Def
::
Struct
(
def_id
)
=
def
{
if
let
Some
((
ctor_def
,
ctor_vis
))
=
this
.struct_constructors
.get
(
&
def_id
)
.cloned
()
{
if
is_expected
(
ctor_def
)
&&
!
this
.is_accessible
(
ctor_vis
)
{
accessible_ctor
=
this
.is_accessible
(
ctor_vis
);
if
is_expected
(
ctor_def
)
&&
!
accessible_ctor
{
err
.span_label
(
span
,
format!
(
"constructor is not visible
\
here due to private fields"
));
}
}
}
err
.span_label
(
span
,
format!
(
"did you mean `{} {{ /* fields */ }}`?"
,
path_str
));
if
accessible_ctor
{
err
.span_label
(
span
,
format!
(
"did you mean `{} {{ /* fields */ }}`?"
,
path_str
));
}
return
(
err
,
candidates
);
}
_
=>
{}
...
...
src/test/ui/resolve/privacy-struct-ctor.stderr
浏览文件 @
9bab0f09
...
...
@@ -6,7 +6,6 @@ error[E0423]: expected value, found struct `Z`
| |
| did you mean `S`?
| constructor is not visible here due to private fields
| did you mean `Z { /* fields */ }`?
help: possible better candidate is found in another module, you can import it into scope
|
22 | use m::n::Z;
...
...
@@ -16,10 +15,7 @@ error[E0423]: expected value, found struct `S`
--> $DIR/privacy-struct-ctor.rs:35:5
|
35 | S;
| ^
| |
| constructor is not visible here due to private fields
| did you mean `S { /* fields */ }`?
| ^ constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
|
31 | use m::S;
...
...
@@ -29,10 +25,7 @@ error[E0423]: expected value, found struct `xcrate::S`
--> $DIR/privacy-struct-ctor.rs:40:5
|
40 | xcrate::S;
| ^^^^^^^^^
| |
| constructor is not visible here due to private fields
| did you mean `xcrate::S { /* fields */ }`?
| ^^^^^^^^^ constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
|
31 | use m::S;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录