Skip to content

Commit

Permalink
Don't assign comments to fake_read
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Oct 1, 2024
1 parent b7e098f commit 56d438f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions charon/src/transform/recover_body_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl LlbcPass for Transform {
// correspond to what the comment was intended to point to.
let mut best_span_for_line: HashMap<usize, Span> = Default::default();
b.body.drive(&mut visitor_enter_fn(|st: &Statement| {
if matches!(st.content, RawStatement::FakeRead(_)) {
// These are added after many `let` statements and mess up the comments.
return;
}
let span = st.span;
best_span_for_line
.entry(span.span.beg.line)
Expand Down
7 changes: 3 additions & 4 deletions charon/tests/ui/comments.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ fn test_crate::sum<'_0>(@1: &'_0 (Slice<u32>)) -> u32
let @25: &'_ (Slice<u32>); // anonymous local
let @26: &'_ (u32); // anonymous local

sum@2 := const (0 : u32)
// Comment1
sum@2 := const (0 : u32)
@fake_read(sum@2)
i@3 := const (0 : usize)
// Comment2
// Comment2.1
// Comment2.2
i@3 := const (0 : usize)
@fake_read(i@3)
@6 := copy (sum@2)
@5 := move (@6) + const (2 : u32)
Expand Down Expand Up @@ -147,9 +147,9 @@ fn test_crate::thing()

@5 := test_crate::CONSTANT
@2 := move (@5) >> const (3 : i32)
// This comment belongs above the assignment to `x` and not above intermediate computations.
x@1 := move (@2) + const (12 : u32)
drop @2
// This comment belongs above the assignment to `x` and not above intermediate computations.
@fake_read(x@1)
@4 := copy (x@1)
@3 := test_crate::function_call(move (@4))
Expand All @@ -168,7 +168,6 @@ fn test_crate::fake_read(@1: u32)
let x@1: u32; // arg #1
let @2: (); // anonymous local

// This statement is translated to a `fake_read`.
@fake_read(x@1)
@2 := ()
@0 := move (@2)
Expand Down

0 comments on commit 56d438f

Please sign in to comment.