Use correct span for structured suggestion
On structured suggestion for `let` -> `const` and `const` -> `let`, use a proper `Span` and update tests to check the correct application. Follow up to #80012.
This commit is contained in:
parent
c8915eebea
commit
9a5dcaab67
27 changed files with 146 additions and 64 deletions
|
@ -398,20 +398,30 @@ impl<'a> Resolver<'a> {
|
|||
err.help("use the `|| { ... }` closure form instead");
|
||||
err
|
||||
}
|
||||
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg) => {
|
||||
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg, current) => {
|
||||
let mut err = struct_span_err!(
|
||||
self.session,
|
||||
span,
|
||||
E0435,
|
||||
"attempt to use a non-constant value in a constant"
|
||||
);
|
||||
err.span_suggestion(
|
||||
ident.span,
|
||||
&sugg,
|
||||
"".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.span_label(span, "non-constant value");
|
||||
// let foo =...
|
||||
// ^^^ given this Span
|
||||
// ------- get this Span to have an applicable suggestion
|
||||
let sp =
|
||||
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
|
||||
if sp.lo().0 == 0 {
|
||||
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
|
||||
} else {
|
||||
let sp = sp.with_lo(BytePos(sp.lo().0 - current.len() as u32));
|
||||
err.span_suggestion(
|
||||
sp,
|
||||
&format!("consider using `{}` instead of `{}`", sugg, current),
|
||||
format!("{} {}", sugg, ident),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.span_label(span, "non-constant value");
|
||||
}
|
||||
err
|
||||
}
|
||||
ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue