Skip to content
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

Don't import enum variants into the global namespace in html5ever #593

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

simonwuelker
Copy link
Contributor

@simonwuelker simonwuelker commented Apr 6, 2025

Currently the tokenizer and treebuilder in html5ever import all variants of commonly used enums:

enum Token {
   FooToken,
   BarToken
}

use Token::*;

fn main() {
    let x = FooToken;
}

This is not really idiomatic rust. I've never seen any other codebase do this, and it is not the style we use in servo either.

This change removes the imports and instead uses the Token::Foo notation, renaming the variants where appropriate.

This is a breaking change, because the PushFlag import was public (even though it really shouldn't have been, I suspect that's another common problem in html5ever).

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

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

I totally agree! This makes the code a lot easier to follow.

Copy link
Contributor

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

This does make the code a bit more verbose, but overall this seems like a really good change. Definitely makes the code more readable to me knowing which enum the type is coming from.

@simonwuelker simonwuelker added this pull request to the merge queue Apr 6, 2025
Merged via the queue into servo:main with commit f541230 Apr 6, 2025
6 checks passed
simonwuelker added a commit to simonwuelker/html5ever that referenced this pull request Apr 12, 2025
This is mostly the same as servo#593 but for xml5ever.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
simonwuelker added a commit to simonwuelker/html5ever that referenced this pull request Apr 12, 2025
This is mostly the same as servo#593 but for xml5ever.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
simonwuelker added a commit to simonwuelker/html5ever that referenced this pull request Apr 12, 2025
This is mostly the same as servo#593 but for xml5ever.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
simonwuelker added a commit to simonwuelker/html5ever that referenced this pull request Apr 12, 2025
This is mostly the same as servo#593 but for xml5ever.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
github-merge-queue bot pushed a commit that referenced this pull request Apr 12, 2025
This is mostly the same as #593 but for xml5ever.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
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