Skip to content

Commit c518664

Browse files
committed
Rollup merge of rust-lang#30584 - GuillaumeGomez:new_handles, r=pnkfelix
Last part of rust-lang#30413. r? @pnkfelix
2 parents 64a8ffe + c078769 commit c518664

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/librustc_resolve/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use rustc_front::intravisit::{self, FnKind, Visitor};
7272
use rustc_front::hir;
7373
use rustc_front::hir::{Arm, BindByRef, BindByValue, BindingMode, Block};
7474
use rustc_front::hir::Crate;
75-
use rustc_front::hir::{Expr, ExprAgain, ExprBreak, ExprField};
75+
use rustc_front::hir::{Expr, ExprAgain, ExprBreak, ExprCall, ExprField};
7676
use rustc_front::hir::{ExprLoop, ExprWhile, ExprMethodCall};
7777
use rustc_front::hir::{ExprPath, ExprStruct, FnDecl};
7878
use rustc_front::hir::{ForeignItemFn, ForeignItemStatic, Generics};
@@ -433,7 +433,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
433433
msg);
434434

435435
match context {
436-
UnresolvedNameContext::Other => {} // no help available
436+
UnresolvedNameContext::Other => { } // no help available
437437
UnresolvedNameContext::PathIsMod(id) => {
438438
let mut help_msg = String::new();
439439
let parent_id = resolver.ast_map.get_parent_node(id);
@@ -446,17 +446,22 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
446446
module = &*path,
447447
ident = ident.node);
448448
}
449-
450449
ExprMethodCall(ident, _, _) => {
451450
help_msg = format!("To call a function from the \
452451
`{module}` module, use \
453452
`{module}::{ident}(..)`",
454453
module = &*path,
455454
ident = ident.node);
456455
}
457-
458-
_ => {} // no help available
456+
ExprCall(_, _) => {
457+
help_msg = format!("No function corresponds to `{module}(..)`",
458+
module = &*path);
459+
}
460+
_ => { } // no help available
459461
}
462+
} else {
463+
help_msg = format!("Module `{module}` cannot be the value of an expression",
464+
module = &*path);
460465
}
461466

462467
if !help_msg.is_empty() {

src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ fn h6() -> i32 {
5858
//~^ ERROR E0425
5959
//~| HELP To call a function from the `a::b` module, use `a::b::f(..)`
6060
}
61+
62+
fn h7() {
63+
a::b
64+
//~^ ERROR E0425
65+
//~| HELP Module `a::b` cannot be the value of an expression
66+
}
67+
68+
fn h8() -> i32 {
69+
a::b()
70+
//~^ ERROR E0425
71+
//~| HELP No function corresponds to `a::b(..)`
72+
}

0 commit comments

Comments
 (0)