Rollup merge of #106935 - TaKO8Ki:fix-104440, r=cjgillot
Fix `SingleUseLifetime` ICE Fixes #104440 cc: ``@matthiaskrgr``
This commit is contained in:
commit
8a830cf182
5 changed files with 174 additions and 25 deletions
|
@ -825,21 +825,24 @@ pub trait LintContext: Sized {
|
|||
debug!(?param_span, ?use_span, ?deletion_span);
|
||||
db.span_label(param_span, "this lifetime...");
|
||||
db.span_label(use_span, "...is used only here");
|
||||
let msg = "elide the single-use lifetime";
|
||||
let (use_span, replace_lt) = if elide {
|
||||
let use_span = sess.source_map().span_extend_while(
|
||||
use_span,
|
||||
char::is_whitespace,
|
||||
).unwrap_or(use_span);
|
||||
(use_span, String::new())
|
||||
} else {
|
||||
(use_span, "'_".to_owned())
|
||||
};
|
||||
db.multipart_suggestion(
|
||||
msg,
|
||||
vec![(deletion_span, String::new()), (use_span, replace_lt)],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
if let Some(deletion_span) = deletion_span {
|
||||
let msg = "elide the single-use lifetime";
|
||||
let (use_span, replace_lt) = if elide {
|
||||
let use_span = sess.source_map().span_extend_while(
|
||||
use_span,
|
||||
char::is_whitespace,
|
||||
).unwrap_or(use_span);
|
||||
(use_span, String::new())
|
||||
} else {
|
||||
(use_span, "'_".to_owned())
|
||||
};
|
||||
debug!(?deletion_span, ?use_span);
|
||||
db.multipart_suggestion(
|
||||
msg,
|
||||
vec![(deletion_span, String::new()), (use_span, replace_lt)],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
},
|
||||
BuiltinLintDiagnostics::SingleUseLifetime {
|
||||
param_span: _,
|
||||
|
@ -847,12 +850,14 @@ pub trait LintContext: Sized {
|
|||
deletion_span,
|
||||
} => {
|
||||
debug!(?deletion_span);
|
||||
db.span_suggestion(
|
||||
deletion_span,
|
||||
"elide the unused lifetime",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
if let Some(deletion_span) = deletion_span {
|
||||
db.span_suggestion(
|
||||
deletion_span,
|
||||
"elide the unused lifetime",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
},
|
||||
BuiltinLintDiagnostics::NamedArgumentUsedPositionally{ position_sp_to_replace, position_sp_for_msg, named_arg_sp, named_arg_name, is_formatting_arg} => {
|
||||
db.span_label(named_arg_sp, "this named argument is referred to by position in formatting string");
|
||||
|
|
|
@ -503,7 +503,7 @@ pub enum BuiltinLintDiagnostics {
|
|||
param_span: Span,
|
||||
/// Span of the code that should be removed when eliding this lifetime.
|
||||
/// This span should include leading or trailing comma.
|
||||
deletion_span: Span,
|
||||
deletion_span: Option<Span>,
|
||||
/// Span of the single use, or None if the lifetime is never used.
|
||||
/// If true, the lifetime will be fully elided.
|
||||
use_span: Option<(Span, bool)>,
|
||||
|
|
|
@ -2188,15 +2188,31 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
let deletion_span = || {
|
||||
if params.len() == 1 {
|
||||
// if sole lifetime, remove the entire `<>` brackets
|
||||
generics_span
|
||||
Some(generics_span)
|
||||
} else if param_index == 0 {
|
||||
// if removing within `<>` brackets, we also want to
|
||||
// delete a leading or trailing comma as appropriate
|
||||
param.span().to(params[param_index + 1].span().shrink_to_lo())
|
||||
match (
|
||||
param.span().find_ancestor_inside(generics_span),
|
||||
params[param_index + 1].span().find_ancestor_inside(generics_span),
|
||||
) {
|
||||
(Some(param_span), Some(next_param_span)) => {
|
||||
Some(param_span.to(next_param_span.shrink_to_lo()))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
// if removing within `<>` brackets, we also want to
|
||||
// delete a leading or trailing comma as appropriate
|
||||
params[param_index - 1].span().shrink_to_hi().to(param.span())
|
||||
match (
|
||||
param.span().find_ancestor_inside(generics_span),
|
||||
params[param_index - 1].span().find_ancestor_inside(generics_span),
|
||||
) {
|
||||
(Some(param_span), Some(prev_param_span)) => {
|
||||
Some(prev_param_span.shrink_to_hi().to(param_span))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
};
|
||||
match use_set {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue