Skip to content

clippy::complexity fixes #116209

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
/// `read_discriminant` can be hooked for better error messages.
#[inline(always)]
fn read_discriminant(&mut self, v: &Self::V) -> InterpResult<'tcx, VariantIdx> {
Ok(self.ecx().read_discriminant(&v.to_op(self.ecx())?)?)
self.ecx().read_discriminant(&v.to_op(self.ecx())?)
}

/// This function provides the chance to reorder the order in which fields are visited for
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,8 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
let mut print_formatted = if pager_name == "less" {
cmd.arg("-r");
true
} else if ["bat", "catbat", "delta"].iter().any(|v| *v == pager_name) {
true
} else {
false
["bat", "catbat", "delta"].iter().any(|v| *v == pager_name)
};

if color == ColorConfig::Never {
Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1;
const DEP_NODE_WIDTH_BITS: usize = DEP_NODE_SIZE / 2;

/// Data for use when recompiling the **current crate**.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct SerializedDepGraph {
/// The set of all DepNodes in the graph
nodes: IndexVec<SerializedDepNodeIndex, DepNode>,
Expand All @@ -88,18 +88,6 @@ pub struct SerializedDepGraph {
index: Vec<UnhashMap<PackedFingerprint, SerializedDepNodeIndex>>,
}

impl Default for SerializedDepGraph {
fn default() -> Self {
SerializedDepGraph {
nodes: Default::default(),
fingerprints: Default::default(),
edge_list_indices: Default::default(),
edge_list_data: Default::default(),
index: Default::default(),
}
}
}

impl SerializedDepGraph {
#[inline]
pub fn edge_targets_from(
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
initial_binding.res()
});
let res = binding.res();
let has_ambiguity_error = this
.ambiguity_errors
.iter()
.filter(|error| !error.warning)
.next()
.is_some();
let has_ambiguity_error =
this.ambiguity_errors.iter().any(|error| !error.warning);
if res == Res::Err || has_ambiguity_error {
this.tcx
.sess
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>
let adt_has_dtor =
|adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
let res = drop_tys_helper(tcx, query.value, query.param_env, adt_has_dtor, false)
.filter(filter_array_elements(tcx, query.param_env))
.next()
.find(filter_array_elements(tcx, query.param_env))
.is_some();
Comment on lines +23 to 24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.find(filter_array_elements(tcx, query.param_env))
.is_some();
.any(filter_array_elements(tcx, query.param_env));


debug!("needs_drop_raw({:?}) = {:?}", query, res);
Expand Down Expand Up @@ -56,8 +55,7 @@ fn has_significant_drop_raw<'tcx>(
adt_consider_insignificant_dtor(tcx),
true,
)
.filter(filter_array_elements(tcx, query.param_env))
.next()
.find(filter_array_elements(tcx, query.param_env))
.is_some();
Comment on lines +58 to 59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.find(filter_array_elements(tcx, query.param_env))
.is_some();
.any(filter_array_elements(tcx, query.param_env));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0277]: expected a `std::ops::FnMut<(Result<rustc_middle::ty::Ty<'tcx>, AlwaysRequiresDrop>,)>` closure, found `impl for<'a> Fn(&'a Result<rustc_middle::ty::Ty<'_>, AlwaysRequiresDrop>) -> bool`
    --> compiler/rustc_ty_utils/src/needs_drop.rs:58:10
     |
58   |     .any(filter_array_elements(tcx, query.param_env));
     |      --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut<(Result<rustc_middle::ty::Ty<'tcx>, AlwaysRequiresDrop>,)>` closure, found `impl for<'a> Fn(&'a Result<rustc_middle::ty::Ty<'_>, AlwaysRequiresDrop>) -> bool`
     |      |
     |      required by a bound introduced by this call
     |
     = help: the trait `std::ops::FnMut<(Result<rustc_middle::ty::Ty<'tcx>, AlwaysRequiresDrop>,)>` is not implemented for `impl for<'a> Fn(&'a Result<rustc_middle::ty::Ty<'_>, AlwaysRequiresDrop>) -> bool`
     = note: expected a closure with arguments `(&Result<rustc_middle::ty::Ty<'_>, AlwaysRequiresDrop>,)`
                found a closure with arguments `(Result<rustc_middle::ty::Ty<'tcx>, AlwaysRequiresDrop>,)`
note: required by a bound in `std::iter::Iterator::any`
    --> /home/matthias/vcs/github/rust/library/core/src/iter/traits/iterator.rs:2857:12
     |
2854 |     fn any<F>(&mut self, f: F) -> bool
     |        --- required by a bound in this associated function
...
2857 |         F: FnMut(Self::Item) -> bool,
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::any`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to fix it by introducing a closure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, just edit the signature of filter_array_elements to take a Result<Ty<'tcx>, NeedsDrop> rather than a &Result<..>?

debug!("has_significant_drop_raw({:?}) = {:?}", query, res);
res
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ fn first_non_private<'tcx>(
path: &hir::Path<'tcx>,
) -> Option<Path> {
let target_def_id = path.res.opt_def_id()?;
let (parent_def_id, ident) = match &path.segments[..] {
let (parent_def_id, ident) = match &path.segments {
[] => return None,
// Relative paths are available in the same scope as the owner.
[leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit("/").filter(|c| !c.is_empty()).next().unwrap());
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit("/").find(|c| !c.is_empty()).unwrap());

/// Render a sequence of macro arms in a format suitable for displaying to the user
/// as part of an item declaration.
Expand Down