Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clippy::toplevel_ref_arg and ::manual_map #110404

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,9 @@ impl<K: Eq + Hash, V> SsoHashMap<K, 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),
}
}
Expand Down
39 changes: 16 additions & 23 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,20 +636,14 @@ trait UnusedDelimLint {
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,
};
Expand Down Expand Up @@ -928,11 +922,10 @@ impl UnusedParens {
// 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);
}
}
Expand Down Expand Up @@ -1043,11 +1036,11 @@ impl EarlyLintPass for UnusedParens {
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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/const_prop_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
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);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl<'a> Parser<'a> {
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;
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,15 +1867,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
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 {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,10 +1663,11 @@ impl SourceFile {

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))))
}
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,8 @@ impl SourceMap {

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 {
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_trait_selection/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/structural_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
/// 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);
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,13 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
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)
}
}
Expand Down