Skip to content

Commit 3df030d

Browse files
authored
Rollup merge of #103140 - chenyukang:yukang/fix-103112, r=estebank
Add diagnostic for calling a function with the same name with unresolved Macro Fixes #103112
2 parents 23d1b05 + f90bf50 commit 3df030d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

compiler/rustc_resolve/src/macros.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_attr::StabilityLevel;
1212
use rustc_data_structures::fx::FxHashSet;
1313
use rustc_data_structures::intern::Interned;
1414
use rustc_data_structures::sync::Lrc;
15-
use rustc_errors::struct_span_err;
15+
use rustc_errors::{struct_span_err, Applicability};
1616
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
1717
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1818
use rustc_expand::compile_declarative_macro;
@@ -694,7 +694,19 @@ impl<'a> Resolver<'a> {
694694
check_consistency(self, &path, path_span, kind, initial_res, res)
695695
}
696696
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed { .. } => {
697+
let mut suggestion = None;
697698
let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
699+
// try to suggest if it's not a macro, maybe a function
700+
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
701+
&& partial_res.unresolved_segments() == 0 {
702+
let sm = self.session.source_map();
703+
let exclamation_span = sm.next_point(span);
704+
suggestion = Some((
705+
vec![(exclamation_span, "".to_string())],
706+
format!("{} is not a macro, but a {}, try to remove `!`", Segment::names_to_string(&path), partial_res.base_res().descr()),
707+
Applicability::MaybeIncorrect
708+
));
709+
}
698710
(span, label)
699711
} else {
700712
(
@@ -708,7 +720,7 @@ impl<'a> Resolver<'a> {
708720
};
709721
self.report_error(
710722
span,
711-
ResolutionError::FailedToResolve { label, suggestion: None },
723+
ResolutionError::FailedToResolve { label, suggestion },
712724
);
713725
}
714726
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
std::process::abort!();
3+
//~^ ERROR: failed to resolve
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: could not find `abort` in `process`
2+
--> $DIR/issue-103112.rs:2:19
3+
|
4+
LL | std::process::abort!();
5+
| ^^^^^ could not find `abort` in `process`
6+
|
7+
help: std::process::abort is not a macro, but a function, try to remove `!`
8+
|
9+
LL - std::process::abort!();
10+
LL + std::process::abort();
11+
|
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)