Simplify some nested if statements

This commit is contained in:
Michael Goulet 2024-09-11 13:32:53 -04:00
parent 5a2dd7d4f3
commit 954419aab0
36 changed files with 340 additions and 380 deletions

View file

@ -95,19 +95,19 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
// Check for assignment to fields of a constant
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
// so emitting a lint would be redundant.
if !lhs.projection.is_empty() {
if let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
&& let Some((lint_root, span, item)) =
self.should_lint_const_item_usage(lhs, def_id, loc)
{
self.tcx.emit_node_span_lint(
CONST_ITEM_MUTATION,
lint_root,
span,
errors::ConstMutate::Modify { konst: item },
);
}
if !lhs.projection.is_empty()
&& let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
&& let Some((lint_root, span, item)) =
self.should_lint_const_item_usage(lhs, def_id, loc)
{
self.tcx.emit_node_span_lint(
CONST_ITEM_MUTATION,
lint_root,
span,
errors::ConstMutate::Modify { konst: item },
);
}
// We are looking for MIR of the form:
//
// ```

View file

@ -168,17 +168,16 @@ pub(super) fn deduced_param_attrs<'tcx>(
// Codegen won't use this information for anything if all the function parameters are passed
// directly. Detect that and bail, for compilation speed.
let fn_ty = tcx.type_of(def_id).instantiate_identity();
if matches!(fn_ty.kind(), ty::FnDef(..)) {
if fn_ty
if matches!(fn_ty.kind(), ty::FnDef(..))
&& fn_ty
.fn_sig(tcx)
.inputs()
.skip_binder()
.iter()
.cloned()
.all(type_will_always_be_passed_directly)
{
return &[];
}
{
return &[];
}
// Don't deduce any attributes for functions that have no MIR.

View file

@ -378,19 +378,19 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
if let (Some(l), Some(r)) = (l, r)
&& l.layout.ty.is_integral()
&& op.is_overflowing()
{
if self.use_ecx(|this| {
&& self.use_ecx(|this| {
let (_res, overflow) = this.ecx.binary_op(op, &l, &r)?.to_scalar_pair();
overflow.to_bool()
})? {
self.report_assert_as_lint(
location,
AssertLintKind::ArithmeticOverflow,
AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()),
);
return None;
}
})?
{
self.report_assert_as_lint(
location,
AssertLintKind::ArithmeticOverflow,
AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()),
);
return None;
}
Some(())
}