Skip to content

Commit

Permalink
Don't ignore warnings in html5ever/src/tree_builder (#551)
Browse files Browse the repository at this point in the history
* remove unnecessary references

Signed-off-by: Simon Wülker <[email protected]>

* remove unused imports

Signed-off-by: Simon Wülker <[email protected]>

* Restrict visibility of unreachable public items

This addresses the clippy::unreachable_pub lint
Signed-off-by: Simon Wülker <[email protected]>

* Replace .filter(..).next() calls with .find(..)

Signed-off-by: Simon Wülker <[email protected]>

* Remove unneeded "mut" qualifiers

Signed-off-by: Simon Wülker <[email protected]>

* Don't call .map with functions returning ()

This fixes a clippy lint

Signed-off-by: Simon Wülker <[email protected]>

* Replace trivial matches

These can all either use if-let branches
or the matches! macro

Signed-off-by: Simon Wülker <[email protected]>

* ignore clippy warnings in autogenerated code

Signed-off-by: Simon Wülker <[email protected]>

* Elide lifetimes where possible

Signed-off-by: Simon Wülker <[email protected]>

* Remove empty string literals in println!

Signed-off-by: Simon Wülker <[email protected]>

* Use Option::as_ref/as_deref where possible

Signed-off-by: Simon Wülker <[email protected]>

* Remove unneeded () returns

Signed-off-by: Simon Wülker <[email protected]>

* Remove unneeded field names

Signed-off-by: Simon Wülker <[email protected]>

* Simplify pop_until_current a bit

This also fixes a clippy warning

Signed-off-by: Simon Wülker <[email protected]>

* Ignore some variants that are never constructed

This is necessary to allow html5ever to build (due
to #[deny(warnings)].

We might want to remove these in the future,
but I'm not sure whether they're necessary.

* Format `html5ever/src/tree_builder/mod.rs`

Signed-off-by: Martin Robinson <[email protected]>

---------

Signed-off-by: Simon Wülker <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
Co-authored-by: Martin Robinson <[email protected]>
  • Loading branch information
simonwuelker and mrobinson authored Aug 31, 2024
1 parent e6f0018 commit bb62eac
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 145 deletions.
5 changes: 5 additions & 0 deletions html5ever/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ macro_rules! unwrap_or_else {
}

macro_rules! unwrap_or_return {
($opt:expr) => {
unwrap_or_else!($opt, {
return;
})
};
($opt:expr, $retval:expr) => {
unwrap_or_else!($opt, { return $retval })
};
Expand Down
79 changes: 39 additions & 40 deletions html5ever/src/tree_builder/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::tendril::StrTendril;
use crate::tokenizer::Doctype;

// These should all be lowercase, for ASCII-case-insensitive matching.
static QUIRKY_PUBLIC_PREFIXES: &'static [&'static str] = &[
static QUIRKY_PUBLIC_PREFIXES: &[&str] = &[
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
"-//as//dtd html 3.0 aswedit + extensions//",
"-//ietf//dtd html 2.0 level 1//",
Expand Down Expand Up @@ -69,35 +69,35 @@ static QUIRKY_PUBLIC_PREFIXES: &'static [&'static str] = &[
"-//webtechs//dtd mozilla html//",
];

static QUIRKY_PUBLIC_MATCHES: &'static [&'static str] = &[
static QUIRKY_PUBLIC_MATCHES: &[&str] = &[
"-//w3o//dtd w3 html strict 3.0//en//",
"-/w3c/dtd html 4.0 transitional/en",
"html",
];

static QUIRKY_SYSTEM_MATCHES: &'static [&'static str] =
static QUIRKY_SYSTEM_MATCHES: &[&str] =
&["http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"];

static LIMITED_QUIRKY_PUBLIC_PREFIXES: &'static [&'static str] = &[
static LIMITED_QUIRKY_PUBLIC_PREFIXES: &[&str] = &[
"-//w3c//dtd xhtml 1.0 frameset//",
"-//w3c//dtd xhtml 1.0 transitional//",
];

static HTML4_PUBLIC_PREFIXES: &'static [&'static str] = &[
static HTML4_PUBLIC_PREFIXES: &[&str] = &[
"-//w3c//dtd html 4.01 frameset//",
"-//w3c//dtd html 4.01 transitional//",
];

pub fn doctype_error_and_quirks(doctype: &Doctype, iframe_srcdoc: bool) -> (bool, QuirksMode) {
fn opt_string_as_slice<'t>(x: &'t Option<String>) -> Option<&'t str> {
x.as_ref().map(|y| &y[..])
pub(crate) fn doctype_error_and_quirks(
doctype: &Doctype,
iframe_srcdoc: bool,
) -> (bool, QuirksMode) {
fn opt_string_as_slice(x: &Option<String>) -> Option<&str> {
x.as_deref()
}

fn opt_tendril_as_slice<'t>(x: &'t Option<StrTendril>) -> Option<&'t str> {
match *x {
Some(ref t) => Some(t),
None => None,
}
fn opt_tendril_as_slice(x: &Option<StrTendril>) -> Option<&str> {
x.as_deref()
}

fn opt_to_ascii_lower(x: Option<&str>) -> Option<String> {
Expand All @@ -108,34 +108,33 @@ pub fn doctype_error_and_quirks(doctype: &Doctype, iframe_srcdoc: bool) -> (bool
let public = opt_tendril_as_slice(&doctype.public_id);
let system = opt_tendril_as_slice(&doctype.system_id);

let err = match (name, public, system) {
let err = !matches!(
(name, public, system),
(Some("html"), None, None)
| (Some("html"), None, Some("about:legacy-compat"))
| (Some("html"), Some("-//W3C//DTD HTML 4.0//EN"), None)
| (
Some("html"),
Some("-//W3C//DTD HTML 4.0//EN"),
Some("http://www.w3.org/TR/REC-html40/strict.dtd"),
)
| (Some("html"), Some("-//W3C//DTD HTML 4.01//EN"), None)
| (
Some("html"),
Some("-//W3C//DTD HTML 4.01//EN"),
Some("http://www.w3.org/TR/html4/strict.dtd"),
)
| (
Some("html"),
Some("-//W3C//DTD XHTML 1.0 Strict//EN"),
Some("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
)
| (
Some("html"),
Some("-//W3C//DTD XHTML 1.1//EN"),
Some("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"),
) => false,

_ => true,
};
| (Some("html"), None, Some("about:legacy-compat"))
| (Some("html"), Some("-//W3C//DTD HTML 4.0//EN"), None)
| (
Some("html"),
Some("-//W3C//DTD HTML 4.0//EN"),
Some("http://www.w3.org/TR/REC-html40/strict.dtd"),
)
| (Some("html"), Some("-//W3C//DTD HTML 4.01//EN"), None)
| (
Some("html"),
Some("-//W3C//DTD HTML 4.01//EN"),
Some("http://www.w3.org/TR/html4/strict.dtd"),
)
| (
Some("html"),
Some("-//W3C//DTD XHTML 1.0 Strict//EN"),
Some("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
)
| (
Some("html"),
Some("-//W3C//DTD XHTML 1.1//EN"),
Some("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"),
)
);

// FIXME: We could do something asymptotically faster here.
// But there aren't many strings, and this happens at most once per parse.
Expand Down
Loading

0 comments on commit bb62eac

Please sign in to comment.