Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a317da42
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,发现更多精彩内容 >>
提交
a317da42
编写于
1月 01, 2018
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Suggest the correct syntax for different struct types
上级
9bab0f09
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
62 addition
and
45 deletion
+62
-45
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+22
-12
src/test/ui/resolve/issue-18252.stderr
src/test/ui/resolve/issue-18252.stderr
+1
-1
src/test/ui/resolve/issue-19452.stderr
src/test/ui/resolve/issue-19452.stderr
+2
-2
src/test/ui/resolve/privacy-struct-ctor.rs
src/test/ui/resolve/privacy-struct-ctor.rs
+7
-0
src/test/ui/resolve/privacy-struct-ctor.stderr
src/test/ui/resolve/privacy-struct-ctor.stderr
+26
-20
src/test/ui/resolve/tuple-struct-alias.stderr
src/test/ui/resolve/tuple-struct-alias.stderr
+4
-10
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
a317da42
...
...
@@ -2702,19 +2702,29 @@ 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
()
{
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"
));
}
(
Def
::
Struct
(
def_id
),
_
)
if
ns
==
ValueNS
&&
is_struct_like
(
def
)
=>
{
if
let
Some
((
ctor_def
,
ctor_vis
))
=
this
.struct_constructors
.get
(
&
def_id
)
.cloned
()
{
let
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"
));
}
else
if
accessible_ctor
{
let
block
=
match
ctor_def
{
Def
::
StructCtor
(
_
,
CtorKind
::
Fn
)
|
Def
::
VariantCtor
(
_
,
CtorKind
::
Fn
)
=>
"(/* fields */)"
,
Def
::
StructCtor
(
_
,
CtorKind
::
Fictive
)
|
Def
::
VariantCtor
(
_
,
CtorKind
::
Fictive
)
=>
{
" { /* fields */ }"
}
def
=>
bug!
(
"found def `{:?}` when looking for a ctor"
,
def
),
};
err
.span_label
(
span
,
format!
(
"did you mean `{}{}`?"
,
path_str
,
block
));
}
}
if
accessible_ctor
{
}
else
{
err
.span_label
(
span
,
format!
(
"did you mean `{} {{ /* fields */ }}`?"
,
path_str
));
}
...
...
src/test/ui/resolve/issue-18252.stderr
浏览文件 @
a317da42
...
...
@@ -2,7 +2,7 @@ error[E0423]: expected function, found struct variant `Foo::Variant`
--> $DIR/issue-18252.rs:16:13
|
16 | let f = Foo::Variant(42);
| ^^^^^^^^^^^^
did you mean `Foo::Variant { /* fields */ }`?
| ^^^^^^^^^^^^
not a function
error: aborting due to previous error
src/test/ui/resolve/issue-19452.stderr
浏览文件 @
a317da42
...
...
@@ -2,13 +2,13 @@ error[E0423]: expected value, found struct variant `Homura::Madoka`
--> $DIR/issue-19452.rs:19:18
|
19 | let homura = Homura::Madoka;
| ^^^^^^^^^^^^^^
did you mean `Homura::Madoka { /* fields */ }`?
| ^^^^^^^^^^^^^^
not a value
error[E0423]: expected value, found struct variant `issue_19452_aux::Homura::Madoka`
--> $DIR/issue-19452.rs:22:18
|
22 | let homura = issue_19452_aux::Homura::Madoka;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
did you mean `issue_19452_aux::Homura::Madoka { /* fields */ }`?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
not a value
error: aborting due to 2 previous errors
src/test/ui/resolve/privacy-struct-ctor.rs
浏览文件 @
a317da42
...
...
@@ -14,6 +14,9 @@
mod
m
{
pub
struct
S
(
u8
);
pub
struct
S2
{
s
:
u8
}
pub
mod
n
{
pub
(
in
m
)
struct
Z
(
pub
(
in
m
::
n
)
u8
);
...
...
@@ -29,6 +32,7 @@ fn f() {
}
use
m
::
S
;
// OK, only the type is imported
use
m
::
S2
;
// OK, only the type is imported
fn
main
()
{
m
::
S
;
//~ ERROR tuple struct `S` is private
...
...
@@ -36,6 +40,9 @@ fn main() {
//~^ ERROR expected value, found struct `S`
m
::
n
::
Z
;
//~ ERROR tuple struct `Z` is private
S2
;
//~^ ERROR expected value, found struct `S2`
xcrate
::
m
::
S
;
//~ ERROR tuple struct `S` is private
xcrate
::
S
;
//~^ ERROR expected value, found struct `xcrate::S`
...
...
src/test/ui/resolve/privacy-struct-ctor.stderr
浏览文件 @
a317da42
error[E0423]: expected value, found struct `Z`
--> $DIR/privacy-struct-ctor.rs:2
6
:9
--> $DIR/privacy-struct-ctor.rs:2
9
:9
|
2
6
| Z;
2
9
| Z;
| ^
| |
| did you mean `S`?
| constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
|
2
2
| use m::n::Z;
2
5
| use m::n::Z;
|
error[E0423]: expected value, found struct `S`
--> $DIR/privacy-struct-ctor.rs:3
5
:5
--> $DIR/privacy-struct-ctor.rs:3
9
:5
|
3
5
| S;
3
9
| S;
| ^ 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;
34 | use m::S;
|
error[E0423]: expected value, found struct `S2`
--> $DIR/privacy-struct-ctor.rs:43:5
|
43 | S2;
| ^^ did you mean `S2 { /* fields */ }`?
error[E0423]: expected value, found struct `xcrate::S`
--> $DIR/privacy-struct-ctor.rs:4
0
:5
--> $DIR/privacy-struct-ctor.rs:4
7
:5
|
4
0
| xcrate::S;
4
7
| xcrate::S;
| ^^^^^^^^^ constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
|
3
1
| use m::S;
3
4
| use m::S;
|
error[E0603]: tuple struct `Z` is private
--> $DIR/privacy-struct-ctor.rs:2
5
:9
--> $DIR/privacy-struct-ctor.rs:2
8
:9
|
2
5
| n::Z; //~ ERROR tuple struct `Z` is private
2
8
| n::Z; //~ ERROR tuple struct `Z` is private
| ^^^^
error[E0603]: tuple struct `S` is private
--> $DIR/privacy-struct-ctor.rs:3
4
:5
--> $DIR/privacy-struct-ctor.rs:3
8
:5
|
3
4
| m::S; //~ ERROR tuple struct `S` is private
3
8
| m::S; //~ ERROR tuple struct `S` is private
| ^^^^
error[E0603]: tuple struct `Z` is private
--> $DIR/privacy-struct-ctor.rs:
37
:5
--> $DIR/privacy-struct-ctor.rs:
41
:5
|
37
| m::n::Z; //~ ERROR tuple struct `Z` is private
41
| m::n::Z; //~ ERROR tuple struct `Z` is private
| ^^^^^^^
error[E0603]: tuple struct `S` is private
--> $DIR/privacy-struct-ctor.rs:
39
:5
--> $DIR/privacy-struct-ctor.rs:
46
:5
|
39
| xcrate::m::S; //~ ERROR tuple struct `S` is private
46
| xcrate::m::S; //~ ERROR tuple struct `S` is private
| ^^^^^^^^^^^^
error[E0603]: tuple struct `Z` is private
--> $DIR/privacy-struct-ctor.rs:4
2
:5
--> $DIR/privacy-struct-ctor.rs:4
9
:5
|
4
2
| xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
4
9
| xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
| ^^^^^^^^^^^^^^^
error: aborting due to
8
previous errors
error: aborting due to
9
previous errors
src/test/ui/resolve/tuple-struct-alias.stderr
浏览文件 @
a317da42
...
...
@@ -2,31 +2,25 @@ error[E0423]: expected function, found self type `Self`
--> $DIR/tuple-struct-alias.rs:16:17
|
16 | let s = Self(0, 1); //~ ERROR expected function
| ^^^^
did you mean `Self { /* fields */ }`?
| ^^^^
not a function
error[E0532]: expected tuple struct/variant, found self type `Self`
--> $DIR/tuple-struct-alias.rs:18:13
|
18 | Self(..) => {} //~ ERROR expected tuple struct/variant
| ^^^^
did you mean `Self { /* fields */ }`?
| ^^^^
not a tuple struct/variant
error[E0423]: expected function, found type alias `A`
--> $DIR/tuple-struct-alias.rs:24:13
|
24 | let s = A(0, 1); //~ ERROR expected function
| ^
| |
| did you mean `S`?
| did you mean `A { /* fields */ }`?
| ^ did you mean `S`?
error[E0532]: expected tuple struct/variant, found type alias `A`
--> $DIR/tuple-struct-alias.rs:26:9
|
26 | A(..) => {} //~ ERROR expected tuple struct/variant
| ^
| |
| did you mean `S`?
| did you mean `A { /* fields */ }`?
| ^ did you mean `S`?
error: aborting due to 4 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录