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