Skip to content

Problem with Unix line feed annotation using empty ranges #135

Open
@Volham22

Description

@Volham22

Hello, thanks for your amazing work on this crate!

I recently encountered a problem while trying to annotate Unix line feeds (\n). When annotating line feeds with an empty Range, I got the following error:

error: bad
--> test.txt:1:1
 |
 |

This looks like a bug because doing the same thing on letters or digits works as expected:

error: bad
 --> test.txt:1:1
  |
1 | 111
  | ^
  |

Also, giving a non-empty Range solves the problem and outputs the annotation as expected:

error: bad
 --> test.txt:1:1
  |
1 | ...
  | ^
  |

Here is the code used to reproduce the problem (which occurs with the latest release). test.txt is a simple text file containing only Unix line feeds (\n):

use annotate_snippets::{Level, Renderer, Snippet};

pub fn reproduce_bug() {
    let renderer = Renderer::styled();
    let message = Level::Error.title("bad").snippet(
        Snippet::source(include_str!("../test.txt"))
            .origin("test.txt")
            .fold(true)
            .annotation(Level::Error.span(0..0)),
    );
    anstream::println!("{}", renderer.render(message));
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions