Rollup merge of #69547 - matthiaskrgr:more_misc, r=Mark-Simulacrum
remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.
This commit is contained in:
commit
13e4c6c51f
@ -232,10 +232,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
// found type `()`
|
||||
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
|
||||
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
|
||||
if let Some(impl_item) = items
|
||||
.iter()
|
||||
.filter(|item| item.ident == trait_assoc_item.ident)
|
||||
.next()
|
||||
if let Some(impl_item) =
|
||||
items.iter().find(|item| item.ident == trait_assoc_item.ident)
|
||||
{
|
||||
cause.span = impl_item.span;
|
||||
cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
|
||||
@ -285,13 +283,11 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
{
|
||||
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
|
||||
.iter()
|
||||
.filter(|i| i.def_id == *item_def_id)
|
||||
.next()
|
||||
.find(|i| i.def_id == *item_def_id)
|
||||
.and_then(|trait_assoc_item| {
|
||||
items
|
||||
.iter()
|
||||
.filter(|i| i.ident == trait_assoc_item.ident)
|
||||
.next()
|
||||
.find(|i| i.ident == trait_assoc_item.ident)
|
||||
.map(|impl_item| (impl_item, trait_assoc_item))
|
||||
})
|
||||
{
|
||||
|
@ -689,11 +689,7 @@ pub trait BottomValue {
|
||||
/// 3. Override `join` to do the opposite from what it's doing now.
|
||||
#[inline]
|
||||
fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
|
||||
if Self::BOTTOM_VALUE == false {
|
||||
inout_set.union(in_set)
|
||||
} else {
|
||||
inout_set.intersect(in_set)
|
||||
}
|
||||
if !Self::BOTTOM_VALUE { inout_set.union(in_set) } else { inout_set.intersect(in_set) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn parse_stmt_item(&mut self, attrs: Vec<Attribute>) -> PResult<'a, Option<ast::Item>> {
|
||||
let old = mem::replace(&mut self.directory.ownership, DirectoryOwnership::UnownedViaBlock);
|
||||
let item = self.parse_item_common(attrs.clone(), false, true, |_| true)?;
|
||||
let item = self.parse_item_common(attrs, false, true, |_| true)?;
|
||||
self.directory.ownership = old;
|
||||
Ok(item)
|
||||
}
|
||||
|
@ -968,18 +968,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||
for missing in &self.missing_named_lifetime_spots {
|
||||
match missing {
|
||||
MissingLifetimeSpot::Generics(generics) => {
|
||||
let (span, sugg) = if let Some(param) = generics
|
||||
.params
|
||||
.iter()
|
||||
.filter(|p| match p.kind {
|
||||
let (span, sugg) = if let Some(param) =
|
||||
generics.params.iter().find(|p| match p.kind {
|
||||
hir::GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} => false,
|
||||
_ => true,
|
||||
})
|
||||
.next()
|
||||
{
|
||||
}) {
|
||||
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
|
||||
} else {
|
||||
(generics.span, format!("<{}>", lifetime_ref))
|
||||
@ -1053,25 +1049,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
};
|
||||
let suggest_new =
|
||||
|err: &mut DiagnosticBuilder<'_>, sugg: &str| {
|
||||
err.span_label(span, "expected named lifetime parameter");
|
||||
let suggest_new = |err: &mut DiagnosticBuilder<'_>, sugg: &str| {
|
||||
err.span_label(span, "expected named lifetime parameter");
|
||||
|
||||
for missing in self.missing_named_lifetime_spots.iter().rev() {
|
||||
let mut introduce_suggestion = vec![];
|
||||
let msg;
|
||||
let should_break;
|
||||
introduce_suggestion.push(match missing {
|
||||
for missing in self.missing_named_lifetime_spots.iter().rev() {
|
||||
let mut introduce_suggestion = vec![];
|
||||
let msg;
|
||||
let should_break;
|
||||
introduce_suggestion.push(match missing {
|
||||
MissingLifetimeSpot::Generics(generics) => {
|
||||
msg = "consider introducing a named lifetime parameter".to_string();
|
||||
should_break = true;
|
||||
if let Some(param) = generics.params.iter().filter(|p| match p.kind {
|
||||
if let Some(param) = generics.params.iter().find(|p| match p.kind {
|
||||
hir::GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} => false,
|
||||
_ => true,
|
||||
}).next() {
|
||||
}) {
|
||||
(param.span.shrink_to_lo(), "'a, ".to_string())
|
||||
} else {
|
||||
(generics.span, "<'a>".to_string())
|
||||
@ -1090,30 +1085,29 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||
(*span, span_type.suggestion("'a"))
|
||||
}
|
||||
});
|
||||
for param in params {
|
||||
if let Ok(snippet) =
|
||||
self.tcx.sess.source_map().span_to_snippet(param.span)
|
||||
{
|
||||
if snippet.starts_with("&") && !snippet.starts_with("&'") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[1..])));
|
||||
} else if snippet.starts_with("&'_ ") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[4..])));
|
||||
}
|
||||
for param in params {
|
||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span)
|
||||
{
|
||||
if snippet.starts_with("&") && !snippet.starts_with("&'") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[1..])));
|
||||
} else if snippet.starts_with("&'_ ") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[4..])));
|
||||
}
|
||||
}
|
||||
introduce_suggestion.push((span, sugg.to_string()));
|
||||
err.multipart_suggestion(
|
||||
&msg,
|
||||
introduce_suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if should_break {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
introduce_suggestion.push((span, sugg.to_string()));
|
||||
err.multipart_suggestion(
|
||||
&msg,
|
||||
introduce_suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if should_break {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match (
|
||||
lifetime_names.len(),
|
||||
|
@ -398,7 +398,7 @@ pub fn make_test(
|
||||
use rustc_span::source_map::FilePathMapping;
|
||||
|
||||
let filename = FileName::anon_source_code(s);
|
||||
let source = crates + &everything_else;
|
||||
let source = crates + everything_else;
|
||||
|
||||
// Any errors in parsing should also appear when the doctest is compiled for real, so just
|
||||
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
|
||||
|
Loading…
x
Reference in New Issue
Block a user