Skip to content

Commit f14050b

Browse files
committed
(c2rust-analyze) Refactor out AnalysisCtxt::const_ref_perms (needed to add PhantomLifetime to get the lifetimes to work).
1 parent d4f269a commit f14050b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

c2rust-analyze/src/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::pointer_id::{
44
GlobalPointerTable, LocalPointerTable, NextGlobalPointerId, NextLocalPointerId, PointerTable,
55
PointerTableMut,
66
};
7-
use crate::util::{self, describe_rvalue, RvalueDesc};
7+
use crate::util::{self, describe_rvalue, PhantomLifetime, RvalueDesc};
88
use crate::AssignPointerIds;
99
use bitflags::bitflags;
1010
use rustc_hir::def_id::DefId;
@@ -126,6 +126,13 @@ impl<'a, 'tcx> AnalysisCtxt<'_, 'tcx> {
126126
self.const_ref_locs.iter().map(|loc| self.rvalue_tys[loc])
127127
}
128128

129+
pub fn const_ref_perms(
130+
&'a self,
131+
) -> impl Iterator<Item = (PointerId, PermissionSet)> + PhantomLifetime<'tcx> + 'a {
132+
self.const_ref_tys()
133+
.map(|lty| (lty.label, PermissionSet::for_const_ref_ty(lty.ty)))
134+
}
135+
129136
pub fn check_const_ref_perms(&self, asn: &Assignment) {
130137
for const_ref_lty in self.const_ref_tys() {
131138
let ptr_id = const_ref_lty.label;

c2rust-analyze/src/dataflow/type_check.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,8 @@ pub fn visit<'tcx>(
465465
equiv_constraints: Vec::new(),
466466
};
467467

468-
for const_ref_lty in acx.const_ref_tys() {
469-
tc.constraints.add_all_perms(
470-
const_ref_lty.label,
471-
PermissionSet::for_const_ref_ty(const_ref_lty.ty),
472-
);
468+
for (ptr, perms) in acx.const_ref_perms() {
469+
tc.constraints.add_all_perms(ptr, perms);
473470
}
474471

475472
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {

c2rust-analyze/src/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,6 @@ pub fn is_null_const(constant: Constant) -> bool {
348348
_ => false,
349349
}
350350
}
351+
352+
pub trait PhantomLifetime<'a> {}
353+
impl<'a, T: ?Sized> PhantomLifetime<'a> for T {}

0 commit comments

Comments
 (0)