Skip to content

Use unsafe slicing #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fluent-syntax/src/parser/ftlstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'p> ParserStream<'p> {
}

pub fn get_slice(&self, start: usize, end: usize) -> &'p str {
str::from_utf8(&self.source[start..end]).expect("Slicing the source failed")
unsafe { str::from_utf8_unchecked(&self.source[start..end]) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be unsafe. The start or end might not be at the start or end of a character, which makes the str invalid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjorn3 - please, comment in #82 where we're discussing it. In particular, I made a claim that the start and end must be at the start and end of a character due to how the parser works.

}

pub fn skip_digits(&mut self) -> Result<()> {
Expand Down