Skip to content

Add new help messages for E0425 #30584

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

Merged
merged 1 commit into from
Jan 9, 2016
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use rustc_front::intravisit::{self, FnKind, Visitor};
use rustc_front::hir;
use rustc_front::hir::{Arm, BindByRef, BindByValue, BindingMode, Block};
use rustc_front::hir::Crate;
use rustc_front::hir::{Expr, ExprAgain, ExprBreak, ExprField};
use rustc_front::hir::{Expr, ExprAgain, ExprBreak, ExprCall, ExprField};
use rustc_front::hir::{ExprLoop, ExprWhile, ExprMethodCall};
use rustc_front::hir::{ExprPath, ExprStruct, FnDecl};
use rustc_front::hir::{ForeignItemFn, ForeignItemStatic, Generics};
Expand Down Expand Up @@ -423,7 +423,7 @@ fn resolve_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
msg);

match context {
UnresolvedNameContext::Other => {} // no help available
UnresolvedNameContext::Other => { } // no help available
UnresolvedNameContext::PathIsMod(id) => {
let mut help_msg = String::new();
let parent_id = resolver.ast_map.get_parent_node(id);
Expand All @@ -436,17 +436,22 @@ fn resolve_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
module = &*path,
ident = ident.node);
}

ExprMethodCall(ident, _, _) => {
help_msg = format!("To call a function from the \
`{module}` module, use \
`{module}::{ident}(..)`",
module = &*path,
ident = ident.node);
}

_ => {} // no help available
ExprCall(_, _) => {
help_msg = format!("No function corresponds to `{module}(..)`",
module = &*path);
}
_ => { } // no help available
}
} else {
help_msg = format!("Module `{module}` cannot be the value of an expression",
module = &*path);
}

if !help_msg.is_empty() {
Expand Down
12 changes: 12 additions & 0 deletions src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ fn h6() -> i32 {
//~^ ERROR E0425
//~| HELP To call a function from the `a::b` module, use `a::b::f(..)`
}

fn h7() {
a::b
//~^ ERROR E0425
//~| HELP Module `a::b` cannot be the value of an expression
}

fn h8() -> i32 {
a::b()
//~^ ERROR E0425
//~| HELP No function corresponds to `a::b(..)`
}