Skip to content

Commit f90bf50

Browse files
committed
fix span for suggestion
1 parent 1225c3f commit f90bf50

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

compiler/rustc_resolve/src/macros.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -697,21 +697,15 @@ impl<'a> Resolver<'a> {
697697
let mut suggestion = None;
698698
let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
699699
// try to suggest if it's not a macro, maybe a function
700-
if let PathResult::NonModule(partial_res) = self.resolve_path(
701-
&path,
702-
Some(ValueNS),
703-
&parent_scope,
704-
Some(Finalize::new(ast::CRATE_NODE_ID, path_span)),
705-
None,
706-
) && partial_res.unresolved_segments() == 0 {
700+
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
701+
&& partial_res.unresolved_segments() == 0 {
707702
let sm = self.session.source_map();
708-
let span = sm.span_extend_while(span, |c| c == '!').unwrap_or(span);
709-
let code = sm.span_to_snippet(span).unwrap();
710-
suggestion = Some(
711-
(vec![(span, code.trim_end_matches('!').to_string())],
703+
let exclamation_span = sm.next_point(span);
704+
suggestion = Some((
705+
vec![(exclamation_span, "".to_string())],
712706
format!("{} is not a macro, but a {}, try to remove `!`", Segment::names_to_string(&path), partial_res.base_res().descr()),
713-
Applicability::MaybeIncorrect)
714-
);
707+
Applicability::MaybeIncorrect
708+
));
715709
}
716710
(span, label)
717711
} else {

src/test/ui/suggestions/issue-103112.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | std::process::abort!();
66
|
77
help: std::process::abort is not a macro, but a function, try to remove `!`
88
|
9-
LL | std::process::abort();
10-
| ~~~~~
9+
LL - std::process::abort!();
10+
LL + std::process::abort();
11+
|
1112

1213
error: aborting due to previous error
1314

0 commit comments

Comments
 (0)