Rollup merge of #110404 - matthiaskrgr:mapmap, r=Nilstrieb
fix clippy::toplevel_ref_arg and ::manual_map r? ``@Nilstrieb``
This commit is contained in:
commit
1795bf8222
@ -141,13 +141,7 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
|
||||
args: args
|
||||
.named_args()
|
||||
.iter()
|
||||
.filter_map(|a| {
|
||||
if let Some(ident) = a.kind.ident() {
|
||||
Some((a, ident))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
|
||||
.map(|(arg, n)| n.span.to(arg.expr.span))
|
||||
.collect(),
|
||||
});
|
||||
|
@ -256,12 +256,9 @@ pub fn insert(&mut self, key: K, value: V) -> Option<V> {
|
||||
pub fn remove(&mut self, key: &K) -> Option<V> {
|
||||
match self {
|
||||
SsoHashMap::Array(array) => {
|
||||
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
|
||||
Some(array.swap_remove(index).1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
|
||||
}
|
||||
|
||||
SsoHashMap::Map(map) => map.remove(key),
|
||||
}
|
||||
}
|
||||
|
@ -636,20 +636,14 @@ fn visit_expr(&mut self, expr: &'ast ast::Expr) {
|
||||
return;
|
||||
}
|
||||
let spans = match value.kind {
|
||||
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
|
||||
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
|
||||
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => block.stmts[0]
|
||||
.span
|
||||
.find_ancestor_inside(value.span)
|
||||
.map(|span| (value.span.with_hi(span.lo()), value.span.with_lo(span.hi()))),
|
||||
ast::ExprKind::Paren(ref expr) => {
|
||||
let expr_span = expr.span.find_ancestor_inside(value.span);
|
||||
if let Some(expr_span) = expr_span {
|
||||
Some((value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi())))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
expr.span.find_ancestor_inside(value.span).map(|expr_span| {
|
||||
(value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi()))
|
||||
})
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
@ -928,11 +922,10 @@ fn check_unused_parens_pat(
|
||||
// Otherwise proceed with linting.
|
||||
_ => {}
|
||||
}
|
||||
let spans = if let Some(inner) = inner.span.find_ancestor_inside(value.span) {
|
||||
Some((value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let spans = inner
|
||||
.span
|
||||
.find_ancestor_inside(value.span)
|
||||
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
|
||||
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space);
|
||||
}
|
||||
}
|
||||
@ -1043,11 +1036,11 @@ fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
||||
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
|
||||
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
|
||||
_ => {
|
||||
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
|
||||
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let spans = r
|
||||
.span
|
||||
.find_ancestor_inside(ty.span)
|
||||
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));
|
||||
|
||||
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ fn check_assertion(
|
||||
cond: &Operand<'tcx>,
|
||||
location: Location,
|
||||
) -> Option<!> {
|
||||
let ref value = self.eval_operand(&cond, location)?;
|
||||
let value = &self.eval_operand(&cond, location)?;
|
||||
trace!("assertion on {:?} should be {:?}", value, expected);
|
||||
|
||||
let expected = Scalar::from_bool(expected);
|
||||
|
@ -45,10 +45,10 @@ pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
|
||||
Some(InnerAttrForbiddenReason::AfterOuterDocComment {
|
||||
prev_doc_comment_span: prev_outer_attr_sp.unwrap(),
|
||||
})
|
||||
} else if let Some(prev_outer_attr_sp) = prev_outer_attr_sp {
|
||||
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp })
|
||||
} else {
|
||||
None
|
||||
prev_outer_attr_sp.map(|prev_outer_attr_sp| {
|
||||
InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }
|
||||
})
|
||||
};
|
||||
let inner_parse_policy = InnerAttrPolicy::Forbidden(inner_error_reason);
|
||||
just_parsed_doc_comment = false;
|
||||
|
@ -1869,15 +1869,13 @@ pub(crate) fn report_path_resolution_error(
|
||||
Some(LexicalScopeBinding::Item(name_binding)) => Some(name_binding.span),
|
||||
_ => None,
|
||||
};
|
||||
let suggestion = if let Some(span) = match_span {
|
||||
Some((
|
||||
let suggestion = match_span.map(|span| {
|
||||
(
|
||||
vec![(span, String::from(""))],
|
||||
format!("`{}` is defined here, but is not a type", ident),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
)
|
||||
});
|
||||
|
||||
(format!("use of undeclared type `{}`", ident), suggestion)
|
||||
} else {
|
||||
|
@ -1663,10 +1663,11 @@ fn get_until_newline(src: &str, begin: usize) -> &str {
|
||||
|
||||
if let Some(ref src) = self.src {
|
||||
Some(Cow::from(get_until_newline(src, begin)))
|
||||
} else if let Some(src) = self.external_src.borrow().get_source() {
|
||||
Some(Cow::Owned(String::from(get_until_newline(src, begin))))
|
||||
} else {
|
||||
None
|
||||
self.external_src
|
||||
.borrow()
|
||||
.get_source()
|
||||
.map(|src| Cow::Owned(String::from(get_until_newline(src, begin))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -906,10 +906,8 @@ pub fn start_point(&self, sp: Span) -> Span {
|
||||
|
||||
let snippet = if let Some(ref src) = local_begin.sf.src {
|
||||
Some(&src[start_index..])
|
||||
} else if let Some(src) = src.get_source() {
|
||||
Some(&src[start_index..])
|
||||
} else {
|
||||
None
|
||||
src.get_source().map(|src| &src[start_index..])
|
||||
};
|
||||
|
||||
match snippet {
|
||||
|
@ -243,16 +243,11 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
|
||||
) -> Option<usize> {
|
||||
// Count number of methods preceding the one we are selecting and
|
||||
// add them to the total offset.
|
||||
if let Some(index) = tcx
|
||||
.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
|
||||
tcx.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
|
||||
.iter()
|
||||
.copied()
|
||||
.position(|def_id| def_id == method_def_id)
|
||||
{
|
||||
Some(object.vtable_base + index)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.map(|index| object.vtable_base + index)
|
||||
}
|
||||
|
||||
pub fn closure_trait_ref_and_return_type<'tcx>(
|
||||
|
@ -234,15 +234,12 @@ fn resolve_associated_item<'tcx>(
|
||||
_ => None,
|
||||
},
|
||||
traits::ImplSource::Object(ref data) => {
|
||||
if let Some(index) = traits::get_vtable_index_of_object_method(tcx, data, trait_item_id)
|
||||
{
|
||||
Some(Instance {
|
||||
traits::get_vtable_index_of_object_method(tcx, data, trait_item_id).map(|index| {
|
||||
Instance {
|
||||
def: ty::InstanceDef::Virtual(trait_item_id, index),
|
||||
substs: rcvr_substs,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
traits::ImplSource::Builtin(..) => {
|
||||
let lang_items = tcx.lang_items();
|
||||
|
@ -13,7 +13,7 @@
|
||||
/// Note that this does *not* recursively check if the substructure of `adt_ty`
|
||||
/// implements the traits.
|
||||
fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool {
|
||||
let ref infcx = tcx.infer_ctxt().build();
|
||||
let infcx = &tcx.infer_ctxt().build();
|
||||
let cause = ObligationCause::dummy();
|
||||
|
||||
let ocx = ObligationCtxt::new(infcx);
|
||||
|
@ -300,14 +300,13 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
|
||||
ParentStackItem::Impl { for_, .. } => for_.def_id(&self.cache),
|
||||
ParentStackItem::Type(item_id) => item_id.as_def_id(),
|
||||
};
|
||||
let path = match did.and_then(|did| self.cache.paths.get(&did)) {
|
||||
let path = did
|
||||
.and_then(|did| self.cache.paths.get(&did))
|
||||
// The current stack not necessarily has correlation
|
||||
// for where the type was defined. On the other
|
||||
// hand, `paths` always has the right
|
||||
// information if present.
|
||||
Some((fqp, _)) => Some(&fqp[..fqp.len() - 1]),
|
||||
None => None,
|
||||
};
|
||||
.map(|(fqp, _)| &fqp[..fqp.len() - 1]);
|
||||
((did, path), true)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user