Skip to content

Commit eb6da16

Browse files
committed
Patch the compiler
Some of the changes may be unnecessary / can be done in the macro def, rather than usage. However: I do not care anymore.
1 parent 7777bdd commit eb6da16

File tree

15 files changed

+48
-61
lines changed

15 files changed

+48
-61
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
174174
return Ok(&info_data[offset..(offset + len)]);
175175
} else {
176176
return Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"));
177-
};
177+
}
178178
}
179179

180180
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
275275
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
276276
if let ty::InstanceDef::Intrinsic(def_id) = key.value.instance.def {
277277
let ty = key.value.instance.ty(tcx, key.param_env);
278-
let ty::FnDef(_, args) = ty.kind() else {
279-
bug!("intrinsic with type {:?}", ty);
280-
};
278+
let ty::FnDef(_, args) = ty.kind() else { bug!("intrinsic with type {:?}", ty) };
281279
return eval_nullary_intrinsic(tcx, key.param_env, def_id, args).map_err(|error| {
282280
let span = tcx.def_span(def_id);
283281

compiler/rustc_const_eval/src/interpret/validity.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
476476
Some(CtfeValidationMode::Const { .. }) => {
477477
// We can't recursively validate `extern static`, so we better reject them.
478478
if self.ecx.tcx.is_foreign_item(did) {
479-
throw_validation_failure!(self.path, ConstRefToExtern);
479+
throw_validation_failure!(self.path, ConstRefToExtern)
480480
}
481481
}
482482
None => {}
@@ -518,14 +518,14 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
518518
if ptr_expected_mutbl == Mutability::Mut
519519
&& alloc_actual_mutbl == Mutability::Not
520520
{
521-
throw_validation_failure!(self.path, MutableRefToImmutable);
521+
throw_validation_failure!(self.path, MutableRefToImmutable)
522522
}
523523
// In a const, everything must be completely immutable.
524524
if matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. })) {
525525
if ptr_expected_mutbl == Mutability::Mut
526526
|| alloc_actual_mutbl == Mutability::Mut
527527
{
528-
throw_validation_failure!(self.path, ConstRefToMutable);
528+
throw_validation_failure!(self.path, ConstRefToMutable)
529529
}
530530
}
531531
}
@@ -621,7 +621,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
621621
} else {
622622
// Otherwise (for standalone Miri), we have to still check it to be non-null.
623623
if self.ecx.scalar_may_be_null(value)? {
624-
throw_validation_failure!(self.path, NullFnPtr);
624+
throw_validation_failure!(self.path, NullFnPtr)
625625
}
626626
}
627627
Ok(true)
@@ -786,7 +786,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
786786
if self.ctfe_mode.is_some_and(|c| !c.allow_immutable_unsafe_cell()) {
787787
if !op.layout.is_zst() && !op.layout.ty.is_freeze(*self.ecx.tcx, self.ecx.param_env) {
788788
if !self.in_mutable_memory(op) {
789-
throw_validation_failure!(self.path, UnsafeCellInImmutable);
789+
throw_validation_failure!(self.path, UnsafeCellInImmutable)
790790
}
791791
}
792792
}
@@ -819,7 +819,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
819819
&& def.is_unsafe_cell()
820820
{
821821
if !self.in_mutable_memory(op) {
822-
throw_validation_failure!(self.path, UnsafeCellInImmutable);
822+
throw_validation_failure!(self.path, UnsafeCellInImmutable)
823823
}
824824
}
825825
}
@@ -934,7 +934,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
934934
match op.layout.abi {
935935
Abi::Uninhabited => {
936936
let ty = op.layout.ty;
937-
throw_validation_failure!(self.path, UninhabitedVal { ty });
937+
throw_validation_failure!(self.path, UninhabitedVal { ty })
938938
}
939939
Abi::Scalar(scalar_layout) => {
940940
if !scalar_layout.is_uninit_valid() {

compiler/rustc_driver_impl/src/lib.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -642,21 +642,19 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
642642
});
643643
let (codegen_results, outputs) = match CodegenResults::deserialize_rlink(sess, rlink_data) {
644644
Ok((codegen, outputs)) => (codegen, outputs),
645-
Err(err) => {
646-
match err {
647-
CodegenErrors::WrongFileType => dcx.emit_fatal(RLinkWrongFileType),
648-
CodegenErrors::EmptyVersionNumber => dcx.emit_fatal(RLinkEmptyVersionNumber),
649-
CodegenErrors::EncodingVersionMismatch { version_array, rlink_version } => sess
650-
.dcx()
651-
.emit_fatal(RLinkEncodingVersionMismatch { version_array, rlink_version }),
652-
CodegenErrors::RustcVersionMismatch { rustc_version } => {
653-
dcx.emit_fatal(RLinkRustcVersionMismatch {
654-
rustc_version,
655-
current_version: sess.cfg_version,
656-
})
657-
}
658-
};
659-
}
645+
Err(err) => match err {
646+
CodegenErrors::WrongFileType => dcx.emit_fatal(RLinkWrongFileType),
647+
CodegenErrors::EmptyVersionNumber => dcx.emit_fatal(RLinkEmptyVersionNumber),
648+
CodegenErrors::EncodingVersionMismatch { version_array, rlink_version } => sess
649+
.dcx()
650+
.emit_fatal(RLinkEncodingVersionMismatch { version_array, rlink_version }),
651+
CodegenErrors::RustcVersionMismatch { rustc_version } => {
652+
dcx.emit_fatal(RLinkRustcVersionMismatch {
653+
rustc_version,
654+
current_version: sess.cfg_version,
655+
})
656+
}
657+
},
660658
};
661659
if compiler.codegen_backend.link(sess, codegen_results, &outputs).is_err() {
662660
FatalError.raise();

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
125125
.filter(|arg| arg.is_ty_or_const())
126126
.position(|arg| arg.hir_id() == hir_id)
127127
})
128-
.unwrap_or_else(|| {
129-
bug!("no arg matching AnonConst in segment");
130-
});
128+
.unwrap_or_else(|| bug!("no arg matching AnonConst in segment"));
131129

132130
(generics, arg_index)
133131
} else {
@@ -164,9 +162,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
164162
.filter(|arg| arg.is_ty_or_const())
165163
.position(|arg| arg.hir_id() == hir_id)
166164
})
167-
.unwrap_or_else(|| {
168-
bug!("no arg matching AnonConst in segment");
169-
});
165+
.unwrap_or_else(|| bug!("no arg matching AnonConst in segment"));
170166

171167
(tcx.generics_of(type_dependent_def), idx)
172168
}

compiler/rustc_hir_typeck/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,8 @@ pub struct EnclosingBreakables<'tcx> {
344344

345345
impl<'tcx> EnclosingBreakables<'tcx> {
346346
fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'tcx> {
347-
self.opt_find_breakable(target_id).unwrap_or_else(|| {
348-
bug!("could not find enclosing breakable with id {}", target_id);
349-
})
347+
self.opt_find_breakable(target_id)
348+
.unwrap_or_else(|| bug!("could not find enclosing breakable with id {}", target_id))
350349
}
351350

352351
fn opt_find_breakable(&mut self, target_id: hir::HirId) -> Option<&mut BreakableCtxt<'tcx>> {

compiler/rustc_lint/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
11181118
WrappingRange { start, end } => {
11191119
unreachable!("Unhandled start and end range: ({}, {})", start, end)
11201120
}
1121-
};
1121+
}
11221122
}
11231123
}
11241124
None

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl DiagnosticDeriveVariantBuilder {
152152

153153
if let SubdiagnosticKind::MultipartSuggestion { .. } = subdiag.kind {
154154
throw_invalid_attr!(attr, |diag| diag
155-
.help("consider creating a `Subdiagnostic` instead"));
155+
.help("consider creating a `Subdiagnostic` instead"))
156156
}
157157

158158
let slug = subdiag.slug.unwrap_or_else(|| match subdiag.kind {
@@ -238,7 +238,7 @@ impl DiagnosticDeriveVariantBuilder {
238238
}
239239
SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => {
240240
throw_invalid_attr!(attr, |diag| diag
241-
.help("`#[label]` and `#[suggestion]` can only be applied to fields"));
241+
.help("`#[label]` and `#[suggestion]` can only be applied to fields"))
242242
}
243243
SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(),
244244
}
@@ -373,7 +373,7 @@ impl DiagnosticDeriveVariantBuilder {
373373
.note("`#[suggestion(...)]` applied to `Vec` field is ambiguous")
374374
.help("to show a suggestion consisting of multiple parts, use a `Subdiagnostic` annotated with `#[multipart_suggestion(...)]`")
375375
.help("to show a variable set of suggestions, use a `Vec` of `Subdiagnostic`s annotated with `#[suggestion(...)]`")
376-
});
376+
})
377377
}
378378

379379
let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?;
@@ -458,15 +458,13 @@ impl DiagnosticDeriveVariantBuilder {
458458
} else if type_matches_path(elem, &["rustc_errors", "Applicability"]) {
459459
applicability_idx.set_once(syn::Index::from(idx), elem.span().unwrap());
460460
} else {
461-
type_err(&elem.span())?;
461+
type_err(&elem.span())?
462462
}
463463
}
464464

465-
let Some((span_idx, _)) = span_idx else {
466-
type_err(&tup.span())?;
467-
};
465+
let Some((span_idx, _)) = span_idx else { type_err(&tup.span())? };
468466
let Some((applicability_idx, applicability_span)) = applicability_idx else {
469-
type_err(&tup.span())?;
467+
type_err(&tup.span())?
470468
};
471469
let binding = &info.binding.binding;
472470
let span = quote!(#binding.#span_idx);

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
205205
format!(
206206
"diagnostic slug must be first argument of a `#[{name}(...)]` attribute"
207207
)
208-
);
208+
)
209209
};
210210

211211
kind_slugs.push((kind, slug, no_span));
@@ -327,7 +327,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
327327
} else {
328328
diag
329329
}
330-
});
330+
})
331331
}
332332

333333
self.span_field.set_once(binding, span);
@@ -489,7 +489,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
489489
throw_span_err!(
490490
self.variant.ast().ident.span().unwrap(),
491491
"subdiagnostic kind not specified"
492-
);
492+
)
493493
}
494494
};
495495

compiler/rustc_macros/src/diagnostics/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub(crate) fn report_type_error(
7777
},
7878
ty_name
7979
)
80-
);
80+
)
8181
}
8282

8383
/// Reports an error if the field's type does not match `path`.
@@ -88,7 +88,7 @@ fn report_error_if_not_applied_to_ty(
8888
ty_name: &str,
8989
) -> Result<(), DiagnosticDeriveError> {
9090
if !type_matches_path(info.ty.inner_type(), path) {
91-
report_type_error(attr, ty_name)?;
91+
report_type_error(attr, ty_name)?
9292
}
9393

9494
Ok(())
@@ -115,7 +115,7 @@ pub(crate) fn report_error_if_not_applied_to_span(
115115
if !type_matches_path(info.ty.inner_type(), &["rustc_span", "Span"])
116116
&& !type_matches_path(info.ty.inner_type(), &["rustc_errors", "MultiSpan"])
117117
{
118-
report_type_error(attr, "`Span` or `MultiSpan`")?;
118+
report_type_error(attr, "`Span` or `MultiSpan`")?
119119
}
120120

121121
Ok(())
@@ -662,7 +662,7 @@ impl SubdiagnosticVariant {
662662
applicability: None,
663663
}
664664
} else {
665-
throw_invalid_attr!(attr);
665+
throw_invalid_attr!(attr)
666666
}
667667
}
668668
};

compiler/rustc_metadata/src/dependency_format.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
374374
}
375375
panic_runtime = Some((
376376
cnum,
377-
tcx.required_panic_strategy(cnum).unwrap_or_else(|| {
378-
bug!("cannot determine panic strategy of a panic runtime");
379-
}),
377+
tcx.required_panic_strategy(cnum)
378+
.unwrap_or_else(|| bug!("cannot determine panic strategy of a panic runtime")),
380379
));
381380
}
382381
}

compiler/rustc_middle/src/ty/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,8 @@ impl<'tcx> TyCtxt<'tcx> {
15981598
///
15991599
/// [`opt_item_name`]: Self::opt_item_name
16001600
pub fn item_name(self, id: DefId) -> Symbol {
1601-
self.opt_item_name(id).unwrap_or_else(|| {
1602-
bug!("item_name: no name for {:?}", self.def_path(id));
1603-
})
1601+
self.opt_item_name(id)
1602+
.unwrap_or_else(|| bug!("item_name: no name for {:?}", self.def_path(id)))
16041603
}
16051604

16061605
/// Look up the name and span of a definition.

compiler/rustc_middle/src/ty/typeck_results.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
518518
tcx.hir().node_to_string(hir_id),
519519
hir_owner
520520
)
521-
});
521+
})
522522
}
523523

524524
pub struct LocalTableInContext<'a, V> {

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,4 +857,4 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> {
857857
}
858858
}
859859
}
860-
}
860+
}

compiler/rustc_mir_transform/src/jump_threading.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
546546
};
547547
if writes_discriminant {
548548
let discr = self.ecx.discriminant_for_variant(enum_ty, *variant_index).ok()?;
549-
self.process_immediate(bb, discr_target, discr, state)?;
549+
self.process_immediate(bb, discr_target, discr, state)?
550550
}
551551
}
552552
// If we expect `lhs ?= true`, we have an opportunity if we assume `lhs == true`.
@@ -557,7 +557,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
557557
conditions.iter_matches(ScalarInt::TRUE).for_each(register_opportunity);
558558
}
559559
StatementKind::Assign(box (lhs_place, rhs)) => {
560-
self.process_assign(bb, lhs_place, rhs, state)?;
560+
self.process_assign(bb, lhs_place, rhs, state)?
561561
}
562562
_ => {}
563563
}

0 commit comments

Comments
 (0)