Move report_elision_failure in diagnostics.rs.
This commit is contained in:
parent
207c80f105
commit
c44e93086d
2 changed files with 83 additions and 82 deletions
|
@ -1871,6 +1871,85 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether to add `'static` lifetime to the suggested lifetime list.
|
||||||
|
crate fn report_elision_failure(
|
||||||
|
&mut self,
|
||||||
|
db: &mut DiagnosticBuilder<'_>,
|
||||||
|
params: &[ElisionFailureInfo],
|
||||||
|
) -> bool {
|
||||||
|
let mut m = String::new();
|
||||||
|
let len = params.len();
|
||||||
|
|
||||||
|
let elided_params: Vec<_> =
|
||||||
|
params.iter().cloned().filter(|info| info.lifetime_count > 0).collect();
|
||||||
|
|
||||||
|
let elided_len = elided_params.len();
|
||||||
|
|
||||||
|
for (i, info) in elided_params.into_iter().enumerate() {
|
||||||
|
let ElisionFailureInfo { parent, index, lifetime_count: n, have_bound_regions, span } =
|
||||||
|
info;
|
||||||
|
|
||||||
|
db.span_label(span, "");
|
||||||
|
let help_name = if let Some(ident) =
|
||||||
|
parent.and_then(|body| self.tcx.hir().body(body).params[index].pat.simple_ident())
|
||||||
|
{
|
||||||
|
format!("`{}`", ident)
|
||||||
|
} else {
|
||||||
|
format!("argument {}", index + 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
m.push_str(
|
||||||
|
&(if n == 1 {
|
||||||
|
help_name
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"one of {}'s {} {}lifetimes",
|
||||||
|
help_name,
|
||||||
|
n,
|
||||||
|
if have_bound_regions { "free " } else { "" }
|
||||||
|
)
|
||||||
|
})[..],
|
||||||
|
);
|
||||||
|
|
||||||
|
if elided_len == 2 && i == 0 {
|
||||||
|
m.push_str(" or ");
|
||||||
|
} else if i + 2 == elided_len {
|
||||||
|
m.push_str(", or ");
|
||||||
|
} else if i != elided_len - 1 {
|
||||||
|
m.push_str(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len == 0 {
|
||||||
|
db.help(
|
||||||
|
"this function's return type contains a borrowed value, \
|
||||||
|
but there is no value for it to be borrowed from",
|
||||||
|
);
|
||||||
|
true
|
||||||
|
} else if elided_len == 0 {
|
||||||
|
db.help(
|
||||||
|
"this function's return type contains a borrowed value with \
|
||||||
|
an elided lifetime, but the lifetime cannot be derived from \
|
||||||
|
the arguments",
|
||||||
|
);
|
||||||
|
true
|
||||||
|
} else if elided_len == 1 {
|
||||||
|
db.help(&format!(
|
||||||
|
"this function's return type contains a borrowed value, \
|
||||||
|
but the signature does not say which {} it is borrowed from",
|
||||||
|
m
|
||||||
|
));
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
db.help(&format!(
|
||||||
|
"this function's return type contains a borrowed value, \
|
||||||
|
but the signature does not say whether it is borrowed from {}",
|
||||||
|
m
|
||||||
|
));
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const
|
// FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const
|
||||||
// generics. We are disallowing this until we can decide on how we want to handle non-'static
|
// generics. We are disallowing this until we can decide on how we want to handle non-'static
|
||||||
// lifetimes in const generics. See issue #74052 for discussion.
|
// lifetimes in const generics. See issue #74052 for discussion.
|
||||||
|
|
|
@ -357,11 +357,11 @@ enum Elide {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct ElisionFailureInfo {
|
crate struct ElisionFailureInfo {
|
||||||
/// Where we can find the argument pattern.
|
/// Where we can find the argument pattern.
|
||||||
parent: Option<hir::BodyId>,
|
crate parent: Option<hir::BodyId>,
|
||||||
/// The index of the argument in the original definition.
|
/// The index of the argument in the original definition.
|
||||||
index: usize,
|
crate index: usize,
|
||||||
lifetime_count: usize,
|
crate lifetime_count: usize,
|
||||||
have_bound_regions: bool,
|
crate have_bound_regions: bool,
|
||||||
crate span: Span,
|
crate span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3166,84 +3166,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_elision_failure(
|
|
||||||
&mut self,
|
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
|
||||||
params: &[ElisionFailureInfo],
|
|
||||||
) -> bool /* add `'static` lifetime to lifetime list */ {
|
|
||||||
let mut m = String::new();
|
|
||||||
let len = params.len();
|
|
||||||
|
|
||||||
let elided_params: Vec<_> =
|
|
||||||
params.iter().cloned().filter(|info| info.lifetime_count > 0).collect();
|
|
||||||
|
|
||||||
let elided_len = elided_params.len();
|
|
||||||
|
|
||||||
for (i, info) in elided_params.into_iter().enumerate() {
|
|
||||||
let ElisionFailureInfo { parent, index, lifetime_count: n, have_bound_regions, span } =
|
|
||||||
info;
|
|
||||||
|
|
||||||
db.span_label(span, "");
|
|
||||||
let help_name = if let Some(ident) =
|
|
||||||
parent.and_then(|body| self.tcx.hir().body(body).params[index].pat.simple_ident())
|
|
||||||
{
|
|
||||||
format!("`{}`", ident)
|
|
||||||
} else {
|
|
||||||
format!("argument {}", index + 1)
|
|
||||||
};
|
|
||||||
|
|
||||||
m.push_str(
|
|
||||||
&(if n == 1 {
|
|
||||||
help_name
|
|
||||||
} else {
|
|
||||||
format!(
|
|
||||||
"one of {}'s {} {}lifetimes",
|
|
||||||
help_name,
|
|
||||||
n,
|
|
||||||
if have_bound_regions { "free " } else { "" }
|
|
||||||
)
|
|
||||||
})[..],
|
|
||||||
);
|
|
||||||
|
|
||||||
if elided_len == 2 && i == 0 {
|
|
||||||
m.push_str(" or ");
|
|
||||||
} else if i + 2 == elided_len {
|
|
||||||
m.push_str(", or ");
|
|
||||||
} else if i != elided_len - 1 {
|
|
||||||
m.push_str(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len == 0 {
|
|
||||||
db.help(
|
|
||||||
"this function's return type contains a borrowed value, \
|
|
||||||
but there is no value for it to be borrowed from",
|
|
||||||
);
|
|
||||||
true
|
|
||||||
} else if elided_len == 0 {
|
|
||||||
db.help(
|
|
||||||
"this function's return type contains a borrowed value with \
|
|
||||||
an elided lifetime, but the lifetime cannot be derived from \
|
|
||||||
the arguments",
|
|
||||||
);
|
|
||||||
true
|
|
||||||
} else if elided_len == 1 {
|
|
||||||
db.help(&format!(
|
|
||||||
"this function's return type contains a borrowed value, \
|
|
||||||
but the signature does not say which {} it is borrowed from",
|
|
||||||
m
|
|
||||||
));
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
db.help(&format!(
|
|
||||||
"this function's return type contains a borrowed value, \
|
|
||||||
but the signature does not say whether it is borrowed from {}",
|
|
||||||
m
|
|
||||||
));
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
|
fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
|
||||||
debug!("resolve_object_lifetime_default(lifetime_ref={:?})", lifetime_ref);
|
debug!("resolve_object_lifetime_default(lifetime_ref={:?})", lifetime_ref);
|
||||||
let mut late_depth = 0;
|
let mut late_depth = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue