Rollup merge of #79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings fix clippy::unnecessary_filter_map use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn) fix clippy::{needless_bool, manual_unwrap_or} don't clone types that are copy (clippy::clone_on_copy) don't convert types into identical types with .into() (clippy::useless_conversion) use strip_prefix over slicing (clippy::manual_strip) r? ``@Dylan-DPC``
This commit is contained in:
commit
1b81f08d4c
15 changed files with 70 additions and 86 deletions
|
@ -597,10 +597,7 @@ impl<'a> TraitDef<'a> {
|
||||||
|
|
||||||
let mut ty_params = params
|
let mut ty_params = params
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|param| match param.kind {
|
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type{..}))
|
||||||
ast::GenericParamKind::Type { .. } => Some(param),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
if ty_params.peek().is_some() {
|
if ty_params.peek().is_some() {
|
||||||
|
|
|
@ -854,8 +854,8 @@ fn generic_simd_intrinsic(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if name_str.starts_with("simd_shuffle") {
|
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
|
||||||
let n: u64 = name_str["simd_shuffle".len()..].parse().unwrap_or_else(|_| {
|
let n: u64 = stripped.parse().unwrap_or_else(|_| {
|
||||||
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
|
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -201,10 +201,10 @@ fn main() {
|
||||||
cmd.args(&components);
|
cmd.args(&components);
|
||||||
|
|
||||||
for lib in output(&mut cmd).split_whitespace() {
|
for lib in output(&mut cmd).split_whitespace() {
|
||||||
let name = if lib.starts_with("-l") {
|
let name = if let Some(stripped) = lib.strip_prefix("-l") {
|
||||||
&lib[2..]
|
stripped
|
||||||
} else if lib.starts_with('-') {
|
} else if let Some(stripped) = lib.strip_prefix('-') {
|
||||||
&lib[1..]
|
stripped
|
||||||
} else if Path::new(lib).exists() {
|
} else if Path::new(lib).exists() {
|
||||||
// On MSVC llvm-config will print the full name to libraries, but
|
// On MSVC llvm-config will print the full name to libraries, but
|
||||||
// we're only interested in the name part
|
// we're only interested in the name part
|
||||||
|
@ -241,17 +241,17 @@ fn main() {
|
||||||
cmd.arg(llvm_link_arg).arg("--ldflags");
|
cmd.arg(llvm_link_arg).arg("--ldflags");
|
||||||
for lib in output(&mut cmd).split_whitespace() {
|
for lib in output(&mut cmd).split_whitespace() {
|
||||||
if is_crossed {
|
if is_crossed {
|
||||||
if lib.starts_with("-LIBPATH:") {
|
if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
|
||||||
println!("cargo:rustc-link-search=native={}", lib[9..].replace(&host, &target));
|
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
|
||||||
} else if lib.starts_with("-L") {
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
||||||
println!("cargo:rustc-link-search=native={}", lib[2..].replace(&host, &target));
|
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
|
||||||
}
|
}
|
||||||
} else if lib.starts_with("-LIBPATH:") {
|
} else if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
|
||||||
println!("cargo:rustc-link-search=native={}", &lib[9..]);
|
println!("cargo:rustc-link-search=native={}", stripped);
|
||||||
} else if lib.starts_with("-l") {
|
} else if let Some(stripped) = lib.strip_prefix("-l") {
|
||||||
println!("cargo:rustc-link-lib={}", &lib[2..]);
|
println!("cargo:rustc-link-lib={}", stripped);
|
||||||
} else if lib.starts_with("-L") {
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
||||||
println!("cargo:rustc-link-search=native={}", &lib[2..]);
|
println!("cargo:rustc-link-search=native={}", stripped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,10 +262,10 @@ fn main() {
|
||||||
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
|
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
|
||||||
if let Some(s) = llvm_linker_flags {
|
if let Some(s) = llvm_linker_flags {
|
||||||
for lib in s.into_string().unwrap().split_whitespace() {
|
for lib in s.into_string().unwrap().split_whitespace() {
|
||||||
if lib.starts_with("-l") {
|
if let Some(stripped) = lib.strip_prefix("-l") {
|
||||||
println!("cargo:rustc-link-lib={}", &lib[2..]);
|
println!("cargo:rustc-link-lib={}", stripped);
|
||||||
} else if lib.starts_with("-L") {
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
||||||
println!("cargo:rustc-link-search=native={}", &lib[2..]);
|
println!("cargo:rustc-link-search=native={}", stripped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl DebugCounters {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
counters
|
counters
|
||||||
.insert(id.into(), DebugCounter::new(counter_kind.clone(), some_block_label))
|
.insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
|
||||||
.expect_none(
|
.expect_none(
|
||||||
"attempt to add the same counter_kind to DebugCounters more than once",
|
"attempt to add the same counter_kind to DebugCounters more than once",
|
||||||
);
|
);
|
||||||
|
@ -340,7 +340,7 @@ impl DebugCounters {
|
||||||
if self.some_counters.is_some() && (counter_format.block || !counter_format.id) {
|
if self.some_counters.is_some() && (counter_format.block || !counter_format.id) {
|
||||||
let counters = self.some_counters.as_ref().unwrap();
|
let counters = self.some_counters.as_ref().unwrap();
|
||||||
if let Some(DebugCounter { some_block_label: Some(block_label), .. }) =
|
if let Some(DebugCounter { some_block_label: Some(block_label), .. }) =
|
||||||
counters.get(&id.into())
|
counters.get(&id)
|
||||||
{
|
{
|
||||||
return if counter_format.id {
|
return if counter_format.id {
|
||||||
format!("{}#{}", block_label, id.index())
|
format!("{}#{}", block_label, id.index())
|
||||||
|
|
|
@ -216,9 +216,10 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
|
||||||
let discr = self.find_switch_discriminant_info(bb, switch)?;
|
let discr = self.find_switch_discriminant_info(bb, switch)?;
|
||||||
|
|
||||||
// go through each target, finding a discriminant read, and a switch
|
// go through each target, finding a discriminant read, and a switch
|
||||||
let results = discr.targets_with_values.iter().map(|(value, target)| {
|
let results = discr
|
||||||
self.find_discriminant_switch_pairing(&discr, target.clone(), value.clone())
|
.targets_with_values
|
||||||
});
|
.iter()
|
||||||
|
.map(|(value, target)| self.find_discriminant_switch_pairing(&discr, *target, *value));
|
||||||
|
|
||||||
// if the optimization did not apply for one of the targets, then abort
|
// if the optimization did not apply for one of the targets, then abort
|
||||||
if results.clone().any(|x| x.is_none()) || results.len() == 0 {
|
if results.clone().any(|x| x.is_none()) || results.len() == 0 {
|
||||||
|
|
|
@ -616,8 +616,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
debug!("stmt_expr Break val block_context.push(SubExpr)");
|
debug!("stmt_expr Break val block_context.push(SubExpr)");
|
||||||
self.block_context.push(BlockFrame::SubExpr);
|
self.block_context.push(BlockFrame::SubExpr);
|
||||||
unpack!(block = self.into(destination, dest_scope, block, value));
|
unpack!(block = self.into(destination, dest_scope, block, value));
|
||||||
dest_scope
|
if let Some(scope) = dest_scope {
|
||||||
.map(|scope| self.unschedule_drop(scope, destination.as_local().unwrap()));
|
self.unschedule_drop(scope, destination.as_local().unwrap())
|
||||||
|
};
|
||||||
self.block_context.pop();
|
self.block_context.pop();
|
||||||
} else {
|
} else {
|
||||||
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())
|
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())
|
||||||
|
|
|
@ -1109,10 +1109,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_dead_code(&self) -> bool {
|
pub fn link_dead_code(&self) -> bool {
|
||||||
match self.opts.cg.link_dead_code {
|
self.opts.cg.link_dead_code.unwrap_or(false)
|
||||||
Some(explicitly_set) => explicitly_set,
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_attr_known(&self, attr: &Attribute) {
|
pub fn mark_attr_known(&self, attr: &Attribute) {
|
||||||
|
|
|
@ -1448,31 +1448,30 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
typeck_results
|
if let Some(cause) = typeck_results
|
||||||
.generator_interior_types
|
.generator_interior_types
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
|
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
|
||||||
.map(|cause| {
|
{
|
||||||
// Check to see if any awaited expressions have the target type.
|
// Check to see if any awaited expressions have the target type.
|
||||||
let from_awaited_ty = visitor
|
let from_awaited_ty = visitor
|
||||||
.awaits
|
.awaits
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|id| hir.expect_expr(id))
|
.map(|id| hir.expect_expr(id))
|
||||||
.find(|await_expr| {
|
.find(|await_expr| {
|
||||||
let ty = typeck_results.expr_ty_adjusted(&await_expr);
|
let ty = typeck_results.expr_ty_adjusted(&await_expr);
|
||||||
debug!(
|
debug!(
|
||||||
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
|
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
|
||||||
await_expr
|
await_expr
|
||||||
);
|
);
|
||||||
ty_matches(ty)
|
ty_matches(ty)
|
||||||
})
|
})
|
||||||
.map(|expr| expr.span);
|
.map(|expr| expr.span);
|
||||||
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } =
|
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } = cause;
|
||||||
cause;
|
|
||||||
|
|
||||||
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
|
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
|
||||||
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
|
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
|
||||||
});
|
};
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"maybe_note_obligation_cause_for_async_await: interior_or_upvar={:?} \
|
"maybe_note_obligation_cause_for_async_await: interior_or_upvar={:?} \
|
||||||
|
|
|
@ -447,7 +447,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
nested.push(Obligation::new(
|
nested.push(Obligation::new(
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
obligation.param_env.clone(),
|
obligation.param_env,
|
||||||
normalized_super_trait,
|
normalized_super_trait,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
nested.push(Obligation::new(
|
nested.push(Obligation::new(
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
obligation.param_env.clone(),
|
obligation.param_env,
|
||||||
normalized_bound,
|
normalized_bound,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,17 +294,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
closure_captures.insert(*var_hir_id, upvar_id);
|
closure_captures.insert(*var_hir_id, upvar_id);
|
||||||
|
|
||||||
let new_capture_kind = if let Some(capture_kind) =
|
let new_capture_kind =
|
||||||
upvar_capture_map.get(&upvar_id)
|
if let Some(capture_kind) = upvar_capture_map.get(&upvar_id) {
|
||||||
{
|
// upvar_capture_map only stores the UpvarCapture (CaptureKind),
|
||||||
// upvar_capture_map only stores the UpvarCapture (CaptureKind),
|
// so we create a fake capture info with no expression.
|
||||||
// so we create a fake capture info with no expression.
|
let fake_capture_info =
|
||||||
let fake_capture_info =
|
ty::CaptureInfo { expr_id: None, capture_kind: *capture_kind };
|
||||||
ty::CaptureInfo { expr_id: None, capture_kind: capture_kind.clone() };
|
determine_capture_info(fake_capture_info, capture_info).capture_kind
|
||||||
determine_capture_info(fake_capture_info, capture_info).capture_kind
|
} else {
|
||||||
} else {
|
capture_info.capture_kind
|
||||||
capture_info.capture_kind
|
};
|
||||||
};
|
|
||||||
upvar_capture_map.insert(upvar_id, new_capture_kind);
|
upvar_capture_map.insert(upvar_id, new_capture_kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2141,13 +2141,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||||
// * It must be an associated type for this trait (*not* a
|
// * It must be an associated type for this trait (*not* a
|
||||||
// supertrait).
|
// supertrait).
|
||||||
if let ty::Projection(projection) = ty.kind() {
|
if let ty::Projection(projection) = ty.kind() {
|
||||||
if projection.substs == trait_identity_substs
|
projection.substs == trait_identity_substs
|
||||||
&& tcx.associated_item(projection.item_def_id).container.id() == def_id
|
&& tcx.associated_item(projection.item_def_id).container.id() == def_id
|
||||||
{
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1186,7 +1186,7 @@ pub fn sanitize_sh(path: &Path) -> String {
|
||||||
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
|
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
|
||||||
|
|
||||||
fn unc_to_lfs(s: &str) -> &str {
|
fn unc_to_lfs(s: &str) -> &str {
|
||||||
if s.starts_with("//?/") { &s[4..] } else { s }
|
s.strip_prefix("//?/").unwrap_or(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_drive(s: &str) -> Option<String> {
|
fn change_drive(s: &str) -> Option<String> {
|
||||||
|
|
|
@ -159,11 +159,7 @@ pub fn check(build: &mut Build) {
|
||||||
panic!("the iOS target is only supported on macOS");
|
panic!("the iOS target is only supported on macOS");
|
||||||
}
|
}
|
||||||
|
|
||||||
build
|
build.config.target_config.entry(*target).or_insert(Target::from_triple(&target.triple));
|
||||||
.config
|
|
||||||
.target_config
|
|
||||||
.entry(target.clone())
|
|
||||||
.or_insert(Target::from_triple(&target.triple));
|
|
||||||
|
|
||||||
if target.contains("-none-") || target.contains("nvptx") {
|
if target.contains("-none-") || target.contains("nvptx") {
|
||||||
if build.no_std(*target) == Some(false) {
|
if build.no_std(*target) == Some(false) {
|
||||||
|
@ -176,7 +172,7 @@ pub fn check(build: &mut Build) {
|
||||||
// If this is a native target (host is also musl) and no musl-root is given,
|
// If this is a native target (host is also musl) and no musl-root is given,
|
||||||
// fall back to the system toolchain in /usr before giving up
|
// fall back to the system toolchain in /usr before giving up
|
||||||
if build.musl_root(*target).is_none() && build.config.build == *target {
|
if build.musl_root(*target).is_none() && build.config.build == *target {
|
||||||
let target = build.config.target_config.entry(target.clone()).or_default();
|
let target = build.config.target_config.entry(*target).or_default();
|
||||||
target.musl_root = Some("/usr".into());
|
target.musl_root = Some("/usr".into());
|
||||||
}
|
}
|
||||||
match build.musl_libdir(*target) {
|
match build.musl_libdir(*target) {
|
||||||
|
|
|
@ -139,9 +139,9 @@ fn map_line(s: &str) -> Line<'_> {
|
||||||
let trimmed = s.trim();
|
let trimmed = s.trim();
|
||||||
if trimmed.starts_with("##") {
|
if trimmed.starts_with("##") {
|
||||||
Line::Shown(Cow::Owned(s.replacen("##", "#", 1)))
|
Line::Shown(Cow::Owned(s.replacen("##", "#", 1)))
|
||||||
} else if trimmed.starts_with("# ") {
|
} else if let Some(stripped) = trimmed.strip_prefix("# ") {
|
||||||
// # text
|
// # text
|
||||||
Line::Hidden(&trimmed[2..])
|
Line::Hidden(&stripped)
|
||||||
} else if trimmed == "#" {
|
} else if trimmed == "#" {
|
||||||
// We cannot handle '#text' because it could be #[attr].
|
// We cannot handle '#text' because it could be #[attr].
|
||||||
Line::Hidden("")
|
Line::Hidden("")
|
||||||
|
|
|
@ -1012,7 +1012,6 @@ impl LinkCollector<'_, '_> {
|
||||||
} else {
|
} else {
|
||||||
// This is a bug.
|
// This is a bug.
|
||||||
debug!("attempting to resolve item without parent module: {}", path_str);
|
debug!("attempting to resolve item without parent module: {}", path_str);
|
||||||
let err_kind = ResolutionFailure::NoParentItem.into();
|
|
||||||
resolution_failure(
|
resolution_failure(
|
||||||
self,
|
self,
|
||||||
&item,
|
&item,
|
||||||
|
@ -1020,7 +1019,7 @@ impl LinkCollector<'_, '_> {
|
||||||
disambiguator,
|
disambiguator,
|
||||||
dox,
|
dox,
|
||||||
link_range,
|
link_range,
|
||||||
smallvec![err_kind],
|
smallvec![ResolutionFailure::NoParentItem],
|
||||||
);
|
);
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue