提交 a317da42 编写于 作者: E Esteban Küber

Suggest the correct syntax for different struct types

上级 9bab0f09
......@@ -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));
}
......
......@@ -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
......@@ -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
......@@ -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`
......
error[E0423]: expected value, found struct `Z`
--> $DIR/privacy-struct-ctor.rs:26:9
--> $DIR/privacy-struct-ctor.rs:29:9
|
26 | Z;
29 | 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
|
22 | use m::n::Z;
25 | use m::n::Z;
|
error[E0423]: expected value, found struct `S`
--> $DIR/privacy-struct-ctor.rs:35:5
--> $DIR/privacy-struct-ctor.rs:39:5
|
35 | S;
39 | 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:40:5
--> $DIR/privacy-struct-ctor.rs:47:5
|
40 | xcrate::S;
47 | 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
|
31 | use m::S;
34 | use m::S;
|
error[E0603]: tuple struct `Z` is private
--> $DIR/privacy-struct-ctor.rs:25:9
--> $DIR/privacy-struct-ctor.rs:28:9
|
25 | n::Z; //~ ERROR tuple struct `Z` is private
28 | n::Z; //~ ERROR tuple struct `Z` is private
| ^^^^
error[E0603]: tuple struct `S` is private
--> $DIR/privacy-struct-ctor.rs:34:5
--> $DIR/privacy-struct-ctor.rs:38:5
|
34 | m::S; //~ ERROR tuple struct `S` is private
38 | 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:42:5
--> $DIR/privacy-struct-ctor.rs:49:5
|
42 | xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
49 | xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
| ^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors
error: aborting due to 9 previous errors
......@@ -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.
先完成此消息的编辑!
想要评论请 注册