Auto merge of #87915 - estebank:fancy-spans, r=oli-obk

Use smaller spans for some structured suggestions

Use more accurate suggestion spans for

* argument parse error
* fully qualified path
* missing code block type
* numeric casts
This commit is contained in:
bors 2021-09-13 16:31:12 +00:00
commit 9bb77da74d
60 changed files with 1200 additions and 958 deletions

View file

@ -12,7 +12,7 @@ use rustc_ast::{
};
use rustc_ast_pretty::pprust::path_segment_to_string;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, SuggestionStyle};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
@ -1960,11 +1960,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
introduce_suggestion.push((*span, formatter(&lt_name)));
}
}
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
&msg,
introduce_suggestion,
Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
);
}
@ -1976,14 +1975,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
})
.map(|(formatter, span)| (*span, formatter(name)))
.collect();
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
&format!(
"consider using the `{}` lifetime",
lifetime_names.iter().next().unwrap()
),
spans_suggs,
Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
);
};
let suggest_new = |err: &mut DiagnosticBuilder<'_>, suggs: Vec<Option<String>>| {
@ -2074,11 +2072,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
};
spans_suggs.push((span, sugg.to_string()));
}
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
"consider using the `'static` lifetime",
spans_suggs,
Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
);
continue;
}
@ -2163,11 +2160,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
.unwrap_or((span, sugg));
introduce_suggestion.push((span, sugg.to_string()));
}
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
&msg,
introduce_suggestion,
Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
);
if should_break {
break;
@ -2243,11 +2239,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
if spans_suggs.len() > 0 {
// This happens when we have `Foo<T>` where we point at the space before `T`,
// but this can be confusing so we give a suggestion with placeholders.
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
"consider using one of the available lifetimes here",
spans_suggs,
Applicability::HasPlaceholders,
SuggestionStyle::ShowAlways,
);
}
}