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

collaps if x {} else { if .. } conditions #80793

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
26 changes: 12 additions & 14 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,20 @@ fn parse_args<'a>(
err.emit();
}
args.named_args.insert(name, slot);
} else {
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
let mut err = ecx.struct_span_err(
span,
"positional arguments cannot follow named arguments \
} else if !args.named_args.is_empty() || !args.reg_args.is_empty() {
let mut err = ecx.struct_span_err(
span,
"positional arguments cannot follow named arguments \
or explicit register arguments",
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix indentation

);
err.span_label(span, "positional argument");
for pos in args.named_args.values() {
err.span_label(args.operands[*pos].1, "named argument");
}
for pos in &args.reg_args {
err.span_label(args.operands[*pos].1, "explicit register argument");
}
err.emit();
);
err.span_label(span, "positional argument");
for pos in args.named_args.values() {
err.span_label(args.operands[*pos].1, "named argument");
}
for pos in &args.reg_args {
err.span_label(args.operands[*pos].1, "explicit register argument");
}
err.emit();
}
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,8 @@ fn add_late_link_args(
if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) {
cmd.args(args);
}
} else {
if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
cmd.args(args);
}
} else if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
cmd.args(args);
}
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I feel like this change is hiding intent - previously the code was pretty clearly handling the dynamic and non-dynamic cases, but now it is less obvious IMO, at least for me.

if let Some(args) = sess.target.late_link_args.get(&flavor) {
cmd.args(args);
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
if size != cx.data_layout().pointer_size {
// *Now*, we better make sure that the inside is free of relocations too.
self.check_relocations(cx, ptr, size)?;
} else {
if let Some(&(tag, alloc_id)) = self.relocations.get(&ptr.offset) {
let ptr = Pointer::new_with_tag(alloc_id, Size::from_bytes(bits), tag);
return Ok(ScalarMaybeUninit::Scalar(ptr.into()));
}
} else if let Some(&(tag, alloc_id)) = self.relocations.get(&ptr.offset) {
let ptr = Pointer::new_with_tag(alloc_id, Size::from_bytes(bits), tag);
return Ok(ScalarMaybeUninit::Scalar(ptr.into()));
}
// We don't. Just return the bits.
Ok(ScalarMaybeUninit::Scalar(Scalar::from_uint(bits, size)))
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
} else {
ct
}
} else if !ct.has_vars_bound_at_or_above(self.current_index) {
// Nothing more to substitute.
ct
} else {
if !ct.has_vars_bound_at_or_above(self.current_index) {
// Nothing more to substitute.
ct
} else {
ct.super_fold_with(self)
}
ct.super_fold_with(self)
}
}
}
Expand Down
46 changes: 22 additions & 24 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2532,31 +2532,29 @@ fn fn_can_unwind(
} else if codegen_fn_attr_flags.contains(CodegenFnAttrFlags::RUSTC_ALLOCATOR_NOUNWIND) {
// Special attribute for allocator functions, which can't unwind.
false
} else if call_conv == Conv::Rust {
// Any Rust method (or `extern "Rust" fn` or `extern
// "rust-call" fn`) is explicitly allowed to unwind
// (unless it has no-unwind attribute, handled above).
true
} else {
if call_conv == Conv::Rust {
// Any Rust method (or `extern "Rust" fn` or `extern
// "rust-call" fn`) is explicitly allowed to unwind
// (unless it has no-unwind attribute, handled above).
true
} else {
// Anything else is either:
//
// 1. A foreign item using a non-Rust ABI (like `extern "C" { fn foo(); }`), or
//
// 2. A Rust item using a non-Rust ABI (like `extern "C" fn foo() { ... }`).
//
// Foreign items (case 1) are assumed to not unwind; it is
// UB otherwise. (At least for now; see also
// rust-lang/rust#63909 and Rust RFC 2753.)
//
// Items defined in Rust with non-Rust ABIs (case 2) are also
// not supposed to unwind. Whether this should be enforced
// (versus stating it is UB) and *how* it would be enforced
// is currently under discussion; see rust-lang/rust#58794.
//
// In either case, we mark item as explicitly nounwind.
false
}
// Anything else is either:
//
// 1. A foreign item using a non-Rust ABI (like `extern "C" { fn foo(); }`), or
//
// 2. A Rust item using a non-Rust ABI (like `extern "C" fn foo() { ... }`).
//
// Foreign items (case 1) are assumed to not unwind; it is
// UB otherwise. (At least for now; see also
// rust-lang/rust#63909 and Rust RFC 2753.)
//
// Items defined in Rust with non-Rust ABIs (case 2) are also
// not supposed to unwind. Whether this should be enforced
// (versus stating it is UB) and *how* it would be enforced
// is currently under discussion; see rust-lang/rust#58794.
//
// In either case, we mark item as explicitly nounwind.
false
}
}

Expand Down
119 changes: 57 additions & 62 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,87 +168,82 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
partially_str, move_msg
),
);
} else {
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } =
move_spans
{
let place_name = self
.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(|| "value".to_owned());
match kind {
FnSelfUseKind::FnOnceCall => {
} else if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } =
move_spans
{
let place_name = self
.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(|| "value".to_owned());
match kind {
FnSelfUseKind::FnOnceCall => {
err.span_label(
fn_call_span,
&format!("{} {}moved due to this call", place_name, partially_str),
);
err.span_note(
var_span,
"this value implements `FnOnce`, which causes it to be moved when called",
);
}
FnSelfUseKind::Operator { self_arg } => {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to usage in operator",
place_name, partially_str
),
);
if self.fn_self_span_reported.insert(fn_span) {
err.span_note(
self_arg.span,
"calling this operator moves the left-hand side",
);
}
}
FnSelfUseKind::Normal { self_arg, implicit_into_iter } => {
if implicit_into_iter {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this call",
"{} {}moved due to this implicit call to `.into_iter()`",
place_name, partially_str
),
);
err.span_note(
var_span,
"this value implements `FnOnce`, which causes it to be moved when called",
);
}
FnSelfUseKind::Operator { self_arg } => {
} else {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to usage in operator",
"{} {}moved due to this method call",
place_name, partially_str
),
);
if self.fn_self_span_reported.insert(fn_span) {
err.span_note(
self_arg.span,
"calling this operator moves the left-hand side",
);
}
}
FnSelfUseKind::Normal { self_arg, implicit_into_iter } => {
if implicit_into_iter {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this implicit call to `.into_iter()`",
place_name, partially_str
),
);
} else {
err.span_label(
fn_call_span,
&format!(
"{} {}moved due to this method call",
place_name, partially_str
),
);
}
// Avoid pointing to the same function in multiple different
// error messages
if self.fn_self_span_reported.insert(self_arg.span) {
err.span_note(
// Avoid pointing to the same function in multiple different
// error messages
if self.fn_self_span_reported.insert(self_arg.span) {
err.span_note(
self_arg.span,
&format!("this function consumes the receiver `self` by taking ownership of it, which moves {}", place_name)
);
}
}
// Deref::deref takes &self, which cannot cause a move
FnSelfUseKind::DerefCoercion { .. } => unreachable!(),
}
} else {
err.span_label(
move_span,
format!("value {}moved{} here", partially_str, move_msg),
);
move_spans.var_span_label(
&mut err,
format!(
"variable {}moved due to use{}",
partially_str,
move_spans.describe()
),
);
// Deref::deref takes &self, which cannot cause a move
FnSelfUseKind::DerefCoercion { .. } => unreachable!(),
}
} else {
err.span_label(
move_span,
format!("value {}moved{} here", partially_str, move_msg),
);
move_spans.var_span_label(
&mut err,
format!(
"variable {}moved due to use{}",
partially_str,
move_spans.describe()
),
);
}
if let UseSpans::PatUse(span) = move_spans {
err.span_suggestion_verbose(
Expand Down
32 changes: 15 additions & 17 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
buf.push('*');
buf.push_str(&name);
}
} else if autoderef {
// FIXME turn this recursion into iteration
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
} else {
if autoderef {
// FIXME turn this recursion into iteration
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
} else {
buf.push('*');
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
}
buf.push('*');
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
}
}
ProjectionElem::Downcast(..) => {
Expand Down
28 changes: 10 additions & 18 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,16 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
let promoted_ty = promoted_body.return_ty();
check_err(self, promoted_body, ty, promoted_ty);
}
} else {
if let Err(terr) = self.cx.fully_perform_op(
location.to_locations(),
ConstraintCategory::Boring,
self.cx.param_env.and(type_op::ascribe_user_type::AscribeUserType::new(
constant.literal.ty,
def.did,
UserSubsts { substs, user_self_ty: None },
)),
) {
span_mirbug!(
self,
constant,
"bad constant type {:?} ({:?})",
constant,
terr
);
}
} else if let Err(terr) = self.cx.fully_perform_op(
location.to_locations(),
ConstraintCategory::Boring,
self.cx.param_env.and(type_op::ascribe_user_type::AscribeUserType::new(
constant.literal.ty,
def.did,
UserSubsts { substs, user_self_ty: None },
)),
) {
span_mirbug!(self, constant, "bad constant type {:?} ({:?})", constant, terr);
}
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
let unnormalized_ty = tcx.type_of(static_def_id);
Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_mir/src/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,15 +1220,13 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
msg,
);
}
} else {
if self.should_const_prop(value) {
if let ScalarMaybeUninit::Scalar(scalar) = value_const {
*cond = self.operand_from_scalar(
scalar,
self.tcx.types.bool,
source_info.span,
);
}
} else if self.should_const_prop(value) {
if let ScalarMaybeUninit::Scalar(scalar) = value_const {
*cond = self.operand_from_scalar(
scalar,
self.tcx.types.bool,
source_info.span,
);
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,12 @@ impl Inliner<'tcx> {
if let attr::InlineAttr::Always = codegen_fn_attrs.inline {
debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost);
true
} else if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
true
} else {
if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
true
} else {
debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
false
}
debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
false
}
}

Expand Down
Loading