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

Hide suggestion to use struct ctor when it is not visible

上级 bb345a0b
...@@ -2568,7 +2568,8 @@ fn smart_resolve_path_fragment(&mut self, ...@@ -2568,7 +2568,8 @@ fn smart_resolve_path_fragment(&mut self,
let code = source.error_code(def.is_some()); let code = source.error_code(def.is_some());
let (base_msg, fallback_label, base_span) = if let Some(def) = def { let (base_msg, fallback_label, base_span) = if let Some(def) = def {
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str), (format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
format!("not a {}", expected), span) format!("not a {}", expected),
span)
} else { } else {
let item_str = path[path.len() - 1].node; let item_str = path[path.len() - 1].node;
let item_span = path[path.len() - 1].span; let item_span = path[path.len() - 1].span;
...@@ -2585,7 +2586,8 @@ fn smart_resolve_path_fragment(&mut self, ...@@ -2585,7 +2586,8 @@ fn smart_resolve_path_fragment(&mut self,
(mod_prefix, format!("`{}`", names_to_string(mod_path))) (mod_prefix, format!("`{}`", names_to_string(mod_path)))
}; };
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str), (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 code = DiagnosticId::Error(code.into());
let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code); 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, ...@@ -2701,17 +2703,21 @@ fn smart_resolve_path_fragment(&mut self,
return (err, candidates); return (err, candidates);
}, },
_ if ns == ValueNS && is_struct_like(def) => { _ if ns == ValueNS && is_struct_like(def) => {
let mut accessible_ctor = true;
if let Def::Struct(def_id) = def { if let Def::Struct(def_id) = def {
if let Some((ctor_def, ctor_vis)) if let Some((ctor_def, ctor_vis))
= this.struct_constructors.get(&def_id).cloned() { = 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 \ err.span_label(span, format!("constructor is not visible \
here due to private fields")); here due to private fields"));
} }
} }
} }
if accessible_ctor {
err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?", err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?",
path_str)); path_str));
}
return (err, candidates); return (err, candidates);
} }
_ => {} _ => {}
......
...@@ -6,7 +6,6 @@ error[E0423]: expected value, found struct `Z` ...@@ -6,7 +6,6 @@ error[E0423]: expected value, found struct `Z`
| | | |
| did you mean `S`? | did you mean `S`?
| constructor is not visible here due to private fields | 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 help: possible better candidate is found in another module, you can import it into scope
| |
22 | use m::n::Z; 22 | use m::n::Z;
...@@ -16,10 +15,7 @@ error[E0423]: expected value, found struct `S` ...@@ -16,10 +15,7 @@ error[E0423]: expected value, found struct `S`
--> $DIR/privacy-struct-ctor.rs:35:5 --> $DIR/privacy-struct-ctor.rs:35:5
| |
35 | S; 35 | S;
| ^ | ^ constructor is not visible here due to private fields
| |
| constructor is not visible here due to private fields
| did you mean `S { /* fields */ }`?
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
31 | use m::S; 31 | use m::S;
...@@ -29,10 +25,7 @@ error[E0423]: expected value, found struct `xcrate::S` ...@@ -29,10 +25,7 @@ error[E0423]: expected value, found struct `xcrate::S`
--> $DIR/privacy-struct-ctor.rs:40:5 --> $DIR/privacy-struct-ctor.rs:40:5
| |
40 | xcrate::S; 40 | xcrate::S;
| ^^^^^^^^^ | ^^^^^^^^^ constructor is not visible here due to private fields
| |
| constructor is not visible here due to private fields
| did you mean `xcrate::S { /* fields */ }`?
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
31 | use m::S; 31 | use m::S;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册