Skip to content

Commit bf3e37d

Browse files
Add note when a function is called from a module like it's an object
1 parent ce13275 commit bf3e37d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/librustc_resolve/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -3391,6 +3391,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
33913391

33923392
self.record_candidate_traits_for_expr_if_necessary(expr);
33933393

3394+
expr.toto();
33943395
// Next, resolve the node.
33953396
match expr.node {
33963397
ExprPath(ref maybe_qself, ref path) => {
@@ -3509,13 +3510,38 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35093510
format!("to call `{}::{}`", path_str, path_name),
35103511
};
35113512

3513+
let mut help_msg = String::new();
35123514
if !msg.is_empty() {
35133515
msg = format!(". Did you mean {}?", msg)
3516+
} else {
3517+
// we check if this a module and if so, we display a help
3518+
// message
3519+
let name_path = path.segments.iter()
3520+
.map(|seg| seg.identifier.name)
3521+
.collect::<Vec<_>>();
3522+
let current_module = self.current_module.clone();
3523+
3524+
match self.resolve_module_path(current_module,
3525+
&name_path[..],
3526+
UseLexicalScope,
3527+
expr.span,
3528+
PathSearch) {
3529+
Success(_) => {
3530+
help_msg = format!("To reference an item from the \
3531+
`{module}` module, use \
3532+
`{module}::the_function_you_want`",
3533+
module = &*path_name);
3534+
},
3535+
_ => {},
3536+
};
35143537
}
35153538

35163539
resolve_error(self,
35173540
expr.span,
35183541
ResolutionError::UnresolvedName(&*path_name, &*msg));
3542+
if !help_msg.is_empty() {
3543+
self.session.fileline_help(expr.span, &help_msg);
3544+
}
35193545
}
35203546
}
35213547
}

0 commit comments

Comments
 (0)