From 62e4484ad8703b0c86208674bdf0f129f1f3eca6 Mon Sep 17 00:00:00 2001 From: Margaret Meyerhofer Date: Fri, 3 Aug 2012 15:16:08 -0700 Subject: [PATCH] servo: Fixed the changing alt syntax and cleaned up some compiler warnings Source-Repo: https://github.com/servo/servo Source-Revision: 0b796c410cf5d0924b652186d5b17e8b3ad285a8 --- servo/src/servo/content.rs | 38 +++---- servo/src/servo/dom/base.rs | 6 +- servo/src/servo/dom/bindings/node.rs | 14 +-- servo/src/servo/dom/bindings/utils.rs | 4 +- servo/src/servo/dom/rcu.rs | 12 +- servo/src/servo/engine.rs | 6 +- servo/src/servo/gfx/pngsink.rs | 6 +- servo/src/servo/gfx/renderer.rs | 30 ++--- servo/src/servo/gfx/surface.rs | 2 +- servo/src/servo/layout/base.rs | 8 +- servo/src/servo/layout/box_builder.rs | 50 ++++----- .../src/servo/layout/display_list_builder.rs | 30 +++-- servo/src/servo/layout/layout_task.rs | 52 +++++---- servo/src/servo/layout/style/apply.rs | 12 +- servo/src/servo/layout/style/matching.rs | 99 ++++++++--------- servo/src/servo/layout/style/style.rs | 16 +-- servo/src/servo/layout/text.rs | 6 +- servo/src/servo/layout/traverse.rs | 2 +- servo/src/servo/opts.rs | 10 +- servo/src/servo/parser/css_builder.rs | 93 ++++++++-------- servo/src/servo/parser/css_lexer.rs | 60 +++++----- servo/src/servo/parser/html_builder.rs | 103 +++++++++--------- servo/src/servo/parser/html_lexer.rs | 33 +++--- servo/src/servo/parser/lexer_util.rs | 23 ++-- servo/src/servo/parser/parser_util.rs | 56 +++++----- servo/src/servo/platform/osmain.rs | 16 +-- servo/src/servo/resource/file_loader.rs | 6 +- servo/src/servo/resource/http_loader.rs | 13 ++- servo/src/servo/resource/resource_task.rs | 23 ++-- servo/src/servo/servo.rc | 2 +- servo/src/servo/servo.rs | 21 ++-- servo/src/servo/text/font.rs | 4 +- .../servo/text/native_font/ft_native_font.rs | 2 +- servo/src/servo/text/shaper.rs | 14 +-- servo/src/servo/util/color.rs | 72 ++++++------ servo/src/servo/util/tree.rs | 12 +- servo/src/servo/util/url.rs | 5 +- 37 files changed, 479 insertions(+), 482 deletions(-) diff --git a/servo/src/servo/content.rs b/servo/src/servo/content.rs index 5a2eee9fb557..a0c14283ddc8 100644 --- a/servo/src/servo/content.rs +++ b/servo/src/servo/content.rs @@ -9,6 +9,7 @@ export PingMsg, PongMsg; export create_content; export Document; +import arc::{arc, clone}; import comm::{port, chan, listen, select2}; import task::{spawn, spawn_listener}; import io::{read_whole_file, println}; @@ -55,7 +56,7 @@ enum PingMsg { } #[doc="Sends a ping to layout and waits for the response."] -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn join_layout(scope: NodeScope, layout: Layout) { if scope.is_reader_forked() { @@ -69,11 +70,11 @@ fn join_layout(scope: NodeScope, layout: Layout) { class Document { let root: Node; - let css_rules: Stylesheet; + let css_rules: arc; - new(root: Node, +css_rules: Stylesheet) { + new(root: Node, -css_rules: Stylesheet) { self.root = root; - self.css_rules = css_rules; + self.css_rules = arc(css_rules); } } @@ -114,24 +115,21 @@ class Content { fn handle_msg(msg: either) -> bool { alt msg { - left(control_msg) { - return self.handle_control_msg(control_msg); - } - right(event) { - return self.handle_event(event); - } + left(control_msg) => self.handle_control_msg(control_msg), + right(event) => self.handle_event(event) } } fn handle_control_msg(control_msg: ControlMsg) -> bool { alt control_msg { - ParseMsg(url) { + ParseMsg(url) => { #debug["content: Received url `%s` to parse", url_to_str(url)]; // Note: we can parse the next document in parallel // with any previous documents. let stream = spawn_html_lexer_task(copy url, self.resource_task); - let (root, style_port, js_port) = build_dom(self.scope, stream, url, self.resource_task); + let (root, style_port, js_port) = build_dom(self.scope, stream, url, + self.resource_task); let css_rules = style_port.recv(); let js_scripts = js_port.recv(); @@ -160,14 +158,14 @@ class Content { return true; } - ExecuteMsg(url) { + ExecuteMsg(url) => { #debug["content: Received url `%s` to execute", url_to_str(url)]; alt read_whole_file(url.path) { - err(msg) { + err(msg) => { println(#fmt["Error opening %s: %s", url_to_str(url), msg]); } - ok(bytes) { + ok(bytes) => { let cx = self.jsrt.cx(); cx.set_default_options_and_version(); cx.set_logging_error_reporter(); @@ -180,7 +178,7 @@ class Content { return true; } - ExitMsg { + ExitMsg => { self.layout.send(layout_task::ExitMsg); return false; } @@ -196,7 +194,7 @@ class Content { // Send new document and relevant styles to layout // FIXME: Put CSS rules in an arc or something. - self.layout.send(BuildMsg(document.root, document.css_rules)); + self.layout.send(BuildMsg(document.root, clone(&document.css_rules))); // Indicate that reader was forked so any further // changes will be isolated. @@ -205,13 +203,13 @@ class Content { fn handle_event(event: Event) -> bool { alt event { - ResizeEvent(new_width, new_height) { + ResizeEvent(new_width, new_height) => { #debug("content got resize event: %d, %d", new_width, new_height); alt copy self.document { - none { + none => { // Nothing to do. } - some(document) { + some(document) => { self.relayout(*document); } } diff --git a/servo/src/servo/dom/base.rs b/servo/src/servo/dom/base.rs index f20129f6a1e0..d47826ff7df0 100644 --- a/servo/src/servo/dom/base.rs +++ b/servo/src/servo/dom/base.rs @@ -90,14 +90,14 @@ trait node_scope { fn new_node(-k: NodeKind) -> Node; } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] impl NodeScope of node_scope for NodeScope { fn new_node(-k: NodeKind) -> Node { self.handle(NodeData({tree: tree::empty(), kind: ~k})) } } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] impl TreeReadMethods of tree::ReadMethods for NodeScope { fn each_child(node: Node, f: fn(Node) -> bool) { tree::each_child(self, node, f) @@ -112,7 +112,7 @@ impl TreeReadMethods of tree::ReadMethods for NodeScope { } } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] impl TreeWriteMethods of tree::WriteMethods for NodeScope { fn add_child(node: Node, child: Node) { tree::add_child(self, node, child) diff --git a/servo/src/servo/dom/bindings/node.rs b/servo/src/servo/dom/bindings/node.rs index ce3609ea69c7..33d4d06117b4 100644 --- a/servo/src/servo/dom/bindings/node.rs +++ b/servo/src/servo/dom/bindings/node.rs @@ -94,11 +94,11 @@ extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut js unsafe { (*unwrap(obj)).payload.read(|nd| { alt nd.tree.first_child { - some(n) { + some(n) => { let obj = create(cx, n).ptr; *rval = RUST_OBJECT_TO_JSVAL(obj); } - none { + none => { *rval = JSVAL_NULL; } } @@ -111,11 +111,11 @@ extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut j unsafe { (*unwrap(obj)).payload.read(|nd| { alt nd.tree.next_sibling { - some(n) { + some(n) => { let obj = create(cx, n).ptr; *rval = RUST_OBJECT_TO_JSVAL(obj); } - none { + none => { *rval = JSVAL_NULL; } } @@ -128,11 +128,11 @@ extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval unsafe { (*unwrap(obj)).payload.read(|nd| { alt nd.kind { - ~Element(ed) { - let s = str(ed.tag_name); + ~Element(ed) => { + let s = str(copy ed.tag_name); *rval = domstring_to_jsval(cx, s); } - _ { + _ => { //XXXjdm should probably read the spec to figure out what to do here *rval = JSVAL_NULL; } diff --git a/servo/src/servo/dom/bindings/utils.rs b/servo/src/servo/dom/bindings/utils.rs index a481f60a60df..f9978dd7c2e5 100644 --- a/servo/src/servo/dom/bindings/utils.rs +++ b/servo/src/servo/dom/bindings/utils.rs @@ -55,10 +55,10 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> result<~str, ()> { unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval { alt str { - null_string { + null_string => { JSVAL_NULL } - str(s) { + str(s) => { str::as_buf(s, |buf, len| { let cbuf = unsafe::reinterpret_cast(buf); RUST_STRING_TO_JSVAL(JS_NewStringCopyN(cx, cbuf, len as libc::size_t)) diff --git a/servo/src/servo/dom/rcu.rs b/servo/src/servo/dom/rcu.rs index 0a11127f4d7c..8d5587fe3747 100644 --- a/servo/src/servo/dom/rcu.rs +++ b/servo/src/servo/dom/rcu.rs @@ -210,7 +210,7 @@ impl WriterMethods for Scope { f(*h.write_ptr()) } - #[warn(no_non_implicitly_copyable_typarams)] + #[allow(non_implicitly_copyable_typarams)] fn handle(v: T) -> Handle unsafe { let d: *HandleData = unsafe::reinterpret_cast( @@ -226,7 +226,7 @@ impl WriterMethods for Scope { } #[cfg(test)] -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] mod test { type animal = {name: ~str, species: species}; @@ -250,15 +250,15 @@ mod test { fn mutate(a: animal) { alt a.species { - chicken(c) { c.eggs_per_day += 1u; } - bull(c) { c.horns += 1u; } + chicken(c) => c.eggs_per_day += 1u, + bull(c) => c.horns += 1u } } fn read_characteristic(a: animal) -> uint { alt a.species { - chicken(c) { c.eggs_per_day } - bull(c) { c.horns } + chicken(c) => c.eggs_per_day, + bull(c) => c.horns } } diff --git a/servo/src/servo/engine.rs b/servo/src/servo/engine.rs index 2bf4c1ccb0f9..f7861af49ece 100644 --- a/servo/src/servo/engine.rs +++ b/servo/src/servo/engine.rs @@ -42,7 +42,9 @@ class Engine { fn handle_request(request: Msg) -> bool { alt request { - LoadURLMsg(url) { + LoadURLMsg(url) => { + // TODO: change copy to move once we have alt move + let url = copy url; if url.path.ends_with(".js") { self.content.send(ExecuteMsg(url)) } else { @@ -51,7 +53,7 @@ class Engine { return true; } - ExitMsg(sender) { + ExitMsg(sender) => { self.content.send(content::ExitMsg); self.layout.send(layout_task::ExitMsg); diff --git a/servo/src/servo/gfx/pngsink.rs b/servo/src/servo/gfx/pngsink.rs index 1dfbc7daf953..04b9e6654995 100644 --- a/servo/src/servo/gfx/pngsink.rs +++ b/servo/src/servo/gfx/pngsink.rs @@ -59,15 +59,15 @@ fn PngSink(output: chan<~[u8]>) -> PngSink { loop { alt po.recv() { - BeginDrawing(sender) { + BeginDrawing(sender) => { #debug("pngsink: begin_drawing"); sender.send(draw_target); } - Draw(sender, dt) { + Draw(sender, dt) => { #debug("pngsink: draw"); do_draw(sender, dt, output, cairo_surf); } - Exit { break } + Exit => { break } } } diff --git a/servo/src/servo/gfx/renderer.rs b/servo/src/servo/gfx/renderer.rs index ad5a6b92368d..061544dfe91e 100644 --- a/servo/src/servo/gfx/renderer.rs +++ b/servo/src/servo/gfx/renderer.rs @@ -47,7 +47,7 @@ fn Renderer(sink: S) -> comm::chan { loop { alt po.recv() { - RenderMsg(display_list) { + RenderMsg(display_list) => { #debug("renderer: got render request"); let draw_target = draw_target_po.recv(); let (ch, po) = pipes::stream(); @@ -64,7 +64,7 @@ fn Renderer(sink: S) -> comm::chan { sink.draw(draw_target_ch, draw_target); } } - ExitMsg(response_ch) { + ExitMsg(response_ch) => { response_ch.send(()); break; } @@ -88,18 +88,10 @@ fn draw_display_list(draw_target: AzDrawTargetRef, display_list: dl::display_lis #debug["drawing %?", item]; alt item.item_type { - dl::display_item_solid_color(r, g, b) { - draw_solid_color(draw_target, item, r, g, b); - } - dl::display_item_image(image) { - draw_image(draw_target, item, *image); - } - dl::display_item_text(text_run) { - draw_text(draw_target, item, text_run); - } - dl::padding(*) { - fail ~"should never see padding"; - } + dl::display_item_solid_color(r, g, b) => draw_solid_color(draw_target, item, r, g, b), + dl::display_item_image(image) => draw_image(draw_target, item, *image), + dl::display_item_text(text_run) => draw_text(draw_target, item, text_run), + dl::padding(*) => fail ~"should never see padding" } } } @@ -141,11 +133,11 @@ fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item, image: arc<~ let color = i % 4; let pixel = i / 4; alt color { - 0 { image.data[pixel * 3 + 2] } - 1 { image.data[pixel * 3 + 1] } - 2 { image.data[pixel * 3 + 0] } - 3 { 0xffu8 } - _ { fail } + 0 => image.data[pixel * 3 + 2], + 1 => image.data[pixel * 3 + 1], + 2 => image.data[pixel * 3 + 0], + 3 => 0xffu8, + _ => fail } }; diff --git a/servo/src/servo/gfx/surface.rs b/servo/src/servo/gfx/surface.rs index c190a5c1d8fb..a155f405c5fe 100644 --- a/servo/src/servo/gfx/surface.rs +++ b/servo/src/servo/gfx/surface.rs @@ -15,7 +15,7 @@ type image_surface = { impl format for format { fn bpp() -> uint { alt self { - fo_rgba_8888 { 32u } + fo_rgba_8888 => 32u } } } diff --git a/servo/src/servo/layout/base.rs b/servo/src/servo/layout/base.rs index 795ab8f26226..d99887dc5b97 100644 --- a/servo/src/servo/layout/base.rs +++ b/servo/src/servo/layout/base.rs @@ -180,10 +180,10 @@ impl layout_methods for @Box { #[doc="The main reflow routine."] fn reflow(available_width: au) { alt self.kind { - BlockBox { self.reflow_block(available_width) } - InlineBox { self.reflow_inline(available_width) } - IntrinsicBox(size) { self.reflow_intrinsic(*size) } - TextBox(subbox) { self.reflow_text(available_width, subbox) } + BlockBox => self.reflow_block(available_width), + InlineBox => self.reflow_inline(available_width), + IntrinsicBox(size) => self.reflow_intrinsic(*size), + TextBox(subbox) => self.reflow_text(available_width, subbox) } } diff --git a/servo/src/servo/layout/box_builder.rs b/servo/src/servo/layout/box_builder.rs index 1df99eeb449f..938273bbc634 100644 --- a/servo/src/servo/layout/box_builder.rs +++ b/servo/src/servo/layout/box_builder.rs @@ -55,12 +55,10 @@ impl methods for ctxt { // Add the child's box to the current enclosing box or the current anonymous box. alt kid.get_specified_style().display_type { - some(DisBlock) { - BTree.add_child(self.parent_box, kid_box); - } - some(DisInline) { + some(DisBlock) => BTree.add_child(self.parent_box, kid_box), + some(DisInline) => { let anon_box = alt self.anon_box { - none { + none => { // // The anonymous box inherits the attributes of its parents for now, so // that properties of intrinsic boxes are not spread to their parenting @@ -73,14 +71,14 @@ impl methods for ctxt { self.anon_box = some(b); b } - some(b) { b } + some(b) => b }; BTree.add_child(anon_box, kid_box); } - some(DisNone) { + some(DisNone) => { // Nothing to do. } - _ { //hack for now + _ => { //hack for now } } } @@ -104,18 +102,18 @@ impl methods for ctxt { // Add the child's box to the current enclosing box. alt kid.get_specified_style().display_type { - some(DisBlock) { + some(DisBlock) => { // TODO #warn("TODO: non-inline display found inside inline box"); BTree.add_child(self.parent_box, kid_box); } - some(DisInline) { + some(DisInline) => { BTree.add_child(self.parent_box, kid_box); } - some(DisNone) { + some(DisNone) => { // Nothing to do. } - _ { //hack for now + _ => { //hack for now } } } @@ -127,10 +125,10 @@ impl methods for ctxt { self.parent_node.dump(); alt self.parent_node.get_specified_style().display_type { - some(DisBlock) { self.construct_boxes_for_block_children(); } - some(DisInline) { self.construct_boxes_for_inline_children(); } - some(DisNone) { /* Nothing to do. */ } - _ { //hack for now + some(DisBlock) => self.construct_boxes_for_block_children(), + some(DisInline) => self.construct_boxes_for_inline_children(), + some(DisNone) => { /* Nothing to do. */ } + _ => { //hack for now } } @@ -144,8 +142,8 @@ impl methods for ctxt { "] fn finish_anonymous_box_if_necessary() { alt copy self.anon_box { - none { /* Nothing to do. */ } - some(b) { BTree.add_child(self.parent_box, b); } + none => { /* Nothing to do. */ } + some(b) => BTree.add_child(self.parent_box, b) } self.anon_box = none; } @@ -162,14 +160,12 @@ impl box_builder_priv of box_builder_priv for Node { "] fn determine_box_kind() -> BoxKind { alt self.read(|n| copy n.kind) { - ~Text(string) { - TextBox(@text_box(copy string)) - } - ~Element(element) { + ~Text(string) => TextBox(@text_box(copy string)), + ~Element(element) => { alt *element.kind { - HTMLDivElement { BlockBox } - HTMLImageElement({size}) { IntrinsicBox(@size) } - UnknownElement { InlineBox } + HTMLDivElement => BlockBox, + HTMLImageElement({size}) => IntrinsicBox(@size), + UnknownElement => InlineBox } } } @@ -186,11 +182,11 @@ impl box_builder_methods of box_builder_methods for Node { let box_kind = self.determine_box_kind(); let my_box = @Box(self, box_kind); alt box_kind { - BlockBox | InlineBox { + BlockBox | InlineBox => { let cx = create_context(self, my_box); cx.construct_boxes_for_children(); } - _ { + _ => { // Nothing to do. } } diff --git a/servo/src/servo/layout/display_list_builder.rs b/servo/src/servo/layout/display_list_builder.rs index b301ed317a5a..4760c268e2bb 100644 --- a/servo/src/servo/layout/display_list_builder.rs +++ b/servo/src/servo/layout/display_list_builder.rs @@ -65,7 +65,7 @@ Creates a display list item for a single block. * `origin` - The coordinates of upper-left corner of the passed in box. "] -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D) { #debug("request to display a box from origin %?", origin); @@ -73,7 +73,7 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D) let col = box.appearance.background_color; alt box.kind { - TextBox(subbox) { + TextBox(subbox) => { let run = copy subbox.run; assert run.is_some(); list.push(dl::display_item({ @@ -86,7 +86,7 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D) })); return; } - _ { + _ => { // Fall through } }; @@ -118,14 +118,16 @@ fn should_convert_text_boxes_to_solid_color_background_items() { let s = Scope(); let n = s.new_node(Text(~"firecracker")); let b = n.construct_boxes(); - let subbox = alt check b.kind { TextBox(subbox) { subbox } }; + + let subbox = alt check b.kind { TextBox(subbox) => subbox }; + b.reflow_text(px_to_au(800), subbox); let list = dvec(); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); alt list[0].item_type { - dl::display_item_solid_color(*) { } - _ { fail } + dl::display_item_solid_color(*) => { } + _ => { fail } } } @@ -137,14 +139,16 @@ fn should_convert_text_boxes_to_text_items() { let s = Scope(); let n = s.new_node(Text(~"firecracker")); let b = n.construct_boxes(); - let subbox = alt check b.kind { TextBox(subbox) { subbox } }; + + let subbox = alt check b.kind { TextBox(subbox) => { subbox } }; + b.reflow_text(px_to_au(800), subbox); let list = dvec(); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); alt list[1].item_type { - dl::display_item_text(_) { } - _ { fail } + dl::display_item_text(_) => { } + _ => { fail } } } @@ -155,7 +159,9 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() { let s = Scope(); let n = s.new_node(Text(~"firecracker")); let b = n.construct_boxes(); - let subbox = alt check b.kind { TextBox(subbox) { subbox } }; + + let subbox = alt check b.kind { TextBox(subbox) => { subbox } }; + b.reflow_text(px_to_au(800), subbox); let list = dvec(); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); @@ -175,7 +181,9 @@ fn should_calculate_the_bounds_of_the_text_items() { let s = Scope(); let n = s.new_node(Text(~"firecracker")); let b = n.construct_boxes(); - let subbox = alt check b.kind { TextBox(subbox) { subbox } }; + + let subbox = alt check b.kind { TextBox(subbox) => { subbox } }; + b.reflow_text(px_to_au(800), subbox); let list = dvec(); box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0))); diff --git a/servo/src/servo/layout/layout_task.rs b/servo/src/servo/layout/layout_task.rs index 82ec2bd29e04..54284a07c916 100644 --- a/servo/src/servo/layout/layout_task.rs +++ b/servo/src/servo/layout/layout_task.rs @@ -21,41 +21,39 @@ import comm::*; type Layout = chan; enum Msg { - BuildMsg(Node, Stylesheet), + BuildMsg(Node, arc), PingMsg(chan), ExitMsg } fn Layout(renderer: Renderer) -> Layout { - spawn_listener::(|request| { + do spawn_listener::|request| { loop { alt request.recv() { - PingMsg(ping_channel) { - ping_channel.send(content::PongMsg); - } - ExitMsg { - #debug("layout: ExitMsg received"); - break; - } - BuildMsg(node, styles) { - #debug("layout: received layout request for:"); - node.dump(); - - do util::time::time(~"layout") { - node.initialize_style_for_subtree(); - node.recompute_style_for_subtree(arc(copy styles)); - - let this_box = node.construct_boxes(); - this_box.dump(); - - this_box.apply_css_style(); - this_box.reflow(px_to_au(800)); - - let dlist = build_display_list(this_box); - renderer.send(renderer::RenderMsg(dlist)); - } + PingMsg(ping_channel) => ping_channel.send(content::PongMsg), + ExitMsg => { + #debug("layout: ExitMsg received"); + break; + } + BuildMsg(node, styles) => { + #debug("layout: received layout request for:"); + node.dump(); + + do util::time::time(~"layout") { + node.initialize_style_for_subtree(); + node.recompute_style_for_subtree(styles); + + let this_box = node.construct_boxes(); + this_box.dump(); + + this_box.apply_css_style(); + this_box.reflow(px_to_au(800)); + + let dlist = build_display_list(this_box); + renderer.send(renderer::RenderMsg(dlist)); } + } } } - }) + } } diff --git a/servo/src/servo/layout/style/apply.rs b/servo/src/servo/layout/style/apply.rs index 606b3900b41a..155abf5bcd04 100644 --- a/servo/src/servo/layout/style/apply.rs +++ b/servo/src/servo/layout/style/apply.rs @@ -34,16 +34,16 @@ impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box { // Right now, we only handle images. do self.node.read |node| { alt node.kind { - ~Element(element) { + ~Element(element) => { let style = self.node.get_specified_style(); self.appearance.background_color = alt style.background_color { - some(col) { col } - none { node.kind.default_color() } + some(col) => col, + none => node.kind.default_color() }; alt element.kind { - ~HTMLImageElement(*) { + ~HTMLImageElement(*) => { let url = element.get_attr(~"src"); if url.is_some() { @@ -52,10 +52,10 @@ impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box { self.appearance.background_image = some(ImageHolder(option::unwrap(url))) }; } - _ { /* Ignore. */ } + _ => { /* Ignore. */ } } } - _ { /* Ignore. */ } + _ => { /* Ignore. */ } } } } diff --git a/servo/src/servo/layout/style/matching.rs b/servo/src/servo/layout/style/matching.rs index 91dcb0920f4e..e487d639c3ae 100644 --- a/servo/src/servo/layout/style/matching.rs +++ b/servo/src/servo/layout/style/matching.rs @@ -14,41 +14,41 @@ export matching_methods; #[doc="Check if a CSS attribute matches the attribute of an HTML element."] fn attrs_match(attr: Attr, elmt: ElementData) -> bool { alt attr { - Exists(name) { + Exists(name) => { alt elmt.get_attr(name) { - some(_) { return true; } - none { return false; } + some(_) => true, + none => false } } - Exact(name, val) { + Exact(name, val) => { alt elmt.get_attr(name) { - some(value) { return value == val; } - none { return false; } + some(value) => value == val, + none => false } } - Includes(name, val) { + Includes(name, val) => { // Comply with css spec, if the specified attribute is empty // it cannot match. if val == ~"" { return false; } alt elmt.get_attr(name) { - some(value) { return value.split_char(' ').contains(val); } - none { return false; } + some(value) => value.split_char(' ').contains(val), + none => false } } - StartsWith(name, val) { + StartsWith(name, val) => { alt elmt.get_attr(name) { - some(value) { + some(value) => { //check that there is only one attribute value and it //starts with the perscribed value if !value.starts_with(val) || value.contains(~" ") { return false; } // We match on either the exact value or value-foo - if value.len() == val.len() { return true; } - else { return value.starts_with(val + ~"-"); } + if value.len() == val.len() { true } + else { value.starts_with(val + ~"-") } } - none { - return false; + none => { + false } } } @@ -67,10 +67,10 @@ impl priv_matching_methods of priv_matching_methods for Node { "] fn matches_element(sel: ~Selector) -> bool { alt *sel { - Child(_, _) | Descendant(_, _) | Sibling(_, _) { return false; } - Element(tag, attrs) { + Child(_, _) | Descendant(_, _) | Sibling(_, _) => { return false; } + Element(tag, attrs) => { alt self.read(|n| copy *n.kind) { - base::Element(elmt) { + base::Element(elmt) => { if !(tag == ~"*" || tag == elmt.tag_name) { return false; } @@ -83,7 +83,7 @@ impl priv_matching_methods of priv_matching_methods for Node { return true; } - Text(str) { /*fall through, currently unsupported*/ } + Text(str) => { /*fall through, currently unsupported*/ } } } } @@ -95,70 +95,65 @@ impl priv_matching_methods of priv_matching_methods for Node { #[doc = "Checks if a generic CSS selector matches a given HTML element"] fn matches_selector(sel : ~Selector) -> bool { alt *sel { - Element(str, atts) { return self.matches_element(sel); } - Child(sel1, sel2) { - alt self.read(|n| n.tree.parent) { - some(parent) { - return self.matches_element(sel2) && - parent.matches_selector(sel1); - } - none { return false; } + Element(str, atts) => { return self.matches_element(sel); } + Child(sel1, sel2) => { + return alt self.read(|n| n.tree.parent) { + some(parent) => self.matches_element(sel2) && parent.matches_selector(sel1), + none => false } } - Descendant(sel1, sel2) { - if !self.matches_element(sel2) { - return false; - } + Descendant(sel1, sel2) => { + if !self.matches_element(sel2) { return false; } //loop over all ancestors to check if they are the person //we should be descended from. let mut cur_parent = alt self.read(|n| n.tree.parent) { - some(parent) { parent } - none { return false; } + some(parent) => parent, + none => return false }; loop { if cur_parent.matches_selector(sel1) { return true; } cur_parent = alt cur_parent.read(|n| n.tree.parent) { - some(parent) { parent } - none { return false; } + some(parent) => parent, + none => return false }; } } - Sibling(sel1, sel2) { + Sibling(sel1, sel2) => { if !self.matches_element(sel2) { return false; } // Loop over this node's previous siblings to see if they match. alt self.read(|n| n.tree.prev_sibling) { - some(sib) { + some(sib) => { let mut cur_sib = sib; loop { if cur_sib.matches_selector(sel1) { return true; } cur_sib = alt cur_sib.read(|n| n.tree.prev_sibling) { - some(sib) { sib } - none { break; } + some(sib) => sib, + none => { break; } }; } } - none { } + none => { } } // check the rest of the siblings alt self.read(|n| n.tree.next_sibling) { - some(sib) { + some(sib) => { let mut cur_sib = sib; loop { if cur_sib.matches_selector(sel1) { return true; } cur_sib = alt cur_sib.read(|n| n.tree.next_sibling) { - some(sib) { sib } - none { break; } + some(sib) => sib, + none => { break; } }; } } - none { } + none => { } } return false; @@ -176,13 +171,13 @@ impl priv_style_methods of priv_style_methods for Node { fn update_style(decl : StyleDeclaration) { self.aux(|layout| { alt decl { - BackgroundColor(col) { layout.specified_style.background_color = some(col); } - Display(dis) { layout.specified_style.display_type = some(dis); } - FontSize(size) { layout.specified_style.font_size = some(size); } - Height(size) { layout.specified_style.height = some(size); } - TextColor(col) { layout.specified_style.text_color = some(col); } - Width(size) { layout.specified_style.width = some(size); } - } + BackgroundColor(col) => layout.specified_style.background_color = some(col), + Display(dis) => layout.specified_style.display_type = some(dis), + FontSize(size) => layout.specified_style.font_size = some(size), + Height(size) => layout.specified_style.height = some(size), + TextColor(col) => layout.specified_style.text_color = some(col), + Width(size) => layout.specified_style.width = some(size) + }; }) } } @@ -222,7 +217,7 @@ mod test { import dvec::{dvec, extensions}; import io::println; - #[warn(no_non_implicitly_copyable_typarams)] + #[allow(non_implicitly_copyable_typarams)] fn new_node_from_attr(scope: NodeScope, -name: ~str, -val: ~str) -> Node { let elmt = ElementData(~"div", ~HTMLDivElement); let attr = ~Attr(name, val); diff --git a/servo/src/servo/layout/style/style.rs b/servo/src/servo/layout/style/style.rs index b962913e8a0d..6a3ea4b8fb2e 100644 --- a/servo/src/servo/layout/style/style.rs +++ b/servo/src/servo/layout/style/style.rs @@ -30,8 +30,8 @@ trait default_style_methods { impl default_style_methods of default_style_methods for NodeKind { fn default_color() -> Color { alt self { - Text(*) { white() } - Element(*) { + Text(*) => { white() } + Element(*) => { let r = rand::rng(); rgb(r.next() as u8, r.next() as u8, r.next() as u8) } @@ -40,13 +40,13 @@ impl default_style_methods of default_style_methods for NodeKind { fn default_display_type() -> DisplayType { alt self { - Text(*) { DisInline } - Element(element) { + Text(*) => { DisInline } + Element(element) => { alt *element.kind { - HTMLDivElement { DisBlock } - HTMLHeadElement { DisNone } - HTMLImageElement(*) { DisInline } - UnknownElement { DisInline } + HTMLDivElement => DisBlock, + HTMLHeadElement => DisNone, + HTMLImageElement(*) => DisInline, + UnknownElement => DisInline } } } diff --git a/servo/src/servo/layout/text.rs b/servo/src/servo/layout/text.rs index 5095ecfddb23..035a2ebabdc2 100644 --- a/servo/src/servo/layout/text.rs +++ b/servo/src/servo/layout/text.rs @@ -24,8 +24,8 @@ trait text_layout_methods { impl text_layout_methods of text_layout_methods for @Box { fn reflow_text(_available_width: au, subbox: @text_box) { alt self.kind { - TextBox(*) { /* ok */ } - _ { fail ~"expected text box in reflow_text!" } + TextBox(*) => { /* ok */ } + _ => { fail ~"expected text box in reflow_text!" } }; // FIXME: The font library should not be initialized here @@ -51,7 +51,7 @@ fn should_calculate_the_size_of_the_text_box() { let n = s.new_node(Text(~"firecracker")); let b = n.construct_boxes(); - let subbox = alt check b.kind { TextBox(subbox) { subbox } }; + let subbox = alt check b.kind { TextBox(subbox) => { subbox } }; b.reflow_text(px_to_au(800), subbox); let expected = Size2D(px_to_au(84), px_to_au(20)); assert b.bounds.size == expected; diff --git a/servo/src/servo/layout/traverse.rs b/servo/src/servo/layout/traverse.rs index e137e257ae1f..3f7748bd6d95 100644 --- a/servo/src/servo/layout/traverse.rs +++ b/servo/src/servo/layout/traverse.rs @@ -88,7 +88,7 @@ fn traverse_helper(-root : @Box, -top_down : fn~(@Box), -bottom_up : fn~(@Box)) } #[doc="A noneffectful function to be used if only one pass is required."] -fn nop(box : @Box) { +fn nop(_box : @Box) { return; } diff --git a/servo/src/servo/opts.rs b/servo/src/servo/opts.rs index f287e5e256eb..88f0898163a2 100644 --- a/servo/src/servo/opts.rs +++ b/servo/src/servo/opts.rs @@ -15,7 +15,7 @@ enum RenderMode { Png(~str) } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn from_cmdline_args(args: ~[~str]) -> Opts { import std::getopts; @@ -26,8 +26,8 @@ fn from_cmdline_args(args: ~[~str]) -> Opts { ]; let opt_match = alt getopts::getopts(args, opts) { - result::ok(m) { copy m } - result::err(f) { fail getopts::fail_str(f) } + result::ok(m) => { copy m } + result::err(f) => { fail getopts::fail_str(f) } }; let urls = if opt_match.free.is_empty() { @@ -37,8 +37,8 @@ fn from_cmdline_args(args: ~[~str]) -> Opts { }; let render_mode = alt getopts::opt_maybe_str(opt_match, ~"o") { - some(output_file) { Png(copy output_file) } - none { Screen } + some(output_file) => { Png(copy output_file) } + none => { Screen } }; { diff --git a/servo/src/servo/parser/css_builder.rs b/servo/src/servo/parser/css_builder.rs index 94b2b0abbbb4..814fa7c1350c 100644 --- a/servo/src/servo/parser/css_builder.rs +++ b/servo/src/servo/parser/css_builder.rs @@ -27,8 +27,8 @@ trait util_methods { impl util_methods of util_methods for TokenReader { fn get() -> Token { alt copy self.lookahead { - some(tok) { self.lookahead = none; copy tok } - none { self.stream.recv() } + some(tok) => { self.lookahead = none; copy tok } + none => { self.stream.recv() } } } @@ -49,9 +49,9 @@ impl parser_methods of parser_methods for TokenReader { fn parse_element() -> option<~style::Selector> { // Get the current element type let elmt_name = alt self.get() { - Element(tag) { copy tag } - Eof { return none; } - _ { fail ~"Expected an element" } + Element(tag) => { copy tag } + Eof => { return none; } + _ => { fail ~"Expected an element" } }; let mut attr_list = ~[]; @@ -60,15 +60,15 @@ impl parser_methods of parser_methods for TokenReader { loop { let tok = self.get(); alt tok { - Attr(attr) { push(attr_list, copy attr); } - StartDescription | Descendant | Child | Sibling | Comma { + Attr(attr) => { push(attr_list, copy attr); } + StartDescription | Descendant | Child | Sibling | Comma => { self.unget(tok); break; } - Eof { return none; } - Element(_) { fail ~"Unexpected second element without relation to first element"; } - EndDescription { fail ~"Unexpected '}'"; } - Description(_, _) { fail ~"Unexpected description"; } + Eof => { return none; } + Element(_) => fail ~"Unexpected second element without relation to first element", + EndDescription => fail ~"Unexpected '}'", + Description(_, _) => fail ~"Unexpected description" } } return some(~style::Element(elmt_name, attr_list)); @@ -82,8 +82,8 @@ impl parser_methods of parser_methods for TokenReader { let mut cur_sel; alt self.parse_element() { - some(elmt) { cur_sel = copy elmt; } - none { return none; } // we hit an eof in the middle of a rule + some(elmt) => { cur_sel = copy elmt; } + none => { return none; } // we hit an eof in the middle of a rule } loop { @@ -91,47 +91,47 @@ impl parser_methods of parser_methods for TokenReader { let built_sel <- cur_sel; alt tok { - Descendant { + Descendant => { alt self.parse_element() { - some(elmt) { + some(elmt) => { let new_sel = copy elmt; cur_sel <- ~style::Descendant(built_sel, new_sel) } - none { return none; } + none => { return none; } } } - Child { + Child => { alt self.parse_element() { - some(elmt) { + some(elmt) => { let new_sel = copy elmt; cur_sel <- ~style::Child(built_sel, new_sel) } - none { return none; } + none => { return none; } } } - Sibling { + Sibling => { alt self.parse_element() { - some(elmt) { + some(elmt) => { let new_sel = copy elmt; cur_sel <- ~style::Sibling(built_sel, new_sel) } - none { return none; } + none => { return none; } } } - StartDescription { + StartDescription => { push(sel_list, built_sel); self.unget(StartDescription); break; } - Comma { + Comma => { push(sel_list, built_sel); self.unget(Comma); break; } - Attr(_) | EndDescription | Element(_) | Description(_, _) { + Attr(_) | EndDescription | Element(_) | Description(_, _) => { fail #fmt["Unexpected token %? in elements", tok]; } - Eof { return none; } + Eof => { return none; } } } @@ -139,9 +139,9 @@ impl parser_methods of parser_methods for TokenReader { // TODO: fix this when rust gets labelled loops let tok = self.get(); alt tok { - StartDescription { break; } - Comma { } - _ { self.unget(tok); } + StartDescription => { break; } + Comma => { } + _ => { self.unget(tok); } } } @@ -155,22 +155,22 @@ impl parser_methods of parser_methods for TokenReader { loop { let tok = self.get(); alt tok { - EndDescription { break; } - Description(prop, val) { + EndDescription => { break; } + Description(prop, val) => { let desc = alt prop { // TODO: have color parsing return an option instead of a real value - ~"background-color" { parse_color(val).map(|res| BackgroundColor(res)) } - ~"color" { parse_color(val).map(|res| TextColor(res)) } - ~"display" { parse_display_type(val).map(|res| Display(res)) } - ~"font-size" { parse_font_size(val).map(|res| FontSize(res)) } - ~"height" { parse_size(val).map(|res| Height(res)) } - ~"width" { parse_size(val).map(|res| Width(res)) } - _ { #debug["Recieved unknown style property '%s'", val]; none } + ~"background-color" => parse_color(val).map(|res| BackgroundColor(res)), + ~"color" => parse_color(val).map(|res| TextColor(res)), + ~"display" => parse_display_type(val).map(|res| Display(res)), + ~"font-size" => parse_font_size(val).map(|res| FontSize(res)), + ~"height" => parse_size(val).map(|res| Height(res)), + ~"width" => parse_size(val).map(|res| Width(res)), + _ => { #debug["Recieved unknown style property '%s'", val]; none } }; desc.map(|res| push(desc_list, res)); } - Eof { return none; } - StartDescription | Descendant | Child | Sibling | Comma | Element(_) | Attr(_) { + Eof => { return none; } + StartDescription | Descendant | Child | Sibling | Comma | Element(_) | Attr(_) => { fail #fmt["Unexpected token %? in description", tok]; } } @@ -180,17 +180,18 @@ impl parser_methods of parser_methods for TokenReader { } fn parse_rule() -> option<~style::Rule> { + // TODO: get rid of copies once alt move works let sel_list = alt self.parse_selector() { - some(list){ copy list } - none { return none; } + some(list) => { copy list } + none => { return none; } }; #debug("sel_list: %?", sel_list); // Get the description to be applied to the selector let desc_list = alt self.parse_description() { - some(list) { copy list } - none { return none; } + some(list) => { copy list } + none => { return none; } }; #debug("desc_list: %?", desc_list); @@ -205,8 +206,8 @@ fn build_stylesheet(+stream : pipes::port) -> ~[~style::Rule] { loop { alt reader.parse_rule() { - some(rule) { push(rule_list, copy rule); } - none { break; } + some(rule) => { push(rule_list, copy rule); } + none => { break; } } } diff --git a/servo/src/servo/parser/css_lexer.rs b/servo/src/servo/parser/css_lexer.rs index 145df96afcf5..a2a2b15be51f 100644 --- a/servo/src/servo/parser/css_lexer.rs +++ b/servo/src/servo/parser/css_lexer.rs @@ -50,15 +50,15 @@ impl css_methods of css_methods for CssLexer { fn parse_css() -> Token { let mut ch: u8; alt self.input_state.get() { - CoeChar(c) { ch = c; } - CoeEof { return Eof; } + CoeChar(c) => ch = c, + CoeEof => { return Eof; } } let token = alt self.parser_state { - CssDescription { self.parse_css_description(ch) } - CssAttribute { self.parse_css_attribute(ch) } - CssElement { self.parse_css_element(ch) } - CssRelation { self.parse_css_relation(ch) } + CssDescription => self.parse_css_description(ch), + CssAttribute => self.parse_css_attribute(ch), + CssElement => self.parse_css_element(ch), + CssRelation => self.parse_css_relation(ch) }; #debug["token=%?", token]; @@ -69,11 +69,11 @@ impl css_methods of css_methods for CssLexer { self.parser_state = CssElement; let token = alt c { - '{' as u8 { self.parser_state = CssDescription; StartDescription } - '>' as u8 { Child } - '+' as u8 { Sibling } - ',' as u8 { Comma } - _ { self.input_state.unget(c); Descendant } + '{' as u8 => { self.parser_state = CssDescription; StartDescription } + '>' as u8 => { Child } + '+' as u8 => { Sibling } + ',' as u8 => { Comma } + _ => { self.input_state.unget(c); Descendant } }; self.input_state.eat_whitespace(); @@ -113,22 +113,22 @@ impl css_methods of css_methods for CssLexer { self.input_state.eat_whitespace(); alt self.input_state.get() { - CoeChar(c) { ch = c } - CoeEof { fail ~"File ended before description of style" } + CoeChar(c) => { ch = c } + CoeEof => { fail ~"File ended before description of style" } } return self.parse_css_relation(ch); } alt ch { - '.' as u8 { return Attr(style::Includes(~"class", self.input_state.parse_ident())); } - '#' as u8 { return Attr(style::Includes(~"id", self.input_state.parse_ident())); } - '[' as u8 { + '.' as u8 => return Attr(style::Includes(~"class", self.input_state.parse_ident())), + '#' as u8 => return Attr(style::Includes(~"id", self.input_state.parse_ident())), + '[' as u8 => { let attr_name = self.input_state.parse_ident(); alt self.input_state.get() { - CoeChar(c) { ch = c; } - CoeEof { fail ~"File ended before description finished"; } + CoeChar(c) => { ch = c; } + CoeEof => { fail ~"File ended before description finished"; } } if ch == ']' as u8 { @@ -151,7 +151,7 @@ impl css_methods of css_methods for CssLexer { fail #fmt("Unexpected symbol %c in attribute", ch as char); } - _ { fail #fmt("Unexpected symbol %c in attribute", ch as char); } + _ => { fail #fmt("Unexpected symbol %c in attribute", ch as char); } } } @@ -166,8 +166,8 @@ impl css_methods of css_methods for CssLexer { self.input_state.eat_whitespace(); alt self.input_state.get() { - CoeChar(c) { ch = c } - CoeEof { fail ~"Reached end of file in CSS description" } + CoeChar(c) => { ch = c } + CoeEof => { fail ~"Reached end of file in CSS description" } } } @@ -188,8 +188,8 @@ impl css_methods of css_methods for CssLexer { } alt self.input_state.get() { - CoeChar(c) { ch = c } - CoeEof { fail ~"Reached end of file in CSS description" } + CoeChar(c) => { ch = c } + CoeEof => { fail ~"Reached end of file in CSS description" } } } @@ -199,8 +199,8 @@ impl css_methods of css_methods for CssLexer { // Get the value of the descriptor loop { alt self.input_state.get() { - CoeChar(c) { ch = c } - CoeEof { fail ~"Reached end of file in CSS description" } + CoeChar(c) => { ch = c } + CoeEof => { fail ~"Reached end of file in CSS description" } } if ch.is_whitespace() { @@ -259,7 +259,6 @@ fn spawn_css_lexer_from_string(-content : ~str) -> pipes::port { do task::spawn { let input_port = comm::port(); - let chan = input_port.chan(); input_port.send(Payload(str::bytes(content))); input_port.send(Done(ok(()))); @@ -269,17 +268,18 @@ fn spawn_css_lexer_from_string(-content : ~str) -> pipes::port { return result_port; } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn spawn_css_lexer_task(-url: url, resource_task: ResourceTask) -> pipes::port { let (result_chan, result_port) = pipes::stream(); - task::spawn(|| { + do task::spawn || { assert url.path.ends_with(".css"); let input_port = port(); - resource_task.send(Load(url, input_port.chan())); + // TODO: change copy to move once the compiler permits it + resource_task.send(Load(copy url, input_port.chan())); lex_css_from_bytes(input_port, result_chan); - }); + }; return result_port; } diff --git a/servo/src/servo/parser/html_builder.rs b/servo/src/servo/parser/html_builder.rs index a409db9360fe..d033987d5559 100644 --- a/servo/src/servo/parser/html_builder.rs +++ b/servo/src/servo/parser/html_builder.rs @@ -28,40 +28,40 @@ enum js_message { js_exit } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) { // TODO: Implement atoms so that we don't always perform string comparisons. scope.read(node, |node_contents| { alt *node_contents.kind { - Element(element) { + Element(element) => { element.attrs.push(~Attr(copy key, copy value)); alt *element.kind { - HTMLImageElement(img) if key == ~"width" { + HTMLImageElement(img) if key == ~"width" => { alt int::from_str(value) { - none { + none => { // Drop on the floor. } - some(s) { img.size.width = geometry::px_to_au(s); } + some(s) => { img.size.width = geometry::px_to_au(s); } } } - HTMLImageElement(img) if key == ~"height" { + HTMLImageElement(img) if key == ~"height" => { alt int::from_str(value) { - none { + none => { // Drop on the floor. } - some(s) { + some(s) => { img.size.height = geometry::px_to_au(s); } } } HTMLDivElement | HTMLImageElement(*) | HTMLHeadElement | - HTMLScriptElement | UnknownElement { + HTMLScriptElement | UnknownElement => { // Drop on the floor. } } } - Text(*) { + Text(*) => { fail ~"attempt to link up an attribute to a text node" } } @@ -70,16 +70,15 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) { fn build_element_kind(tag_name: ~str) -> ~ElementKind { alt tag_name { - ~"div" { ~HTMLDivElement } - ~"img" { - ~HTMLImageElement({ - mut size: Size2D(geometry::px_to_au(100), - geometry::px_to_au(100)) + ~"div" => ~HTMLDivElement, + ~"img" => { + ~HTMLImageElement({ mut size: Size2D(geometry::px_to_au(100), + geometry::px_to_au(100)) }) } - ~"script" { ~HTMLScriptElement } - ~"head" { ~HTMLHeadElement } - _ { ~UnknownElement } + ~"script" => ~HTMLScriptElement, + ~"head" => ~HTMLHeadElement, + _ => ~UnknownElement } } @@ -103,10 +102,13 @@ fn css_link_listener(to_parent : comm::chan, from_parent : comm::por loop { alt from_parent.recv() { - File(url) { + File(url) => { let result_port = comm::port(); let result_chan = comm::chan(result_port); + // TODO: change copy to move once we have alt move + let url = copy url; task::spawn(|| { + // TODO: change copy to move once we can move into closures let css_stream = css_lexer::spawn_css_lexer_task(copy url, resource_task); let mut css_rules = css_builder::build_stylesheet(css_stream); result_chan.send(css_rules); @@ -114,7 +116,7 @@ fn css_link_listener(to_parent : comm::chan, from_parent : comm::por push(result_vec, result_port); } - Exit { + Exit => { break; } } @@ -131,24 +133,27 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port loop { alt from_parent.recv() { - js_file(url) { + js_file(url) => { let result_port = comm::port(); let result_chan = comm::chan(result_port); - do task::spawn { + // TODO: change copy to move once we have alt move + let url = copy url; + do task::spawn || { let input_port = port(); - resource_task.send(Load(url, input_port.chan())); + // TODO: change copy to move once we can move into closures + resource_task.send(Load(copy url, input_port.chan())); let mut buf = ~[]; loop { alt input_port.recv() { - Payload(data) { + Payload(data) => { buf += data; } - Done(ok(*)) { + Done(ok(*)) => { result_chan.send(buf); break; } - Done(err(*)) { + Done(err(*)) => { #error("error loading script %s", url.to_str()); } } @@ -156,7 +161,7 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port } push(result_vec, result_port); } - js_exit { + js_exit => { break; } } @@ -166,7 +171,7 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port to_parent.send(js_scripts); } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn build_dom(scope: NodeScope, stream: comm::port, url: url, resource_task: ResourceTask) -> (Node, comm::port, comm::port<~[~[u8]]>) { // The current reference node. @@ -191,75 +196,75 @@ fn build_dom(scope: NodeScope, stream: comm::port, url: url, loop { let token = stream.recv(); alt token { - parser::Eof { break; } - parser::StartOpeningTag(tag_name) { + parser::Eof => { break; } + parser::StartOpeningTag(tag_name) => { #debug["starting tag %s", tag_name]; let element_kind = build_element_kind(tag_name); let new_node = scope.new_node(Element(ElementData(copy tag_name, element_kind))); scope.add_child(cur_node, new_node); cur_node = new_node; } - parser::Attr(key, value) { + parser::Attr(key, value) => { #debug["attr: %? = %?", key, value]; link_up_attribute(scope, cur_node, copy key, copy value); } - parser::EndOpeningTag { + parser::EndOpeningTag => { #debug("end opening tag"); } // TODO: Fail more gracefully (i.e. according to the HTML5 // spec) if we close more tags than we open. - parser::SelfCloseTag { + parser::SelfCloseTag => { //TODO: check for things other than the link tag scope.read(cur_node, |n| { alt *n.kind { - Element(elmt) if elmt.tag_name == ~"link" { + Element(elmt) if elmt.tag_name == ~"link" => { alt elmt.get_attr(~"rel") { - some(r) if r == ~"stylesheet" { + some(r) if r == ~"stylesheet" => { alt elmt.get_attr(~"href") { - some(filename) { + some(filename) => { #debug["Linking to a css sheet named: %s", filename]; // FIXME: Need to base the new url on the current url - let new_url = make_url(filename, some(url)); + let new_url = make_url(filename, some(copy url)); style_chan.send(File(new_url)); } - none { /* fall through*/ } + none => { /* fall through*/ } } } - _ { /* fall through*/ } + _ => { /* fall through*/ } } } - _ { /* fall through*/ } + _ => { /* fall through*/ } } }); cur_node = scope.get_parent(cur_node).get(); } - parser::EndTag(tag_name) { + parser::EndTag(tag_name) => { // TODO: Assert that the closing tag has the right name. scope.read(cur_node, |n| { alt *n.kind { - Element(elmt) if elmt.tag_name == ~"script" { + Element(elmt) if elmt.tag_name == ~"script" => { alt elmt.get_attr(~"src") { - some(filename) { + some(filename) => { #debug["Linking to a js script named: %s", filename]; - let new_url = make_url(filename, some(url)); + let new_url = make_url(filename, some(copy url)); js_chan.send(js_file(new_url)); } - none { /* fall through */ } + none => { /* fall through */ } } } - _ { /* fall though */ } + _ => { /* fall though */ } } }); cur_node = scope.get_parent(cur_node).get(); } - parser::Text(s) if !s.is_whitespace() { + parser::Text(s) if !s.is_whitespace() => { let new_node = scope.new_node(Text(copy s)); scope.add_child(cur_node, new_node); } - parser::Text(_) { + parser::Text(_) => { // FIXME: Whitespace should not be ignored. } - parser::Doctype { + parser::Doctype => { // TODO: Do something here... } } diff --git a/servo/src/servo/parser/html_lexer.rs b/servo/src/servo/parser/html_lexer.rs index 3d9bafa7c33b..9eef05e4cc19 100644 --- a/servo/src/servo/parser/html_lexer.rs +++ b/servo/src/servo/parser/html_lexer.rs @@ -39,12 +39,12 @@ impl html_methods of html_methods for HtmlLexer { fn parse_html() -> Token { let mut ch: u8; alt self.input_state.get() { - CoeChar(c) { ch = c; } - CoeEof { return Eof; } + CoeChar(c) => { ch = c; } + CoeEof => { return Eof; } } let token = alt self.parser_state { - NormalHtml { self.parse_in_normal_state(ch) } - TagHtml { self.parse_in_tag_state(ch) } + NormalHtml => { self.parse_in_normal_state(ch) } + TagHtml => { self.parse_in_tag_state(ch) } }; #debug["token=%?", token]; @@ -55,8 +55,8 @@ impl html_methods of html_methods for HtmlLexer { let mut ch = c; if ch == ('<' as u8) { alt self.input_state.get() { - CoeChar(c) { ch = c; } - CoeEof { self.input_state.parse_err(~"eof after '<'") } + CoeChar(c) => { ch = c; } + CoeEof => { self.input_state.parse_err(~"eof after '<'") } } if ch == ('!' as u8) { @@ -89,14 +89,14 @@ impl html_methods of html_methods for HtmlLexer { let mut s: ~[u8] = ~[ch]; loop { alt self.input_state.get() { - CoeChar(c) { + CoeChar(c) => { if c == ('<' as u8) { self.input_state.unget(c); return Text(from_bytes(s)); } push(s, c); } - CoeEof { return Text(from_bytes(s)); } + CoeEof => { return Text(from_bytes(s)); } } } } @@ -111,7 +111,7 @@ impl html_methods of html_methods for HtmlLexer { if ch == ('/' as u8) { alt self.input_state.get() { - CoeChar(c) { + CoeChar(c) => { if c == ('>' as u8) { self.parser_state = NormalHtml; return SelfCloseTag; @@ -119,7 +119,7 @@ impl html_methods of html_methods for HtmlLexer { #warn["/ not followed by > in a tag"]; } } - CoeEof { + CoeEof => { #warn["/ not followed by > at end of file"]; } } @@ -133,11 +133,11 @@ impl html_methods of html_methods for HtmlLexer { let mut attribute_name = ~[ch]; loop { alt self.input_state.get() { - CoeChar(c) { + CoeChar(c) => { if c == ('=' as u8) { break; } push(attribute_name, c); } - CoeEof { + CoeEof => { let name = from_bytes(attribute_name); return Attr(copy name, name); } @@ -149,11 +149,11 @@ impl html_methods of html_methods for HtmlLexer { let mut attribute_value = ~[]; loop { alt self.input_state.get() { - CoeChar(c) { + CoeChar(c) => { if c == ('"' as u8) { break; } push(attribute_value, c); } - CoeEof { + CoeEof => { return Attr(from_bytes(attribute_name), from_bytes(attribute_value)); } } @@ -178,14 +178,15 @@ fn lexer(+input_port: port, state : ParseState) -> H }; } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn spawn_html_lexer_task(-url: url, resource_task: ResourceTask) -> port { let html_port = port(); let html_chan = chan(html_port); task::spawn(|| { let input_port = port(); - resource_task.send(Load(url, input_port.chan())); + // TODO: change copy to move once we can move into closures + resource_task.send(Load(copy url, input_port.chan())); let lexer = lexer(input_port, NormalHtml); diff --git a/servo/src/servo/parser/lexer_util.rs b/servo/src/servo/parser/lexer_util.rs index 1f63e246f5d2..ce8cbab0854d 100644 --- a/servo/src/servo/parser/lexer_util.rs +++ b/servo/src/servo/parser/lexer_util.rs @@ -47,12 +47,12 @@ trait util_methods { impl util_methods of util_methods for InputState { fn get() -> CharOrEof { alt copy self.lookahead { - some(coe) { + some(coe) => { let rv = coe; self.lookahead = none; return rv; } - none { + none => { /* fall through */ } } @@ -68,11 +68,12 @@ impl util_methods of util_methods for InputState { } alt self.input_port.recv() { - Payload(data) { - self.buffer = data; + Payload(data) => { + // TODO: change copy to move once we have alt move + self.buffer = copy data; return CoeChar(vec::shift(self.buffer)); } - Done(*) { + Done(*) => { self.eof = true; return CoeEof; } @@ -90,8 +91,8 @@ impl util_methods of util_methods for InputState { fn expect(ch: u8) { alt self.get() { - CoeChar(c) { if c != ch { self.parse_err(#fmt("expected '%c'", ch as char)); } } - CoeEof { self.parse_err(#fmt("expected '%c' at eof", ch as char)); } + CoeChar(c) => { if c != ch { self.parse_err(#fmt("expected '%c'", ch as char)); } } + CoeEof => { self.parse_err(#fmt("expected '%c' at eof", ch as char)); } } } @@ -99,7 +100,7 @@ impl util_methods of util_methods for InputState { let mut result: ~[u8] = ~[]; loop { alt self.get() { - CoeChar(c) { + CoeChar(c) => { if (c.is_alpha()) { push(result, c); } else if result.len() == 0u { self.parse_err(~"expected ident"); } else { @@ -107,7 +108,7 @@ impl util_methods of util_methods for InputState { break; } } - CoeEof { + CoeEof => { self.parse_err(~"expected ident"); } } @@ -125,13 +126,13 @@ impl util_methods of util_methods for InputState { fn eat_whitespace() { loop { alt self.get() { - CoeChar(c) { + CoeChar(c) => { if !c.is_whitespace() { self.unget(c); return; } } - CoeEof { + CoeEof => { return; } } diff --git a/servo/src/servo/parser/parser_util.rs b/servo/src/servo/parser/parser_util.rs index 5d7813ca5690..2cfc2e328b55 100644 --- a/servo/src/servo/parser/parser_util.rs +++ b/servo/src/servo/parser/parser_util.rs @@ -11,16 +11,16 @@ export parse_display_type; fn parse_unit(str : ~str) -> option { alt str { - s if s.ends_with(~"%") { from_str(str.substr(0, str.len() - 1)).map(|f| Percent(f)) } - s if s.ends_with(~"in") { from_str(str.substr(0, str.len() - 2)).map(|f| In(f)) } - s if s.ends_with(~"cm") { from_str(str.substr(0, str.len() - 2)).map(|f| Cm(f)) } - s if s.ends_with(~"mm") { from_str(str.substr(0, str.len() - 2)).map(|f| Mm(f)) } - s if s.ends_with(~"pt") { from_str(str.substr(0, str.len() - 2)).map(|f| Pt(f)) } - s if s.ends_with(~"pc") { from_str(str.substr(0, str.len() - 2)).map(|f| Pc(f)) } - s if s.ends_with(~"px") { from_str(str.substr(0, str.len() - 2)).map(|f| Px(f)) } - s if s.ends_with(~"em") { from_str(str.substr(0, str.len() - 2)).map(|f| Em(f)) } - s if s.ends_with(~"ex") { from_str(str.substr(0, str.len() - 2)).map(|f| Ex(f)) } - _ { none } + s if s.ends_with(~"%") => from_str(str.substr(0, str.len() - 1)).map(|f| Percent(f)), + s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| In(f)), + s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Cm(f)), + s if s.ends_with(~"mm") => from_str(str.substr(0, str.len() - 2)).map(|f| Mm(f)), + s if s.ends_with(~"pt") => from_str(str.substr(0, str.len() - 2)).map(|f| Pt(f)), + s if s.ends_with(~"pc") => from_str(str.substr(0, str.len() - 2)).map(|f| Pc(f)), + s if s.ends_with(~"px") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(f)), + s if s.ends_with(~"em") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(f)), + s if s.ends_with(~"ex") => from_str(str.substr(0, str.len() - 2)).map(|f| Ex(f)), + _ => none, } } @@ -29,35 +29,35 @@ fn parse_font_size(str : ~str) -> option { let default = 16.0; alt str { - ~"xx-small" { some(Px(0.6*default)) } - ~"x-small" { some(Px(0.75*default)) } - ~"small" { some(Px(8.0/9.0*default)) } - ~"medium" { some(Px(default)) } - ~"large" { some(Px(1.2*default)) } - ~"x-large" { some(Px(1.5*default)) } - ~"xx-large" { some(Px(2.0*default)) } - ~"smaller" { some(Em(0.8)) } - ~"larger" { some(Em(1.25)) } - ~"inherit" { some(Em(1.0)) } - _ { parse_unit(str) } + ~"xx-small" => some(Px(0.6*default)), + ~"x-small" => some(Px(0.75*default)), + ~"small" => some(Px(8.0/9.0*default)), + ~"medium" => some(Px(default)), + ~"large" => some(Px(1.2*default)), + ~"x-large" => some(Px(1.5*default)), + ~"xx-large" => some(Px(2.0*default)), + ~"smaller" => some(Em(0.8)), + ~"larger" => some(Em(1.25)), + ~"inherit" => some(Em(1.0)), + _ => parse_unit(str), } } // For width / height, and anything else with the same attribute values fn parse_size(str : ~str) -> option { alt str { - ~"auto" { some(Auto) } - ~"inherit" { some(Em(1.0)) } - _ { parse_unit(str) } + ~"auto" => some(Auto), + ~"inherit" => some(Em(1.0)), + _ => parse_unit(str), } } fn parse_display_type(str : ~str) -> option { alt str { - ~"inline" { some(DisInline) } - ~"block" { some(DisBlock) } - ~"none" { some(DisNone) } - _ { #debug["Recieved unknown display value '%s'", str]; none } + ~"inline" => some(DisInline), + ~"block" => some(DisBlock), + ~"none" => some(DisNone), + _ => { #debug["Recieved unknown display value '%s'", str]; none } } } diff --git a/servo/src/servo/platform/osmain.rs b/servo/src/servo/platform/osmain.rs index 52d6aafe885a..7e2c472b5b56 100644 --- a/servo/src/servo/platform/osmain.rs +++ b/servo/src/servo/platform/osmain.rs @@ -71,16 +71,10 @@ fn mainloop(po: port) { #debug("osmain: peeking"); while po.peek() { alt po.recv() { - AddKeyHandler(key_ch) { - key_handlers.push(#move(key_ch)); - } - AddEventListener(event_listener) { - event_listeners.push(event_listener); - } - BeginDrawing(sender) { - lend_surface(*surfaces, sender); - } - Draw(sender, dt) { + AddKeyHandler(key_ch) => key_handlers.push(#move(key_ch)), + AddEventListener(event_listener) => event_listeners.push(event_listener), + BeginDrawing(sender) => lend_surface(*surfaces, sender), + Draw(sender, dt) => { #debug("osmain: received new frame"); return_surface(*surfaces, dt); lend_surface(*surfaces, sender); @@ -95,7 +89,7 @@ fn mainloop(po: port) { @layers::layers::Image(800, 600, layers::layers::ARGB32Format, image_data); image_layer.set_image(image); } - exit { + exit => { *done = true; } } diff --git a/servo/src/servo/resource/file_loader.rs b/servo/src/servo/resource/file_loader.rs index e5c4eb956814..3e400bfa70c3 100644 --- a/servo/src/servo/resource/file_loader.rs +++ b/servo/src/servo/resource/file_loader.rs @@ -14,16 +14,16 @@ fn factory(url: url, progress_chan: chan) { do spawn { alt file_reader(url.path) { - ok(reader) { + ok(reader) => { while !reader.eof() { let data = reader.read_bytes(READ_SIZE); progress_chan.send(Payload(data)); } progress_chan.send(Done(ok(()))); } - err(*) { + err(*) => { progress_chan.send(Done(err(()))); } }; } -} \ No newline at end of file +} diff --git a/servo/src/servo/resource/http_loader.rs b/servo/src/servo/resource/http_loader.rs index 627303df652a..0dc1c6124478 100644 --- a/servo/src/servo/resource/http_loader.rs +++ b/servo/src/servo/resource/http_loader.rs @@ -11,19 +11,22 @@ fn factory(url: url, progress_chan: chan) { assert url.scheme == ~"http"; do spawn { - #debug("http_loader: requesting via http: %?", url); - let request = uv_http_request(url); + let url = copy url; + + #debug("http_loader: requesting via http: %?", copy url); + let request = uv_http_request(copy url); let errored = @mut false; do request.begin |event| { + let url = copy url; alt event { - http_client::Status(*) { } - http_client::Payload(data) { + http_client::Status(*) => { } + http_client::Payload(data) => { #debug("http_loader: got data from %?", url); let mut crap = none; *data <-> crap; progress_chan.send(Payload(option::unwrap(crap))); } - http_client::Error(*) { + http_client::Error(*) => { #debug("http_loader: error loading %?", url); *errored = true; progress_chan.send(Done(err(()))); diff --git a/servo/src/servo/resource/resource_task.rs b/servo/src/servo/resource/resource_task.rs index 849a7f1dc77c..17e617086d01 100644 --- a/servo/src/servo/resource/resource_task.rs +++ b/servo/src/servo/resource/resource_task.rs @@ -50,7 +50,8 @@ fn ResourceTask() -> ResourceTask { fn create_resource_task_with_loaders(+loaders: ~[(~str, LoaderTaskFactory)]) -> ResourceTask { do spawn_listener |from_client| { - ResourceManager(from_client, loaders).start() + // TODO: change copy to move once we can move into closures + ResourceManager(from_client, copy loaders).start() } } @@ -59,7 +60,7 @@ class ResourceManager { /// Per-scheme resource loaders let loaders: ~[(~str, LoaderTaskFactory)]; - new(from_client: port, loaders: ~[(~str, LoaderTaskFactory)]) { + new(from_client: port, -loaders: ~[(~str, LoaderTaskFactory)]) { self.from_client = from_client; self.loaders = loaders; } @@ -67,10 +68,10 @@ class ResourceManager { fn start() { loop { alt self.from_client.recv() { - Load(url, progress_chan) { + Load(url, progress_chan) => { self.load(url, progress_chan) } - Exit { + Exit => { break } } @@ -80,11 +81,11 @@ class ResourceManager { fn load(url: url, progress_chan: chan) { alt self.get_loader_factory(url) { - some(loader_factory) { + some(loader_factory) => { #debug("resource_task: loading url: %s", url::to_str(url)); loader_factory(url, progress_chan); } - none { + none => { #debug("resource_task: no loader for scheme %s", url.scheme); progress_chan.send(Done(err(()))); } @@ -93,7 +94,7 @@ class ResourceManager { fn get_loader_factory(url: url) -> option { for self.loaders.each |scheme_loader| { - let (scheme, loader_factory) = scheme_loader; + let (scheme, loader_factory) = copy scheme_loader; if scheme == url.scheme { return some(loader_factory); } @@ -109,21 +110,23 @@ fn test_exit() { } #[test] +#[allow(non_implicitly_copyable_typarams)] fn test_bad_scheme() { let resource_task = ResourceTask(); let progress = port(); resource_task.send(Load(url::from_str(~"bogus://whatever").get(), progress.chan())); alt check progress.recv() { - Done(result) { assert result.is_err() } + Done(result) => { assert result.is_err() } } resource_task.send(Exit); } #[test] +#[allow(non_implicitly_copyable_typarams)] fn should_delegate_to_scheme_loader() { let payload = ~[1, 2, 3]; - let loader_factory = fn~(url: url, progress_chan: chan) { - progress_chan.send(Payload(payload)); + let loader_factory = fn~(_url: url, progress_chan: chan) { + progress_chan.send(Payload(copy payload)); progress_chan.send(Done(ok(()))); }; let loader_factories = ~[(~"snicklefritz", loader_factory)]; diff --git a/servo/src/servo/servo.rc b/servo/src/servo/servo.rc index dd4408e2215d..d5efca544bb9 100755 --- a/servo/src/servo/servo.rc +++ b/servo/src/servo/servo.rc @@ -103,7 +103,7 @@ mod util { mod url; } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] mod content { } diff --git a/servo/src/servo/servo.rs b/servo/src/servo/servo.rs index a17989d5979f..9b13c9ffc21a 100644 --- a/servo/src/servo/servo.rs +++ b/servo/src/servo/servo.rs @@ -14,13 +14,11 @@ fn main(args: ~[~str]) { run(opts::from_cmdline_args(args)) } -#[warn(no_non_implicitly_copyable_typarams)] +#[allow(non_implicitly_copyable_typarams)] fn run(opts: Opts) { alt opts.render_mode { - Screen { - run_pipeline_screen(opts.urls) - } - Png(outfile) { + Screen => run_pipeline_screen(opts.urls), + Png(outfile) => { assert opts.urls.is_not_empty(); if opts.urls.len() > 1u { fail ~"servo asks that you stick to a single URL in PNG output mode" @@ -48,9 +46,10 @@ fn run_pipeline_screen(urls: ~[~str]) { #debug["master: Sending url `%s`", url_to_str(url)]; engine_chan.send(LoadURLMsg(url)); #debug["master: Waiting for keypress"]; + alt keypress_from_osmain.try_recv() { - some(*) { } - none { #error("keypress stream closed unexpectedly") } + some(*) => { } + none => { #error("keypress stream closed unexpectedly") } }; } @@ -76,12 +75,12 @@ fn run_pipeline_png(-url: ~str, outfile: ~str) { let engine = Engine(sink); let engine_chan = engine.start(); engine_chan.send(LoadURLMsg(make_url(url, none))); + alt buffered_file_writer(outfile) { - ok(writer) { - writer.write(pngdata_from_sink.recv()) - } - err(e) { fail e } + ok(writer) => writer.write(pngdata_from_sink.recv()), + err(e) => fail e } + let (exit_chan, exit_response_from_engine) = pipes::stream(); engine_chan.send(engine::ExitMsg(exit_chan)); exit_response_from_engine.recv(); diff --git a/servo/src/servo/text/font.rs b/servo/src/servo/text/font.rs index bd638b9539f3..b21eb9fce4cb 100644 --- a/servo/src/servo/text/font.rs +++ b/servo/src/servo/text/font.rs @@ -102,14 +102,14 @@ class Font { 1 as c_int, addr_of(extents)); alt cairo_scaled_font_status(self.cairo_font) { - status if status == CAIRO_STATUS_SUCCESS { + status if status == CAIRO_STATUS_SUCCESS => { #debug("x_advance: %?", extents.x_advance); #debug("y_advance: %?", extents.y_advance); return extents.x_advance as int; } - status { + status => { import str::unsafe::from_c_str; let status_cstr = cairo_status_to_string(status); diff --git a/servo/src/servo/text/native_font/ft_native_font.rs b/servo/src/servo/text/native_font/ft_native_font.rs index e51721f7961a..2e9cfe8689ca 100644 --- a/servo/src/servo/text/native_font/ft_native_font.rs +++ b/servo/src/servo/text/native_font/ft_native_font.rs @@ -68,7 +68,7 @@ class FreeTypeNativeFont/& { fn create(lib: FT_Library, buf: &~[u8]) -> result { assert lib.is_not_null(); let face: FT_Face = null(); - return vec_as_buf(*buf, |cbuf, len| { + return vec_as_buf(*buf, |cbuf, _len| { if FT_New_Memory_Face(lib, cbuf, (*buf).len() as FT_Long, 0 as FT_Long, addr_of(face)).succeeded() { // FIXME: These values are placeholders diff --git a/servo/src/servo/text/shaper.rs b/servo/src/servo/text/shaper.rs index ce4a67e7d7d6..35ad014eba39 100644 --- a/servo/src/servo/text/shaper.rs +++ b/servo/src/servo/text/shaper.rs @@ -112,13 +112,13 @@ extern fn glyph_func(_font: *hb_font_t, assert font.is_not_null(); return alt (*font).glyph_idx(unicode as char) { - some(g) { - *glyph = g as hb_codepoint_t; - true - } - none { - false - } + some(g) => { + *glyph = g as hb_codepoint_t; + true + } + none => { + false + } } as hb_bool_t; } diff --git a/servo/src/servo/util/color.rs b/servo/src/servo/util/color.rs index 0d4244d566c0..29edea33e6c1 100644 --- a/servo/src/servo/util/color.rs +++ b/servo/src/servo/util/color.rs @@ -37,11 +37,11 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color { let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h }; alt h { - 0.0 to 1.0/6.0 { return m1 + (m2 - m1)*h*6.0; } - 1.0/6.0 to 1.0/2.0 { return m2; } - 1.0/2.0 to 2.0/3.0 { return m1 + (m2 - m1)*(4.0 - 6.0*h); } - 2.0/3.0 to 1.0 { return m1; } - _ { fail ~"unexpected hue value"; } + 0.0 to 1.0/6.0 => m1 + (m2 - m1)*h*6.0, + 1.0/6.0 to 1.0/2.0 => m2, + 1.0/2.0 to 2.0/3.0 => m1 + (m2 - m1)*(4.0 - 6.0*h), + 2.0/3.0 to 1.0 => return m1, + _ => fail ~"unexpected hue value" } } @@ -74,24 +74,24 @@ mod parsing { #[doc="Match an exact color keyword."] fn parse_by_name(color : ~str) -> option { let col = alt color.to_lower() { - ~"black" { black() } - ~"silver" { silver() } - ~"gray" { gray() } - ~"grey" { gray() } - ~"white" { white() } - ~"maroon" { maroon() } - ~"red" { red() } - ~"purple" { purple() } - ~"fuchsia" { fuchsia() } - ~"green" { green() } - ~"lime" { lime() } - ~"olive" { olive() } - ~"yellow" { yellow() } - ~"navy" { navy() } - ~"blue" { blue() } - ~"teal" { teal() } - ~"aqua" { aqua() } - _ { return fail_unrecognized(color) } + ~"black" => black(), + ~"silver" => silver(), + ~"gray" => gray(), + ~"grey" => gray(), + ~"white" => white(), + ~"maroon" => maroon(), + ~"red" => red(), + ~"purple" => purple(), + ~"fuchsia" => fuchsia(), + ~"green" => green(), + ~"lime" => lime(), + ~"olive" => olive(), + ~"yellow" => yellow(), + ~"navy" => navy(), + ~"blue" => blue(), + ~"teal" => teal(), + ~"aqua" => aqua(), + _ => return fail_unrecognized(color) }; return some(col); @@ -108,8 +108,8 @@ mod parsing { alt (u8::from_str(cols[0]), u8::from_str(cols[1]), u8::from_str(cols[2])) { - (some(r), some(g), some(b)) { some(rgb(r, g, b)) } - _ { fail_unrecognized(color) } + (some(r), some(g), some(b)) => { some(rgb(r, g, b)) } + _ => { fail_unrecognized(color) } } } @@ -124,8 +124,8 @@ mod parsing { alt (u8::from_str(cols[0]), u8::from_str(cols[1]), u8::from_str(cols[2]), float::from_str(cols[3])) { - (some(r), some(g), some(b), some(a)) { some(rgba(r, g, b, a)) } - _ { fail_unrecognized(color) } + (some(r), some(g), some(b), some(a)) => { some(rgba(r, g, b, a)) } + _ => { fail_unrecognized(color) } } } @@ -140,8 +140,8 @@ mod parsing { alt (float::from_str(vals[0]), float::from_str(vals[1]), float::from_str(vals[2])) { - (some(h), some(s), some(l)) { some(hsl(h, s, l)) } - _ { fail_unrecognized(color) } + (some(h), some(s), some(l)) => { some(hsl(h, s, l)) } + _ => { fail_unrecognized(color) } } } @@ -155,8 +155,8 @@ mod parsing { alt (float::from_str(vals[0]), float::from_str(vals[1]), float::from_str(vals[2]), float::from_str(vals[3])) { - (some(h), some(s), some(l), some(a)) { some(hsla(h, s, l, a)) } - _ { fail_unrecognized(color) } + (some(h), some(s), some(l), some(a)) => { some(hsla(h, s, l, a)) } + _ => { fail_unrecognized(color) } } } @@ -165,11 +165,11 @@ mod parsing { // TODO: extend this fn parse_color(color : ~str) -> option { alt color { - c if c.starts_with(~"rgb(") { parse_rgb(c) } - c if c.starts_with(~"rgba(") { parse_rgba(c) } - c if c.starts_with(~"hsl(") { parse_hsl(c) } - c if c.starts_with(~"hsla(") { parse_hsla(c) } - c { parse_by_name(c) } + c if c.starts_with(~"rgb(") => parse_rgb(c), + c if c.starts_with(~"rgba(") => parse_rgba(c), + c if c.starts_with(~"hsl(") => parse_hsl(c), + c if c.starts_with(~"hsla(") => parse_hsla(c), + c => parse_by_name(c) } } } diff --git a/servo/src/servo/util/tree.rs b/servo/src/servo/util/tree.rs index 49d3f32b7f31..c970c61f6eeb 100644 --- a/servo/src/servo/util/tree.rs +++ b/servo/src/servo/util/tree.rs @@ -22,8 +22,8 @@ fn each_child>(ops: O, node: T, f: fn(T) -> bool) { let mut p = ops.with_tree_fields(node, |f| f.first_child); loop { alt copy p { - none { return; } - some(c) { + none => { return; } + some(c) => { if !f(c) { return; } p = ops.with_tree_fields(c, |f| f.next_sibling); } @@ -43,8 +43,8 @@ fn add_child>(ops: O, parent: T, child: T) { ops.with_tree_fields(child, |child_tf| { alt child_tf.parent { - some(_) { fail ~"Already has a parent"; } - none { child_tf.parent = some(parent); } + some(_) => { fail ~"Already has a parent"; } + none => { child_tf.parent = some(parent); } } assert child_tf.prev_sibling == none; @@ -52,10 +52,10 @@ fn add_child>(ops: O, parent: T, child: T) { ops.with_tree_fields(parent, |parent_tf| { alt copy parent_tf.last_child { - none { + none => { parent_tf.first_child = some(child); } - some(lc) { + some(lc) => { let lc = lc; // satisfy alias checker ops.with_tree_fields(lc, |lc_tf| { assert lc_tf.next_sibling == none; diff --git a/servo/src/servo/util/url.rs b/servo/src/servo/util/url.rs index e23e823e45ea..d582223195f6 100644 --- a/servo/src/servo/util/url.rs +++ b/servo/src/servo/util/url.rs @@ -12,6 +12,7 @@ Create a URL object from a string. Does various helpful browsery things like is based off the current url */ +#[allow(non_implicitly_copyable_typarams)] fn make_url(str_url: ~str, current_url: option) -> url { let mut schm = get_scheme(str_url); let str_url = if result::is_err(schm) { @@ -27,13 +28,13 @@ fn make_url(str_url: ~str, current_url: option) -> url { } else { let path = path::split(current_url.path); let path = path.init(); - let path = path::connect_many(path + ~[str_url]); + let path = path::connect_many(path + ~[copy str_url]); current_url.scheme + "://" + path::connect(current_url.host, path) } } } else { - str_url + copy str_url }; // FIXME: Need to handle errors