-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add note when a function is called from a module like it's an object #30356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3391,6 +3391,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
|
||
self.record_candidate_traits_for_expr_if_necessary(expr); | ||
|
||
expr.toto(); | ||
// Next, resolve the node. | ||
match expr.node { | ||
ExprPath(ref maybe_qself, ref path) => { | ||
|
@@ -3509,13 +3510,38 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
format!("to call `{}::{}`", path_str, path_name), | ||
}; | ||
|
||
let mut help_msg = String::new(); | ||
if !msg.is_empty() { | ||
msg = format!(". Did you mean {}?", msg) | ||
} else { | ||
// we check if this a module and if so, we display a help | ||
// message | ||
let name_path = path.segments.iter() | ||
.map(|seg| seg.identifier.name) | ||
.collect::<Vec<_>>(); | ||
let current_module = self.current_module.clone(); | ||
|
||
match self.resolve_module_path(current_module, | ||
&name_path[..], | ||
UseLexicalScope, | ||
expr.span, | ||
PathSearch) { | ||
Success(_) => { | ||
help_msg = format!("To reference an item from the \ | ||
`{module}` module, use \ | ||
`{module}::the_function_you_want`", | ||
module = &*path_name); | ||
}, | ||
_ => {}, | ||
}; | ||
} | ||
|
||
resolve_error(self, | ||
expr.span, | ||
ResolutionError::UnresolvedName(&*path_name, &*msg)); | ||
if !help_msg.is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the help msg should be passed down to resolve_error? I think the rest of the file does help messages this way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I infer @Manishearth is referring to how a case like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind, it's the same for me. I'll just provide an |
||
self.session.fileline_help(expr.span, &help_msg); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test of mine, wasn't intended to get committed. Just ignore it please.