Skip to content
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
16 changes: 14 additions & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_attr::StabilityLevel;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc;
use rustc_errors::struct_span_err;
use rustc_errors::{struct_span_err, Applicability};
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::compile_declarative_macro;
Expand Down Expand Up @@ -694,7 +694,19 @@ impl<'a> Resolver<'a> {
check_consistency(self, &path, path_span, kind, initial_res, res)
}
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed { .. } => {
let mut suggestion = None;
let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
// try to suggest if it's not a macro, maybe a function
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
&& partial_res.unresolved_segments() == 0 {
let sm = self.session.source_map();
let exclamation_span = sm.next_point(span);
suggestion = Some((
vec![(exclamation_span, "".to_string())],
format!("{} is not a macro, but a {}, try to remove `!`", Segment::names_to_string(&path), partial_res.base_res().descr()),
Applicability::MaybeIncorrect
));
}
(span, label)
} else {
(
Expand All @@ -708,7 +720,7 @@ impl<'a> Resolver<'a> {
};
self.report_error(
span,
ResolutionError::FailedToResolve { label, suggestion: None },
ResolutionError::FailedToResolve { label, suggestion },
);
}
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/suggestions/issue-103112.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
std::process::abort!();
//~^ ERROR: failed to resolve
}
15 changes: 15 additions & 0 deletions src/test/ui/suggestions/issue-103112.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0433]: failed to resolve: could not find `abort` in `process`
--> $DIR/issue-103112.rs:2:19
|
LL | std::process::abort!();
| ^^^^^ could not find `abort` in `process`
|
help: std::process::abort is not a macro, but a function, try to remove `!`
|
LL - std::process::abort!();
LL + std::process::abort();
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.