提交 99edcd4d 编写于 作者: C csmoe

lint to use self for this/my

上级 cae164c0
......@@ -2981,13 +2981,13 @@ fn smart_resolve_path_fragment(&mut self,
// Make the base error.
let expected = source.descr_expected();
let path_str = names_to_string(path);
let item_str = path[path.len() - 1];
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)
} else {
let item_str = path[path.len() - 1];
let item_span = path[path.len() - 1].span;
let (mod_prefix, mod_str) = if path.len() == 1 {
(String::new(), "this scope".to_string())
......@@ -3010,6 +3010,20 @@ fn smart_resolve_path_fragment(&mut self,
let code = DiagnosticId::Error(code.into());
let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code);
// Emit help message for fake-self from other languages like `this`(javascript)
let fake_self: Vec<Ident> = ["this", "my"].iter().map(
|s| Ident::from_str(*s)
).collect();
if fake_self.contains(&item_str)
&& this.self_value_is_available(path[0].span, span) {
err.span_suggestion_with_applicability(
span,
"did you mean",
"self".to_string(),
Applicability::MachineApplicable,
);
}
// Emit special messages for unresolved `Self` and `self`.
if is_self_type(path, ns) {
__diagnostic_used!(E0411);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册