Rollup merge of #91764 - cjgillot:elide-anyway, r=jackh726
Do not ICE when suggesting elided lifetimes on non-existent spans. Fixes https://github.com/rust-lang/rust/issues/91763 r? `@jackh726`
This commit is contained in:
commit
72b6a91fe7
6 changed files with 78 additions and 21 deletions
|
@ -22,9 +22,7 @@ use ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
|||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync;
|
||||
use rustc_errors::{
|
||||
add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability, SuggestionStyle,
|
||||
};
|
||||
use rustc_errors::{struct_span_err, Applicability, SuggestionStyle};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
|
@ -670,23 +668,6 @@ pub trait LintContext: Sized {
|
|||
) => {
|
||||
db.span_note(span_def, "the macro is defined here");
|
||||
}
|
||||
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
|
||||
n,
|
||||
path_span,
|
||||
incl_angl_brckt,
|
||||
insertion_span,
|
||||
anon_lts,
|
||||
) => {
|
||||
add_elided_lifetime_in_path_suggestion(
|
||||
sess.source_map(),
|
||||
&mut db,
|
||||
n,
|
||||
path_span,
|
||||
incl_angl_brckt,
|
||||
insertion_span,
|
||||
anon_lts,
|
||||
);
|
||||
}
|
||||
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
|
||||
db.span_suggestion(span, ¬e, sugg, Applicability::MaybeIncorrect);
|
||||
}
|
||||
|
|
|
@ -289,7 +289,6 @@ pub enum BuiltinLintDiagnostics {
|
|||
AbsPathWithModule(Span),
|
||||
ProcMacroDeriveResolutionFallback(Span),
|
||||
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
|
||||
ElidedLifetimesInPaths(usize, Span, bool, Span, String),
|
||||
UnknownCrateTypes(Span, String, String),
|
||||
UnusedImports(String, Vec<(Span, String)>),
|
||||
RedundantImport(Vec<(Span, bool)>, Ident),
|
||||
|
|
|
@ -2115,6 +2115,11 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
})
|
||||
.map(|(formatter, span)| (*span, formatter(name)))
|
||||
.collect();
|
||||
if spans_suggs.is_empty() {
|
||||
// If all the spans come from macros, we cannot extract snippets and then
|
||||
// `formatters` only contains None and `spans_suggs` is empty.
|
||||
return;
|
||||
}
|
||||
err.multipart_suggestion_verbose(
|
||||
&format!(
|
||||
"consider using the `{}` lifetime",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue