Skip to content

Clarify some dead code #189

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

Merged
merged 1 commit into from
Aug 29, 2017
Merged

Conversation

tromey
Copy link
Contributor

@tromey tromey commented Aug 29, 2017

next_token has this code:

        if is_ident_start(tokenizer) { IDHash(consume_name(tokenizer)) }
        else if !tokenizer.is_eof() && match tokenizer.next_byte_unchecked() {
            b'a'...b'z' | b'A'...b'Z' | b'0'...b'9' | b'-' | b'_' => true,
            b'\\' => !tokenizer.has_newline_at(1),
            _ => !b.is_ascii(),
        } { Hash(consume_name(tokenizer)) }

I noticed that the _ case incorrectly checks whether b is ASCII,
rather than the current byte.

However, on further inspection, it turns out that this can't be run,
because all such cases would have been filtered out by is_ident_start.

This patch clarifies this code by removing the dead cases and adding a
comment.


This change is Reviewable

next_token has this code:

            if is_ident_start(tokenizer) { IDHash(consume_name(tokenizer)) }
            else if !tokenizer.is_eof() && match tokenizer.next_byte_unchecked() {
                b'a'...b'z' | b'A'...b'Z' | b'0'...b'9' | b'-' | b'_' => true,
                b'\\' => !tokenizer.has_newline_at(1),
                _ => !b.is_ascii(),
            } { Hash(consume_name(tokenizer)) }

I noticed that the `_` case incorrectly checks whether `b` is ASCII,
rather than the current byte.

However, on further inspection, it turns out that this can't be run,
because all such cases would have been filtered out by is_ident_start.

This patch clarifies this code by removing the dead cases and adding a
comment.
@SimonSapin
Copy link
Member

Good catch, thanks!

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 678736c has been approved by SimonSapin

bors-servo pushed a commit that referenced this pull request Aug 29, 2017
Clarify some dead code

next_token has this code:

            if is_ident_start(tokenizer) { IDHash(consume_name(tokenizer)) }
            else if !tokenizer.is_eof() && match tokenizer.next_byte_unchecked() {
                b'a'...b'z' | b'A'...b'Z' | b'0'...b'9' | b'-' | b'_' => true,
                b'\\' => !tokenizer.has_newline_at(1),
                _ => !b.is_ascii(),
            } { Hash(consume_name(tokenizer)) }

I noticed that the `_` case incorrectly checks whether `b` is ASCII,
rather than the current byte.

However, on further inspection, it turns out that this can't be run,
because all such cases would have been filtered out by is_ident_start.

This patch clarifies this code by removing the dead cases and adding a
comment.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/189)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

⌛ Testing commit 678736c with merge 6105cb1...

@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: SimonSapin
Pushing 6105cb1 to master...

@bors-servo bors-servo merged commit 678736c into servo:master Aug 29, 2017
@tromey tromey deleted the remove-confusing-dead-code branch August 29, 2017 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants