Skip to content

Commit 56d438f

Browse files
committed
Don't assign comments to fake_read
1 parent b7e098f commit 56d438f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

charon/src/transform/recover_body_comments.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ impl LlbcPass for Transform {
2121
// correspond to what the comment was intended to point to.
2222
let mut best_span_for_line: HashMap<usize, Span> = Default::default();
2323
b.body.drive(&mut visitor_enter_fn(|st: &Statement| {
24+
if matches!(st.content, RawStatement::FakeRead(_)) {
25+
// These are added after many `let` statements and mess up the comments.
26+
return;
27+
}
2428
let span = st.span;
2529
best_span_for_line
2630
.entry(span.span.beg.line)

charon/tests/ui/comments.out

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ fn test_crate::sum<'_0>(@1: &'_0 (Slice<u32>)) -> u32
4444
let @25: &'_ (Slice<u32>); // anonymous local
4545
let @26: &'_ (u32); // anonymous local
4646

47-
sum@2 := const (0 : u32)
4847
// Comment1
48+
sum@2 := const (0 : u32)
4949
@fake_read(sum@2)
50-
i@3 := const (0 : usize)
5150
// Comment2
5251
// Comment2.1
5352
// Comment2.2
53+
i@3 := const (0 : usize)
5454
@fake_read(i@3)
5555
@6 := copy (sum@2)
5656
@5 := move (@6) + const (2 : u32)
@@ -147,9 +147,9 @@ fn test_crate::thing()
147147

148148
@5 := test_crate::CONSTANT
149149
@2 := move (@5) >> const (3 : i32)
150+
// This comment belongs above the assignment to `x` and not above intermediate computations.
150151
x@1 := move (@2) + const (12 : u32)
151152
drop @2
152-
// This comment belongs above the assignment to `x` and not above intermediate computations.
153153
@fake_read(x@1)
154154
@4 := copy (x@1)
155155
@3 := test_crate::function_call(move (@4))
@@ -168,7 +168,6 @@ fn test_crate::fake_read(@1: u32)
168168
let x@1: u32; // arg #1
169169
let @2: (); // anonymous local
170170

171-
// This statement is translated to a `fake_read`.
172171
@fake_read(x@1)
173172
@2 := ()
174173
@0 := move (@2)

0 commit comments

Comments
 (0)