diff options
| author | yukang <moorekang@gmail.com> | 2022-10-18 01:58:22 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-10-20 11:55:30 +0800 |
| commit | f90bf50d475eb9240c5bdeef3102c235335180c4 (patch) | |
| tree | 1a1454cebe58b03db5b56411c6399728b85903b7 | |
| parent | 1225c3f6b8976b96eff4444cd7416a5d14eb3cd4 (diff) | |
| download | rust-f90bf50d475eb9240c5bdeef3102c235335180c4.tar.gz rust-f90bf50d475eb9240c5bdeef3102c235335180c4.zip | |
fix span for suggestion
| -rw-r--r-- | compiler/rustc_resolve/src/macros.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-103112.stderr | 5 |
2 files changed, 10 insertions, 15 deletions
diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 71264ffc877..9526296f951 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -697,21 +697,15 @@ impl<'a> Resolver<'a> { 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.resolve_path( - &path, - Some(ValueNS), - &parent_scope, - Some(Finalize::new(ast::CRATE_NODE_ID, path_span)), - None, - ) && partial_res.unresolved_segments() == 0 { + 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 span = sm.span_extend_while(span, |c| c == '!').unwrap_or(span); - let code = sm.span_to_snippet(span).unwrap(); - suggestion = Some( - (vec![(span, code.trim_end_matches('!').to_string())], + 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) - ); + Applicability::MaybeIncorrect + )); } (span, label) } else { diff --git a/src/test/ui/suggestions/issue-103112.stderr b/src/test/ui/suggestions/issue-103112.stderr index 3518ef4c652..4ca7fdf9b5a 100644 --- a/src/test/ui/suggestions/issue-103112.stderr +++ b/src/test/ui/suggestions/issue-103112.stderr @@ -6,8 +6,9 @@ LL | std::process::abort!(); | help: std::process::abort is not a macro, but a function, try to remove `!` | -LL | std::process::abort(); - | ~~~~~ +LL - std::process::abort!(); +LL + std::process::abort(); + | error: aborting due to previous error |
