Skip to content

Don't return a string from TreeSink::attach_declarative_shadow_root #633

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 2 commits into from
Jun 27, 2025

Conversation

simonwuelker
Copy link
Contributor

@simonwuelker simonwuelker commented Jun 26, 2025

The string is unused, so this is just a pointless allocation. This change returns a bool indicating the operations success instead.

Additionally, pass a reference to the elements attributes. The callee can decide whether they need ownership of the vector or not (servo doesn't).

Comment on lines -259 to -261
Err(String::from(
"No implementation for attach_declarative_shadow",
))
Copy link
Contributor

Choose a reason for hiding this comment

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

How about making this &'static str? Then we still get the error message without the allocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the string is discarded anyways. html5ever doesn't care why attaching the shadow root failed - maybe the element already is a shadow host, maybe the element is not in the html namespace. This message is not logged anywhere, and I don't think it needs to be either.

@simonwuelker simonwuelker force-pushed the attach-shadow branch 2 times, most recently from 34a021a to 37ca1e4 Compare June 26, 2025 21:28
@simonwuelker
Copy link
Contributor Author

This now includes a commit to bump html5ever to 0.34. The version bump is necessary because this is a breaking change. There is a passing try run in servo/servo#37736. Can someone with release merge permissions merge this and release to crates.io?

Signed-off-by: Simon Wülker <[email protected]>
@mrobinson mrobinson added this pull request to the merge queue Jun 27, 2025
Merged via the queue into servo:main with commit c74a7ad Jun 27, 2025
6 checks passed
@simonwuelker simonwuelker deleted the attach-shadow branch June 27, 2025 10:32
@simonwuelker
Copy link
Contributor Author

0.34 still needs to be published.

@mrobinson
Copy link
Member

I tried publishing today, but I got this error. Sorry, I haven't had time to get to the bottom of it:

error[E0308]: mismatched types
    --> src/tree_builder/mod.rs:1497:63
     |
1497 |             .attach_declarative_shadow(shadow_host, template, &tag.attrs)
     |              -------------------------                        ^^^^^^^^^^ expected `Vec<Attribute>`, found `&Vec<Attribute>`
     |              |
     |              arguments to this method are incorrect
     |
     = note: expected struct `Vec<_>`
             found reference `&Vec<_>`
note: method defined here
    --> /Users/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markup5ever-0.16.2/interface/tree_builder.rs:253:8
     |
253  |     fn attach_declarative_shadow(
     |        ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider removing the borrow
     |
1497 -             .attach_declarative_shadow(shadow_host, template, &tag.attrs)
1497 +             .attach_declarative_shadow(shadow_host, template, tag.attrs)
     |

error[E0308]: mismatched types
    --> src/tree_builder/mod.rs:1496:9
     |
1495 |       ) -> bool {
     |            ---- expected `bool` because of return type
1496 | /         self.sink
1497 | |             .attach_declarative_shadow(shadow_host, template, &tag.attrs)
     | |_________________________________________________________________________^ expected `bool`, found `Result<(), String>`
     |
     = note: expected type `bool`
                found enum `Result<(), String>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `html5ever` (lib) due to 2 previous errors
error: failed to verify package tarball

@jdm
Copy link
Member

jdm commented Jun 27, 2025

This requires a major version update for markup5ever as well, since the public interface changed.

@simonwuelker
Copy link
Contributor Author

Oops, my bad. I opened #636 to bump markup5ever as well.

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.

4 participants