diff options
| author | Michael Howell <michael@notriddle.com> | 2022-10-23 14:48:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-23 14:48:15 -0700 |
| commit | 3df030d4418e011dbd5a4947157bcd14ba75e189 (patch) | |
| tree | 8838b06be404c650b933e8e0d3524efe6c13980b /compiler/rustc_resolve/src | |
| parent | 23d1b057260c9a3c3520d97922589f5013988de0 (diff) | |
| parent | f90bf50d475eb9240c5bdeef3102c235335180c4 (diff) | |
| download | rust-3df030d4418e011dbd5a4947157bcd14ba75e189.tar.gz rust-3df030d4418e011dbd5a4947157bcd14ba75e189.zip | |
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
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/macros.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index f6f0b3c1139..9526296f951 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -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; @@ -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 { ( @@ -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!(), |
