mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
clippy::complexity fixes
filter_next needless_question_mark bind_instead_of_map manual_find derivable_impls map_identity redundant_slicing skip_while_next unnecessary_unwrap needless_bool
This commit is contained in:
parent
48b3c46126
commit
1da4a49912
@ -620,7 +620,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.impl_trait_defs = current_impl_trait_defs;
|
self.impl_trait_defs = current_impl_trait_defs;
|
||||||
self.impl_trait_bounds = current_impl_trait_bounds;
|
self.impl_trait_bounds = current_impl_trait_bounds;
|
||||||
|
|
||||||
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
|
debug_assert!(!self.children.iter().any(|(id, _)| id == &def_id));
|
||||||
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
|
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2059,12 +2059,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
) -> Option<InitIndex> {
|
) -> Option<InitIndex> {
|
||||||
let mpi = self.move_data.rev_lookup.find_local(local);
|
let mpi = self.move_data.rev_lookup.find_local(local);
|
||||||
let ii = &self.move_data.init_path_map[mpi];
|
let ii = &self.move_data.init_path_map[mpi];
|
||||||
for &index in ii {
|
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
|
||||||
if flow_state.ever_inits.contains(index) {
|
|
||||||
return Some(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the place into the used mutable variables set
|
/// Adds the place into the used mutable variables set
|
||||||
|
@ -233,8 +233,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||||||
// Set KCFI operand bundle
|
// Set KCFI operand bundle
|
||||||
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
|
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
|
||||||
let kcfi_bundle =
|
let kcfi_bundle =
|
||||||
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
|
if self.tcx.sess.is_sanitizer_kcfi_enabled() && let Some(fn_abi) = fn_abi && is_indirect_call {
|
||||||
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
|
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi);
|
||||||
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
|
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -123,7 +123,7 @@ fn try_filter_fat_archs<'a>(
|
|||||||
) -> io::Result<Option<(&'a [u8], u64)>> {
|
) -> io::Result<Option<(&'a [u8], u64)>> {
|
||||||
let archs = archs.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
let archs = archs.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||||
|
|
||||||
let desired = match archs.iter().filter(|a| a.architecture() == target_arch).next() {
|
let desired = match archs.iter().find(|a| a.architecture() == target_arch) {
|
||||||
Some(a) => a,
|
Some(a) => a,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
|
@ -1128,9 +1128,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hir = self.tcx.hir();
|
let hir = self.tcx.hir();
|
||||||
let cond_parent = hir.parent_iter(expr.hir_id).skip_while(|(_, node)| {
|
let cond_parent = hir.parent_iter(expr.hir_id).find(|(_, node)| {
|
||||||
matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
|
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
|
||||||
}).next();
|
});
|
||||||
// Don't suggest:
|
// Don't suggest:
|
||||||
// `let Some(_) = a.is_some() && b`
|
// `let Some(_) = a.is_some() && b`
|
||||||
// ++++++++++
|
// ++++++++++
|
||||||
|
@ -488,7 +488,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
// If this empty region is from a universe that can
|
// If this empty region is from a universe that can
|
||||||
// name the placeholder, then the placeholder is
|
// name the placeholder, then the placeholder is
|
||||||
// larger; otherwise, the only ancestor is `'static`.
|
// larger; otherwise, the only ancestor is `'static`.
|
||||||
if a_ui.can_name(placeholder.universe) { true } else { false }
|
return a_ui.can_name(placeholder.universe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,18 +87,12 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
|
|||||||
|
|
||||||
/// The combined undo log for all the various unification tables. For each change to the storage
|
/// The combined undo log for all the various unification tables. For each change to the storage
|
||||||
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
|
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub(crate) struct InferCtxtUndoLogs<'tcx> {
|
pub(crate) struct InferCtxtUndoLogs<'tcx> {
|
||||||
logs: Vec<UndoLog<'tcx>>,
|
logs: Vec<UndoLog<'tcx>>,
|
||||||
num_open_snapshots: usize,
|
num_open_snapshots: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InferCtxtUndoLogs<'_> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self { logs: Default::default(), num_open_snapshots: Default::default() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The UndoLogs trait defines how we undo a particular kind of action (of type T). We can undo any
|
/// The UndoLogs trait defines how we undo a particular kind of action (of type T). We can undo any
|
||||||
/// action that is convertible into an UndoLog (per the From impls above).
|
/// action that is convertible into an UndoLog (per the From impls above).
|
||||||
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>
|
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>
|
||||||
|
@ -103,12 +103,7 @@ impl EffectiveVisibilities {
|
|||||||
|
|
||||||
pub fn public_at_level(&self, id: LocalDefId) -> Option<Level> {
|
pub fn public_at_level(&self, id: LocalDefId) -> Option<Level> {
|
||||||
self.effective_vis(id).and_then(|effective_vis| {
|
self.effective_vis(id).and_then(|effective_vis| {
|
||||||
for level in Level::all_levels() {
|
Level::all_levels().into_iter().find(|&level| effective_vis.is_public_at_level(level))
|
||||||
if effective_vis.is_public_at_level(level) {
|
|
||||||
return Some(level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ fn replace_flattened_locals<'tcx>(
|
|||||||
let mut fragments = IndexVec::new();
|
let mut fragments = IndexVec::new();
|
||||||
for (k, v) in &replacements.fields {
|
for (k, v) in &replacements.fields {
|
||||||
fragments.ensure_contains_elem(k.local, || Vec::new());
|
fragments.ensure_contains_elem(k.local, || Vec::new());
|
||||||
fragments[k.local].push((&k.projection[..], *v));
|
fragments[k.local].push((k.projection, *v));
|
||||||
}
|
}
|
||||||
debug!(?fragments);
|
debug!(?fragments);
|
||||||
|
|
||||||
|
@ -595,8 +595,8 @@ fn check_recursion_limit<'tcx>(
|
|||||||
let def_path_str = tcx.def_path_str(def_id);
|
let def_path_str = tcx.def_path_str(def_id);
|
||||||
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
|
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
let was_written = if written_to_path.is_some() {
|
let was_written = if let Some(written_to_path) = written_to_path {
|
||||||
path = written_to_path.unwrap();
|
path = written_to_path;
|
||||||
Some(())
|
Some(())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -277,8 +277,7 @@ impl<'a> Parser<'a> {
|
|||||||
if let Some(arg) = args
|
if let Some(arg) = args
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.skip_while(|arg| matches!(arg, AngleBracketedArg::Constraint(_)))
|
.find(|arg| !matches!(arg, AngleBracketedArg::Constraint(_)))
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
arg.span().shrink_to_hi(),
|
arg.span().shrink_to_hi(),
|
||||||
|
@ -787,7 +787,6 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||||||
let mut dead_codes = dead_codes
|
let mut dead_codes = dead_codes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|v| !v.name.as_str().starts_with('_'))
|
.filter(|v| !v.name.as_str().starts_with('_'))
|
||||||
.map(|v| v)
|
|
||||||
.collect::<Vec<&DeadVariant>>();
|
.collect::<Vec<&DeadVariant>>();
|
||||||
if dead_codes.is_empty() {
|
if dead_codes.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -122,7 +122,7 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
|
|||||||
let target = crate::config::host_triple();
|
let target = crate::config::host_triple();
|
||||||
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
|
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
|
||||||
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
|
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
|
||||||
let path = current_dll_path().and_then(|s| Ok(s.canonicalize().map_err(|e| e.to_string())?));
|
let path = current_dll_path().and_then(|s| s.canonicalize().map_err(|e| e.to_string()));
|
||||||
if let Ok(dll) = path {
|
if let Ok(dll) = path {
|
||||||
// use `parent` twice to chop off the file name and then also the
|
// use `parent` twice to chop off the file name and then also the
|
||||||
// directory containing the dll which should be either `lib` or `bin`.
|
// directory containing the dll which should be either `lib` or `bin`.
|
||||||
@ -165,7 +165,7 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn default_from_rustc_driver_dll() -> Result<PathBuf, String> {
|
fn default_from_rustc_driver_dll() -> Result<PathBuf, String> {
|
||||||
let dll = current_dll_path().and_then(|s| Ok(canonicalize(s)))?;
|
let dll = current_dll_path().map(|s| canonicalize(s))?;
|
||||||
|
|
||||||
// `dll` will be in one of the following two:
|
// `dll` will be in one of the following two:
|
||||||
// - compiler's libdir: $sysroot/lib/*.dll
|
// - compiler's libdir: $sysroot/lib/*.dll
|
||||||
|
@ -99,13 +99,8 @@ fn is_c_void_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||||||
ty::Adt(adt_def, ..) => {
|
ty::Adt(adt_def, ..) => {
|
||||||
let def_id = adt_def.0.did;
|
let def_id = adt_def.0.did;
|
||||||
let crate_name = tcx.crate_name(def_id.krate);
|
let crate_name = tcx.crate_name(def_id.krate);
|
||||||
if tcx.item_name(def_id).as_str() == "c_void"
|
tcx.item_name(def_id).as_str() == "c_void"
|
||||||
&& (crate_name == sym::core || crate_name == sym::std || crate_name == sym::libc)
|
&& (crate_name == sym::core || crate_name == sym::std || crate_name == sym::libc)
|
||||||
{
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -267,8 +262,7 @@ fn encode_predicates<'tcx>(
|
|||||||
) -> String {
|
) -> String {
|
||||||
// <predicate1[..predicateN]>E as part of vendor extended type
|
// <predicate1[..predicateN]>E as part of vendor extended type
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> =
|
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates.iter().collect();
|
||||||
predicates.iter().map(|predicate| predicate).collect();
|
|
||||||
for predicate in predicates {
|
for predicate in predicates {
|
||||||
s.push_str(&encode_predicate(tcx, predicate, dict, options));
|
s.push_str(&encode_predicate(tcx, predicate, dict, options));
|
||||||
}
|
}
|
||||||
@ -322,7 +316,7 @@ fn encode_substs<'tcx>(
|
|||||||
) -> String {
|
) -> String {
|
||||||
// [I<subst1..substN>E] as part of vendor extended type
|
// [I<subst1..substN>E] as part of vendor extended type
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let substs: Vec<GenericArg<'_>> = substs.iter().map(|subst| subst).collect();
|
let substs: Vec<GenericArg<'_>> = substs.iter().collect();
|
||||||
if !substs.is_empty() {
|
if !substs.is_empty() {
|
||||||
s.push('I');
|
s.push('I');
|
||||||
for subst in substs {
|
for subst in substs {
|
||||||
@ -703,11 +697,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
|
|||||||
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
|
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
|
||||||
!is_zst
|
!is_zst
|
||||||
});
|
});
|
||||||
if field.is_none() {
|
if let Some(field) = field {
|
||||||
// Transform repr(transparent) types without non-ZST field into ()
|
let ty0 = tcx.type_of(field.did);
|
||||||
ty = tcx.mk_unit();
|
|
||||||
} else {
|
|
||||||
let ty0 = tcx.type_of(field.unwrap().did);
|
|
||||||
// Generalize any repr(transparent) user-defined type that is either a pointer
|
// Generalize any repr(transparent) user-defined type that is either a pointer
|
||||||
// or reference, and either references itself or any other type that contains or
|
// or reference, and either references itself or any other type that contains or
|
||||||
// references itself, to avoid a reference cycle.
|
// references itself, to avoid a reference cycle.
|
||||||
@ -720,6 +711,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
|
|||||||
} else {
|
} else {
|
||||||
ty = transform_ty(tcx, ty0, options);
|
ty = transform_ty(tcx, ty0, options);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Transform repr(transparent) types without non-ZST field into ()
|
||||||
|
ty = tcx.mk_unit();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options));
|
ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options));
|
||||||
|
@ -76,11 +76,7 @@ mod rustc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = if self.visibility(def_id).is_accessible_from(parent, *self) {
|
let ret: bool = self.visibility(def_id).is_accessible_from(parent, *self);
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
trace!(?ret, "ret");
|
trace!(?ret, "ret");
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user