Repository navigation
style: Move contain outside of mako - #19682
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
|
Heads up! This PR modifies the following files:
|
emilio
left a comment
There was a problem hiding this comment.
Looks great! Just minor nits and suggestions, other than that, r=me
Thanks a lot for doing this!
|
|
||
| impl Parse for Contain { | ||
| /// none | strict | content | [ size || layout || style || paint ] | ||
| fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) |
There was a problem hiding this comment.
nit: Indentation is off, let's do:
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Contain, ParseError<'i>> {| }; | ||
| let flag = match flag { | ||
| Some(flag) if !result.contains(flag) => flag, | ||
| _ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone()))) |
There was a problem hiding this comment.
I'm 99% sure this clone() call is not necessary.
| /// none | strict | content | [ size || layout || style || paint ] | ||
| fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) | ||
| -> Result<Contain, ParseError<'i>> { | ||
| let mut result = Contain::empty(); |
There was a problem hiding this comment.
This function is kinda dumb, and could be rewritten to be faster / clearer. Can you file a followup for it?
In particular, I'm thinking of something like:
let mut result = Contain::empty();
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
match_ignore_ascii_case! { &name,
"layout" => Some(Contain::LAYOUT),
"style" => Some(Contain::STYLE),
"paint" => Some(Contain::PAINT),
// The following are only valid as the first value, thus the is_empty()
// checks.
"strict" => {
if result.is_empty() {
return Ok(Contain::STRICT | Contain::STRICT_BITS)
}
None
}
"none" => {
if result.is_empty() {
return Ok(result);
}
None
}
_ => None
};
// Same code as now.
}Also fine to do it in a separate commit in this same PR.
That avoids having to tokenize twice for none and strict just to tokenize an identifier again below.
There was a problem hiding this comment.
Thanks for the feedback, I will file a followup commit soon.
| } | ||
| if input.try(|input| input.expect_ident_matching("strict")).is_ok() { | ||
| result.insert(Contain::STRICT | Contain::STRICT_BITS); | ||
| return Ok(result) |
There was a problem hiding this comment.
nit: just return Ok(Contain::STRICT | Contain::STRICT_BITS) may be cleaner?
| const PAINT = 0x04; | ||
| /// `strict` variant, turns on all types of containment | ||
| const STRICT = 0x8; | ||
| /// `strict bits` variant |
There was a problem hiding this comment.
Just /// variant with all the bits that contain: strict turns on?
|
I just pushed the changes, let me know if there need to be any more! |
| "style" => Some(Contain::STYLE), | ||
| "paint" => Some(Contain::PAINT), | ||
| "strict" if result.is_empty() => return Ok(Contain::STRICT | Contain::STRICT_BITS), | ||
| "none" if result.is_empty() => return Ok(result), |
There was a problem hiding this comment.
I think you'll need to check if result.is_empty() inside the pattern instead of using it as a pattern matching guard. If putting if result.is_empty() as guard here, I think it will only get into the strict one?
IMO, just like @emilio commented in the comment, it might be fine to be like following
"strict" => {
if result.is_empty() {
return Ok(Contain::STRICT | Contain::STRICT_BITS)
}
None
},
"none" => {
if result.is_empty() {
return Ok(result);
}
None
}There was a problem hiding this comment.
Thanks, I changed it back to the previous version. I don't really understand why it won't get into the none arm though; how would rust evaluate the guard?
There was a problem hiding this comment.
FWIW the guard should work just fine, and it's more elegant indeed.
Wanna open a PR after this one merges simplifying it? Thanks!
There was a problem hiding this comment.
Sure, I'd be glad to, assuming this one passes the tests.
There was a problem hiding this comment.
Ahhh... yes... sorry, I think it in a wrong way so using guard here should work fine.
Sorry for the misleading 😣
|
Besides, I think it would be great to squash the two commits into one 😀 |
|
I'm not sure why this test failed after such a small change. Could someone please re-run it? |
|
@stevel98 I think you can try to |
|
Thanks! |
|
@bors-servo r+ |
|
📌 Commit 4c23f09 has been approved by |
style: Move contain outside of mako <!-- Please describe your changes on the following line: --> Sub-PR for #19015. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19656 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19682) <!-- Reviewable:end -->
|
💔 Test failed - mac-dev-unit |
|
@bors-servo retry |
style: Move contain outside of mako <!-- Please describe your changes on the following line: --> Sub-PR for #19015. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19656 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19682) <!-- Reviewable:end -->
|
💔 Test failed - mac-dev-unit |
|
@bors-servo retry
|
|
⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt2, mac-rel-wpt4... |
|
⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt2, mac-rel-wpt4... |
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
style: Make Contain::parse simpler <!-- Please describe your changes on the following line: --> --- Makes Contain::parse slightly simpler, as discussed in #19682 - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19682 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19692) <!-- Reviewable:end -->
Sub-PR for #19015.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorscontainoutside of mako. #19656 (github issue number if applicable).This change is