Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upuse Either type for UrlOrNone #14370
Conversation
highfive
commented
Nov 25, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Nov 25, 2016
|
Hey, thanks for the patch! Looks good, though you also need to fix the stylo build ( From the error, should be straigh-forward, but feel free to ping me if you have any doubts! Thanks again! :) |
|
(Sorry, I meant to say |
| let image_info = box ImageFragmentInfo::new(node, | ||
| url_value.url().map(|u| u.clone()), | ||
| &self.layout_context.shared); | ||
| vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)] | ||
| } | ||
| list_style_image::T::None => { | ||
| Either::Second(_) => { |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Nov 26, 2016
•
Member
The problem with Either type is that, it doesn't even give you a hint of what it holds under. We should do a workaround like this,
Either::Second(_none) => {... so that we can convince ourselves that it really holds a None type.
| match image { | ||
| UrlOrNone::None => { | ||
| Either::Second(_) => { |
This comment has been minimized.
This comment has been minimized.
| @@ -74,3 +74,7 @@ pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str | |||
| pub trait Parse { | |||
| fn parse(input: &mut Parser) -> Result<Self, ()> where Self: Sized; | |||
| } | |||
|
|
|||
| pub trait ParseWithContext { | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Nov 26, 2016
•
Member
This should be a temporary fix. We should probably replace all the types implementing the Parse method to take the context. You can do it if you like, but in case you don't, please drop a FIXME above this, like, FIXME(waffles): Merge this with Parse
This comment has been minimized.
This comment has been minimized.
emilio
Nov 26, 2016
•
Member
What about something like (probably with the traits renamed since we probably want ParseWithContext to be the default):
pub trait Parse : Sized {
fn parse(input: &mut Parser) -> Result<Self, ()>;
}
pub trait ParseWithContext : Sized {
fn parse_with_context(input: &mut Parser, context: &ParserContext) -> Result<Self, ()>;
}
impl<T: Parse> ParseWithContext for T {
fn parse_with_context(input: &mut Parser, context: &ParserContext) -> Result<Self, ()> {
T::parse(input)
}
}In any case agreed, this is kind of offtopic for this PR :)
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Nov 26, 2016
Member
I've changed the function signature (#14373) to include the context to avoid this problem
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Nov 27, 2016
Member
@thiagopnts You won't be needing this trait anymore. We'll be using the context in all the parse functions. Please rebase your changes on top of master :)
This comment has been minimized.
This comment has been minimized.
|
|
|
@emilio @wafflespeanut I did the changes, let me know if everything is ok so I can squash the commits! |
| @@ -54,6 +54,7 @@ use style::properties::{self, ServoComputedValues}; | |||
| use style::selector_parser::{PseudoElement, RestyleDamage}; | |||
| use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW}; | |||
| use style::stylist::Stylist; | |||
| use style::values::{Either, None_}; | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Nov 30, 2016
Member
I don't think the type would be necessary. It's not gonna be used anywhere anyway. Instead, you can just bind it to a name, like so
Either::Second(_none) => (),| @@ -1089,10 +1089,10 @@ fn static_assert() { | |||
|
|
|||
| #[allow(non_snake_case)] | |||
| pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) { | |||
| use properties::longhands::_moz_binding::computed_value::T as BindingValue; | |||
| use values::{Either, None_}; | |||
This comment has been minimized.
This comment has been minimized.
| @@ -72,6 +73,12 @@ pub struct SpecifiedUrl { | |||
| extra_data: UrlExtraData, | |||
| } | |||
|
|
|||
| impl Parse for SpecifiedUrl { | |||
| fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { | |||
| SpecifiedUrl::parse(context, input) | |||
This comment has been minimized.
This comment has been minimized.
|
Once my comments have been addressed, squash the commits, and we'll land it :) |
fix test-tidy errors fix style unit test use the Parse trait instead of ParseWithContext fix stylo test and geckolib build move all specified url parse code to parse trait and remove refs to unused type
|
@wafflespeanut done :) |
|
Thanks for working on this! :) |
|
@bors-servo r+ |
|
@bors-servo r+ Wut? |
|
|
use Either type for UrlOrNone Use the Either type for UrlOrNone --- <!-- 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 - [ ] These changes fix #14298 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- 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/14370) <!-- Reviewable:end -->
|
|
|
@bors-servo retry Nightmare'ish timeouts! |
use Either type for UrlOrNone Use the Either type for UrlOrNone --- <!-- 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 - [ ] These changes fix #14298 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- 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/14370) <!-- Reviewable:end -->
|
|
thiagopnts commentedNov 25, 2016
•
edited by larsbergstrom
Use the Either type for UrlOrNone
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is