Skip to content

Commit d4f269a

Browse files
committed
(c2rust-analyze) Refactor out AnalysisCtxt::check_const_ref_perms.
1 parent 36cdf90 commit d4f269a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

c2rust-analyze/src/context.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,23 @@ pub struct AnalysisCtxt<'a, 'tcx> {
121121
next_ptr_id: NextLocalPointerId,
122122
}
123123

124-
impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> {
124+
impl<'a, 'tcx> AnalysisCtxt<'_, 'tcx> {
125125
pub fn const_ref_tys(&'a self) -> impl Iterator<Item = LTy<'tcx>> + 'a {
126126
self.const_ref_locs.iter().map(|loc| self.rvalue_tys[loc])
127127
}
128+
129+
pub fn check_const_ref_perms(&self, asn: &Assignment) {
130+
for const_ref_lty in self.const_ref_tys() {
131+
let ptr_id = const_ref_lty.label;
132+
let expected_perms = PermissionSet::for_const_ref_ty(const_ref_lty.ty);
133+
let mut actual_perms = asn.perms()[ptr_id];
134+
// Ignore `UNIQUE` as it gets automatically added to all permissions
135+
// and then removed later if it can't apply.
136+
// We don't care about `UNIQUE` for const refs, so just unset it here.
137+
actual_perms.set(PermissionSet::UNIQUE, false);
138+
assert_eq!(expected_perms, actual_perms);
139+
}
140+
}
128141
}
129142

130143
pub struct AnalysisCtxtData<'tcx> {

c2rust-analyze/src/main.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -620,16 +620,7 @@ fn run(tcx: TyCtxt) {
620620
let mut asn = gasn.and(&mut info.lasn);
621621
info.dataflow.propagate_cell(&mut asn);
622622

623-
for const_ref_lty in acx.const_ref_tys() {
624-
let ptr_id = const_ref_lty.label;
625-
let expected_perms = PermissionSet::for_const_ref_ty(const_ref_lty.ty);
626-
let mut actual_perms = asn.perms()[ptr_id];
627-
// Ignore `UNIQUE` as it gets automatically added to all permissions
628-
// and then removed later if it can't apply.
629-
// We don't care about `UNIQUE` for const refs, so just unset it here.
630-
actual_perms.set(PermissionSet::UNIQUE, false);
631-
assert_eq!(expected_perms, actual_perms);
632-
}
623+
acx.check_const_ref_perms(&asn);
633624

634625
// Print labeling and rewrites for the current function.
635626

0 commit comments

Comments
 (0)