Skip to content

Commit af8d911

Browse files
Also fix if in else
1 parent 954419a commit af8d911

File tree

27 files changed

+222
-290
lines changed

27 files changed

+222
-290
lines changed

compiler/rustc_ast/src/entry.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,16 @@ pub fn entry_point_type(
4545
EntryPointType::Start
4646
} else if attr::contains_name(attrs, sym::rustc_main) {
4747
EntryPointType::RustcMainAttr
48-
} else {
49-
if let Some(name) = name
50-
&& name == sym::main
51-
{
52-
if at_root {
53-
// This is a top-level function so it can be `main`.
54-
EntryPointType::MainNamed
55-
} else {
56-
EntryPointType::OtherMain
57-
}
48+
} else if let Some(name) = name
49+
&& name == sym::main
50+
{
51+
if at_root {
52+
// This is a top-level function so it can be `main`.
53+
EntryPointType::MainNamed
5854
} else {
59-
EntryPointType::None
55+
EntryPointType::OtherMain
6056
}
57+
} else {
58+
EntryPointType::None
6159
}
6260
}

compiler/rustc_ast_lowering/src/item.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
628628
.map_or(Const::No, |attr| Const::Yes(attr.span)),
629629
_ => Const::No,
630630
}
631+
} else if self.tcx.is_const_trait(def_id) {
632+
// FIXME(effects) span
633+
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
631634
} else {
632-
if self.tcx.is_const_trait(def_id) {
633-
// FIXME(effects) span
634-
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
635-
} else {
636-
Const::No
637-
}
635+
Const::No
638636
}
639637
} else {
640638
Const::No

compiler/rustc_borrowck/src/region_infer/values.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ impl LivenessValues {
118118
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
119119
if let Some(points) = &mut self.points {
120120
points.insert(region, point);
121-
} else {
122-
if self.elements.point_in_range(point) {
123-
self.live_regions.as_mut().unwrap().insert(region);
124-
}
121+
} else if self.elements.point_in_range(point) {
122+
self.live_regions.as_mut().unwrap().insert(region);
125123
}
126124

127125
// When available, record the loans flowing into this region as live at the given point.
@@ -137,10 +135,8 @@ impl LivenessValues {
137135
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
138136
if let Some(this) = &mut self.points {
139137
this.union_row(region, points);
140-
} else {
141-
if points.iter().any(|point| self.elements.point_in_range(point)) {
142-
self.live_regions.as_mut().unwrap().insert(region);
143-
}
138+
} else if points.iter().any(|point| self.elements.point_in_range(point)) {
139+
self.live_regions.as_mut().unwrap().insert(region);
144140
}
145141

146142
// When available, record the loans flowing into this region as live at the given points.

compiler/rustc_builtin_macros/src/asm.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,11 @@ pub fn parse_asm_args<'a>(
234234
continue;
235235
}
236236
args.named_args.insert(name, slot);
237-
} else {
238-
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
239-
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
240-
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
237+
} else if !args.named_args.is_empty() || !args.reg_args.is_empty() {
238+
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
239+
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
241240

242-
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
243-
}
241+
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
244242
}
245243
}
246244

compiler/rustc_codegen_ssa/src/back/link.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,10 @@ pub fn each_linked_rlib(
281281
let used_crate_source = &info.used_crate_source[&cnum];
282282
if let Some((path, _)) = &used_crate_source.rlib {
283283
f(cnum, path);
284+
} else if used_crate_source.rmeta.is_some() {
285+
return Err(errors::LinkRlibError::OnlyRmetaFound { crate_name });
284286
} else {
285-
if used_crate_source.rmeta.is_some() {
286-
return Err(errors::LinkRlibError::OnlyRmetaFound { crate_name });
287-
} else {
288-
return Err(errors::LinkRlibError::NotFound { crate_name });
289-
}
287+
return Err(errors::LinkRlibError::NotFound { crate_name });
290288
}
291289
}
292290
Ok(())
@@ -628,12 +626,10 @@ fn link_staticlib(
628626
let used_crate_source = &codegen_results.crate_info.used_crate_source[&cnum];
629627
if let Some((path, _)) = &used_crate_source.dylib {
630628
all_rust_dylibs.push(&**path);
629+
} else if used_crate_source.rmeta.is_some() {
630+
sess.dcx().emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name });
631631
} else {
632-
if used_crate_source.rmeta.is_some() {
633-
sess.dcx().emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name });
634-
} else {
635-
sess.dcx().emit_fatal(errors::LinkRlibError::NotFound { crate_name });
636-
}
632+
sess.dcx().emit_fatal(errors::LinkRlibError::NotFound { crate_name });
637633
}
638634
}
639635

@@ -1972,10 +1968,8 @@ fn add_late_link_args(
19721968
if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) {
19731969
cmd.verbatim_args(args.iter().map(Deref::deref));
19741970
}
1975-
} else {
1976-
if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
1977-
cmd.verbatim_args(args.iter().map(Deref::deref));
1978-
}
1971+
} else if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
1972+
cmd.verbatim_args(args.iter().map(Deref::deref));
19791973
}
19801974
if let Some(args) = sess.target.late_link_args.get(&flavor) {
19811975
cmd.verbatim_args(args.iter().map(Deref::deref));
@@ -2635,10 +2629,8 @@ fn add_native_libs_from_crate(
26352629
if link_static {
26362630
cmd.link_staticlib_by_name(name, verbatim, false);
26372631
}
2638-
} else {
2639-
if link_dynamic {
2640-
cmd.link_dylib_by_name(name, verbatim, true);
2641-
}
2632+
} else if link_dynamic {
2633+
cmd.link_dylib_by_name(name, verbatim, true);
26422634
}
26432635
}
26442636
NativeLibKind::Framework { as_needed } => {

compiler/rustc_codegen_ssa/src/back/linker.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -791,14 +791,12 @@ impl<'a> Linker for GccLinker<'a> {
791791
self.link_arg("-exported_symbols_list").link_arg(path);
792792
} else if self.sess.target.is_like_solaris {
793793
self.link_arg("-M").link_arg(path);
794+
} else if is_windows {
795+
self.link_arg(path);
794796
} else {
795-
if is_windows {
796-
self.link_arg(path);
797-
} else {
798-
let mut arg = OsString::from("--version-script=");
799-
arg.push(path);
800-
self.link_arg(arg).link_arg("--no-undefined-version");
801-
}
797+
let mut arg = OsString::from("--version-script=");
798+
arg.push(path);
799+
self.link_arg(arg).link_arg("--no-undefined-version");
802800
}
803801
}
804802

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,13 @@ fn push_debuginfo_type_name<'tcx>(
236236
let has_enclosing_parens = if cpp_like_debuginfo {
237237
output.push_str("dyn$<");
238238
false
239+
} else if trait_data.len() > 1 && auto_traits.len() != 0 {
240+
// We need enclosing parens because there is more than one trait
241+
output.push_str("(dyn ");
242+
true
239243
} else {
240-
if trait_data.len() > 1 && auto_traits.len() != 0 {
241-
// We need enclosing parens because there is more than one trait
242-
output.push_str("(dyn ");
243-
true
244-
} else {
245-
output.push_str("dyn ");
246-
false
247-
}
244+
output.push_str("dyn ");
245+
false
248246
};
249247

250248
if let Some(principal) = trait_data.principal() {

compiler/rustc_hir_analysis/src/check/check.rs

+30-32
Original file line numberDiff line numberDiff line change
@@ -1151,42 +1151,40 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
11511151
"type has conflicting packed and align representation hints"
11521152
)
11531153
.emit();
1154-
} else {
1155-
if let Some(def_spans) = check_packed_inner(tcx, def.did(), &mut vec![]) {
1156-
let mut err = struct_span_code_err!(
1157-
tcx.dcx(),
1158-
sp,
1159-
E0588,
1160-
"packed type cannot transitively contain a `#[repr(align)]` type"
1161-
);
1154+
} else if let Some(def_spans) = check_packed_inner(tcx, def.did(), &mut vec![]) {
1155+
let mut err = struct_span_code_err!(
1156+
tcx.dcx(),
1157+
sp,
1158+
E0588,
1159+
"packed type cannot transitively contain a `#[repr(align)]` type"
1160+
);
11621161

1163-
err.span_note(
1164-
tcx.def_span(def_spans[0].0),
1165-
format!("`{}` has a `#[repr(align)]` attribute", tcx.item_name(def_spans[0].0)),
1166-
);
1162+
err.span_note(
1163+
tcx.def_span(def_spans[0].0),
1164+
format!("`{}` has a `#[repr(align)]` attribute", tcx.item_name(def_spans[0].0)),
1165+
);
11671166

1168-
if def_spans.len() > 2 {
1169-
let mut first = true;
1170-
for (adt_def, span) in def_spans.iter().skip(1).rev() {
1171-
let ident = tcx.item_name(*adt_def);
1172-
err.span_note(
1173-
*span,
1174-
if first {
1175-
format!(
1176-
"`{}` contains a field of type `{}`",
1177-
tcx.type_of(def.did()).instantiate_identity(),
1178-
ident
1179-
)
1180-
} else {
1181-
format!("...which contains a field of type `{ident}`")
1182-
},
1183-
);
1184-
first = false;
1185-
}
1167+
if def_spans.len() > 2 {
1168+
let mut first = true;
1169+
for (adt_def, span) in def_spans.iter().skip(1).rev() {
1170+
let ident = tcx.item_name(*adt_def);
1171+
err.span_note(
1172+
*span,
1173+
if first {
1174+
format!(
1175+
"`{}` contains a field of type `{}`",
1176+
tcx.type_of(def.did()).instantiate_identity(),
1177+
ident
1178+
)
1179+
} else {
1180+
format!("...which contains a field of type `{ident}`")
1181+
},
1182+
);
1183+
first = false;
11861184
}
1187-
1188-
err.emit();
11891185
}
1186+
1187+
err.emit();
11901188
}
11911189
}
11921190
}

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -381,24 +381,22 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
381381
}
382382

383383
mir_opaque_ty.ty
384+
} else if let Some(guar) = tables.tainted_by_errors {
385+
// Some error in the owner fn prevented us from populating
386+
// the `concrete_opaque_types` table.
387+
Ty::new_error(tcx, guar)
384388
} else {
385-
if let Some(guar) = tables.tainted_by_errors {
386-
// Some error in the owner fn prevented us from populating
387-
// the `concrete_opaque_types` table.
388-
Ty::new_error(tcx, guar)
389+
// Fall back to the RPIT we inferred during HIR typeck
390+
if let Some(hir_opaque_ty) = hir_opaque_ty {
391+
hir_opaque_ty.ty
389392
} else {
390-
// Fall back to the RPIT we inferred during HIR typeck
391-
if let Some(hir_opaque_ty) = hir_opaque_ty {
392-
hir_opaque_ty.ty
393-
} else {
394-
// We failed to resolve the opaque type or it
395-
// resolves to itself. We interpret this as the
396-
// no values of the hidden type ever being constructed,
397-
// so we can just make the hidden type be `!`.
398-
// For backwards compatibility reasons, we fall back to
399-
// `()` until we the diverging default is changed.
400-
Ty::new_diverging_default(tcx)
401-
}
393+
// We failed to resolve the opaque type or it
394+
// resolves to itself. We interpret this as the
395+
// no values of the hidden type ever being constructed,
396+
// so we can just make the hidden type be `!`.
397+
// For backwards compatibility reasons, we fall back to
398+
// `()` until we the diverging default is changed.
399+
Ty::new_diverging_default(tcx)
402400
}
403401
}
404402
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
562562
tcx.const_param_default(param.def_id)
563563
.instantiate(tcx, preceding_args)
564564
.into()
565+
} else if infer_args {
566+
self.lowerer.ct_infer(Some(param), self.span).into()
565567
} else {
566-
if infer_args {
567-
self.lowerer.ct_infer(Some(param), self.span).into()
568-
} else {
569-
// We've already errored above about the mismatch.
570-
ty::Const::new_misc_error(tcx).into()
571-
}
568+
// We've already errored above about the mismatch.
569+
ty::Const::new_misc_error(tcx).into()
572570
}
573571
}
574572
}

compiler/rustc_hir_typeck/src/expr.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -2902,21 +2902,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29022902
candidate_fields.iter().map(|path| format!("{unwrap}{path}")),
29032903
Applicability::MaybeIncorrect,
29042904
);
2905-
} else {
2906-
if let Some(field_name) = find_best_match_for_name(&field_names, field.name, None) {
2907-
err.span_suggestion_verbose(
2908-
field.span,
2909-
"a field with a similar name exists",
2910-
format!("{unwrap}{}", field_name),
2911-
Applicability::MaybeIncorrect,
2912-
);
2913-
} else if !field_names.is_empty() {
2914-
let is = if field_names.len() == 1 { " is" } else { "s are" };
2915-
err.note(format!(
2916-
"available field{is}: {}",
2917-
self.name_series_display(field_names),
2918-
));
2919-
}
2905+
} else if let Some(field_name) =
2906+
find_best_match_for_name(&field_names, field.name, None)
2907+
{
2908+
err.span_suggestion_verbose(
2909+
field.span,
2910+
"a field with a similar name exists",
2911+
format!("{unwrap}{}", field_name),
2912+
Applicability::MaybeIncorrect,
2913+
);
2914+
} else if !field_names.is_empty() {
2915+
let is = if field_names.len() == 1 { " is" } else { "s are" };
2916+
err.note(
2917+
format!("available field{is}: {}", self.name_series_display(field_names),),
2918+
);
29202919
}
29212920
}
29222921
err

compiler/rustc_hir_typeck/src/gather_locals.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
158158
),
159159
);
160160
}
161-
} else {
162-
if !self.fcx.tcx.features().unsized_locals {
163-
self.fcx.require_type_is_sized(
164-
var_ty,
165-
p.span,
166-
ObligationCauseCode::VariableType(p.hir_id),
167-
);
168-
}
161+
} else if !self.fcx.tcx.features().unsized_locals {
162+
self.fcx.require_type_is_sized(
163+
var_ty,
164+
p.span,
165+
ObligationCauseCode::VariableType(p.hir_id),
166+
);
169167
}
170168

171169
debug!(

compiler/rustc_incremental/src/persist/dirty_clean.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,10 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
417417
fn expect_associated_value(tcx: TyCtxt<'_>, item: &NestedMetaItem) -> Symbol {
418418
if let Some(value) = item.value_str() {
419419
value
420+
} else if let Some(ident) = item.ident() {
421+
tcx.dcx().emit_fatal(errors::AssociatedValueExpectedFor { span: item.span(), ident });
420422
} else {
421-
if let Some(ident) = item.ident() {
422-
tcx.dcx().emit_fatal(errors::AssociatedValueExpectedFor { span: item.span(), ident });
423-
} else {
424-
tcx.dcx().emit_fatal(errors::AssociatedValueExpected { span: item.span() });
425-
}
423+
tcx.dcx().emit_fatal(errors::AssociatedValueExpected { span: item.span() });
426424
}
427425
}
428426

0 commit comments

Comments
 (0)