Skip to content

Commit

Permalink
Rollup merge of rust-lang#129738 - nnethercote:rustc_mir_transform-cl…
Browse files Browse the repository at this point in the history
…eanups, r=cjgillot

`rustc_mir_transform` cleanups

A bunch of small improvements I made while looking closely at this code.

r? ``@saethlin``
  • Loading branch information
workingjubilee authored Sep 2, 2024
2 parents 8934019 + ac7a293 commit 5377160
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn add_move_for_packed_drop<'tcx>(

let source_info = terminator.source_info;
let ty = place.ty(body, tcx).ty;
let temp = patch.new_temp(ty, terminator.source_info.span);
let temp = patch.new_temp(ty, source_info.span);

let storage_dead_block = patch.new_block(BasicBlockData {
statements: vec![Statement { source_info, kind: StatementKind::StorageDead(temp) }],
Expand Down
29 changes: 11 additions & 18 deletions compiler/rustc_mir_transform/src/check_packed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,17 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
}

fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
if context.is_borrow() {
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
let def_id = self.body.source.instance.def_id();
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
&& self.tcx.is_builtin_derived(impl_def_id)
{
// If we ever reach here it means that the generated derive
// code is somehow doing an unaligned reference, which it
// shouldn't do.
span_bug!(
self.source_info.span,
"builtin derive created an unaligned reference"
);
} else {
self.tcx
.dcx()
.emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
}
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
let def_id = self.body.source.instance.def_id();
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
&& self.tcx.is_builtin_derived(impl_def_id)
{
// If we ever reach here it means that the generated derive
// code is somehow doing an unaligned reference, which it
// shouldn't do.
span_bug!(self.source_info.span, "builtin derive created an unaligned reference");
} else {
self.tcx.dcx().emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
}
}
}
Expand Down
Loading

0 comments on commit 5377160

Please sign in to comment.