Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

self.record_candidate_traits_for_expr_if_necessary(expr);

expr.toto();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Member Author

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.

// Next, resolve the node.
match expr.node {
ExprPath(ref maybe_qself, ref path) => {
Expand Down Expand Up @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I infer @Manishearth is referring to how a case like OnlyIrrefutablePatternsAllowedHere is handled; see linked code; following such a strategy would entail either changing the UnresolvedName variant, or adding a new variant that carries the necessary info... but nonetheless, it is probably a good suggestion, just to keep all the error reporting in one place...

Copy link
Member Author

Choose a reason for hiding this comment

The 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 Option as extra parameter and we're good to go.

self.session.fileline_help(expr.span, &help_msg);
}
}
}
}
Expand Down