mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
lint to use self for this/my
This commit is contained in:
parent
cae164c02c
commit
99edcd4da7
@ -2981,13 +2981,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||
// 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 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user