deindent unsized suggestions
Move stuff out of loops. Use early returns.
This commit is contained in:
parent
437b2026e1
commit
69f0dc69a4
@ -1803,20 +1803,24 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
Some(generics) => generics,
|
||||
None => return,
|
||||
};
|
||||
debug!("suggest_unsized_bound_if_applicable: generics.params={:?}", generics.params);
|
||||
debug!(
|
||||
"suggest_unsized_bound_if_applicable: generics.where_clause={:?}",
|
||||
generics.where_clause
|
||||
);
|
||||
for param in generics.params {
|
||||
if param.span != span
|
||||
|| param.bounds.iter().any(|bound| {
|
||||
bound.trait_ref().and_then(|trait_ref| trait_ref.trait_def_id())
|
||||
== self.tcx.lang_items().sized_trait()
|
||||
let sized_trait = self.tcx.lang_items().sized_trait();
|
||||
debug!("maybe_suggest_unsized_generics: generics.params={:?}", generics.params);
|
||||
debug!("maybe_suggest_unsized_generics: generics.where_clause={:?}", generics.where_clause);
|
||||
let param = generics
|
||||
.params
|
||||
.iter()
|
||||
.filter(|param| param.span == span)
|
||||
.filter(|param| {
|
||||
param
|
||||
.bounds
|
||||
.iter()
|
||||
.all(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) != sized_trait)
|
||||
})
|
||||
{
|
||||
continue;
|
||||
}
|
||||
.next();
|
||||
let param = match param {
|
||||
Some(param) => param,
|
||||
_ => return,
|
||||
};
|
||||
debug!("maybe_suggest_unsized_generics: param={:?}", param);
|
||||
match node {
|
||||
hir::Node::Item(
|
||||
@ -1824,9 +1828,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
@
|
||||
hir::Item {
|
||||
kind:
|
||||
hir::ItemKind::Enum(..)
|
||||
| hir::ItemKind::Struct(..)
|
||||
| hir::ItemKind::Union(..),
|
||||
hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Union(..),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
@ -1835,7 +1837,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
let (span, separator) = match param.bounds {
|
||||
[] => (span.shrink_to_hi(), ":"),
|
||||
[.., bound] => (bound.span().shrink_to_hi(), " +"),
|
||||
@ -1846,8 +1848,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
format!("{} ?Sized", separator),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_indirection_for_unsized(
|
||||
@ -1862,7 +1862,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let mut visitor =
|
||||
FindTypeParam { param: param.name.ident().name, invalid_spans: vec![], nested: false };
|
||||
visitor.visit_item(item);
|
||||
if !visitor.invalid_spans.is_empty() {
|
||||
if visitor.invalid_spans.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let mut multispan: MultiSpan = param.span.into();
|
||||
multispan.push_span_label(
|
||||
param.span,
|
||||
@ -1882,9 +1884,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
T = param.name.ident(),
|
||||
),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
true
|
||||
}
|
||||
|
||||
fn is_recursive_obligation(
|
||||
|
Loading…
x
Reference in New Issue
Block a user