Skip to content

Commit

Permalink
lint to use self for this/my
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Oct 1, 2018
1 parent cae164c commit 99edcd4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -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())
Expand All @@ -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);
Expand Down

0 comments on commit 99edcd4

Please sign in to comment.