Skip to content

Commit 7234635

Browse files
committed
Remove old borrow check workarounds and appease the new borrow checker.
1 parent 4d0c202 commit 7234635

File tree

5 files changed

+57
-70
lines changed

5 files changed

+57
-70
lines changed

src/servo/content/content_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub impl Content {
186186
}
187187

188188
fn handle_msg(&mut self) -> bool {
189-
match select2i(&self.control_port, &self.event_port) {
189+
match select2i(&mut self.control_port, &mut self.event_port) {
190190
either::Left(*) => {
191191
let msg = self.control_port.recv();
192192
self.handle_control_msg(msg)

src/servo/layout/box.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,12 @@ pub impl RenderBox {
168168
match *self {
169169
GenericRenderBoxClass(generic_box) => callback(generic_box),
170170
ImageRenderBoxClass(image_box) => {
171-
let image_box = &*image_box; // FIXME: Borrow check workaround.
172171
callback(&image_box.base)
173172
}
174173
TextRenderBoxClass(text_box) => {
175-
let text_box = &*text_box; // FIXME: Borrow check workaround.
176174
callback(&text_box.base)
177175
}
178176
UnscannedTextRenderBoxClass(unscanned_text_box) => {
179-
let unscanned_text_box = &*unscanned_text_box; // FIXME: Borrow check workaround.
180177
callback(&unscanned_text_box.base)
181178
}
182179
}
@@ -188,16 +185,12 @@ pub impl RenderBox {
188185
match *self {
189186
GenericRenderBoxClass(generic_box) => callback(generic_box),
190187
ImageRenderBoxClass(image_box) => {
191-
let image_box = &mut *image_box; // FIXME: Borrow check workaround.
192188
callback(&mut image_box.base)
193189
}
194190
TextRenderBoxClass(text_box) => {
195-
let text_box = &mut *text_box; // FIXME: Borrow check workaround.
196191
callback(&mut text_box.base)
197192
}
198193
UnscannedTextRenderBoxClass(unscanned_text_box) => {
199-
// FIXME: Borrow check workaround.
200-
let unscanned_text_box = &mut *unscanned_text_box;
201194
callback(&mut unscanned_text_box.base)
202195
}
203196
}
@@ -238,7 +231,6 @@ pub impl RenderBox {
238231
fn is_whitespace_only(&self) -> bool {
239232
match *self {
240233
UnscannedTextRenderBoxClass(unscanned_text_box) => {
241-
let mut unscanned_text_box = &mut *unscanned_text_box; // FIXME: Borrow check.
242234
unscanned_text_box.text.is_whitespace()
243235
}
244236
_ => false
@@ -269,8 +261,6 @@ pub impl RenderBox {
269261
}
270262
271263
TextRenderBoxClass(text_box) => {
272-
let text_box = &mut *text_box; // FIXME: Borrow check.
273-
274264
let mut pieces_processed_count: uint = 0;
275265
let mut remaining_width: Au = max_width;
276266
let mut left_range = Range::new(text_box.text_data.range.begin(), 0);
@@ -379,7 +369,6 @@ pub impl RenderBox {
379369
}
380370
381371
TextRenderBoxClass(text_box) => {
382-
let mut text_box = &mut *text_box; // FIXME: Borrow check.
383372
text_box.text_data.run.min_width_for_range(&text_box.text_data.range)
384373
}
385374
@@ -401,8 +390,6 @@ pub impl RenderBox {
401390
}
402391
403392
TextRenderBoxClass(text_box) => {
404-
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
405-
406393
// A text box cannot span lines, so assume that this is an unsplit text box.
407394
//
408395
// TODO: If text boxes have been split to wrap lines, then they could report a
@@ -567,8 +554,6 @@ pub impl RenderBox {
567554
match *self {
568555
UnscannedTextRenderBoxClass(*) => fail!(~"Shouldn't see unscanned boxes here."),
569556
TextRenderBoxClass(text_box) => {
570-
let text_box = &mut *text_box; // FIXME: Borrow check bug.
571-
572557
let nearest_ancestor_element = self.nearest_ancestor_element();
573558
let color = nearest_ancestor_element.style().color().to_gfx_color();
574559
@@ -783,13 +768,11 @@ impl DebugMethods for RenderBox {
783768
GenericRenderBoxClass(*) => ~"GenericRenderBox",
784769
ImageRenderBoxClass(*) => ~"ImageRenderBox",
785770
TextRenderBoxClass(text_box) => {
786-
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
787771
fmt!("TextRenderBox(text=%s)", str::substr(text_box.text_data.run.text,
788772
text_box.text_data.range.begin(),
789773
text_box.text_data.range.length()))
790774
}
791775
UnscannedTextRenderBoxClass(text_box) => {
792-
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
793776
fmt!("UnscannedTextRenderBox(%s)", text_box.text)
794777
}
795778
};

src/servo/layout/box_builder.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ impl BoxGenerator {
125125
// depending on flow, make a box for this node.
126126
match self.flow {
127127
InlineFlow(inline) => {
128-
let mut inline = &mut *inline;
129128
let node_range_start = inline.boxes.len();
130129
self.range_stack.push(node_range_start);
131130

@@ -387,24 +386,38 @@ pub impl LayoutTreeBuilder {
387386
// check first/last child for whitespace-ness
388387
for first_child.each |first_flow| {
389388
if first_flow.starts_inline_flow() {
390-
let boxes = &mut first_flow.inline().boxes;
389+
// FIXME: workaround for rust#6393
390+
let mut do_remove = false;
391+
{
392+
let boxes = &first_flow.inline().boxes;
391393
if boxes.len() == 1 && boxes[0].is_whitespace_only() {
392394
debug!("LayoutTreeBuilder: pruning whitespace-only first child flow \
393395
f%d from parent f%d",
394396
first_flow.id(),
395397
parent_flow.id());
398+
do_remove = true;
399+
}
400+
}
401+
if (do_remove) {
396402
parent_flow.remove_child(*first_flow);
397403
}
398404
}
399405
}
400406
for last_child.each |last_flow| {
401407
if last_flow.starts_inline_flow() {
402-
let boxes = &mut last_flow.inline().boxes;
408+
// FIXME: workaround for rust#6393
409+
let mut do_remove = false;
410+
{
411+
let boxes = &last_flow.inline().boxes;
403412
if boxes.len() == 1 && boxes.last().is_whitespace_only() {
404413
debug!("LayoutTreeBuilder: pruning whitespace-only last child flow \
405414
f%d from parent f%d",
406415
last_flow.id(),
407416
parent_flow.id());
417+
do_remove = true;
418+
}
419+
}
420+
if (do_remove) {
408421
parent_flow.remove_child(*last_flow);
409422
}
410423
}

src/servo/layout/flow.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,14 @@ impl TreeNodeRef<FlowData> for FlowContext {
7676
match *self {
7777
AbsoluteFlow(info) => callback(info),
7878
BlockFlow(info) => {
79-
let info = &*info; // FIXME: Borrow check workaround.
8079
callback(&info.common)
8180
}
8281
FloatFlow(info) => callback(info),
8382
InlineBlockFlow(info) => callback(info),
8483
InlineFlow(info) => {
85-
let info = &*info; // FIXME: Borrow check workaround.
8684
callback(&info.common)
8785
}
8886
RootFlow(info) => {
89-
let info = &*info; // FIXME: Borrow check workaround.
9087
callback(&info.common)
9188
}
9289
TableFlow(info) => callback(info),
@@ -96,17 +93,14 @@ impl TreeNodeRef<FlowData> for FlowContext {
9693
match *self {
9794
AbsoluteFlow(info) => callback(info),
9895
BlockFlow(info) => {
99-
let info = &mut *info; // FIXME: Borrow check workaround.
10096
callback(&mut info.common)
10197
}
10298
FloatFlow(info) => callback(info),
10399
InlineBlockFlow(info) => callback(info),
104100
InlineFlow(info) => {
105-
let info = &mut *info; // FIXME: Borrow check workaround.
106101
callback(&mut info.common)
107102
}
108103
RootFlow(info) => {
109-
let info = &mut *info; // FIXME: Borrow check workaround.
110104
callback(&mut info.common)
111105
}
112106
TableFlow(info) => callback(info),
@@ -388,22 +382,19 @@ impl DebugMethods for FlowContext {
388382
fn debug_str(&self) -> ~str {
389383
let repr = match *self {
390384
InlineFlow(inline) => {
391-
let inline = &mut *inline;
392385
let mut s = inline.boxes.foldl(~"InlineFlow(children=", |s, box| {
393386
fmt!("%s b%d", *s, box.id())
394387
});
395388
s += ~")";
396389
s
397390
},
398391
BlockFlow(block) => {
399-
let block = &mut *block;
400392
match block.box {
401393
Some(box) => fmt!("BlockFlow(box=b%d)", box.id()),
402394
None => ~"BlockFlow",
403395
}
404396
},
405397
RootFlow(root) => {
406-
let root = &mut *root;
407398
match root.box {
408399
Some(box) => fmt!("RootFlow(box=b%d)", box.id()),
409400
None => ~"RootFlow",

src/servo/layout/inline.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl TextRunScanner {
173173

174174
impl TextRunScanner {
175175
fn scan_for_runs(&mut self, ctx: &mut LayoutContext, flow: FlowContext) {
176-
let inline = &mut *flow.inline();
176+
let inline = flow.inline();
177177
assert!(inline.boxes.len() > 0);
178178
debug!("TextRunScanner: scanning %u boxes for text runs...", inline.boxes.len());
179179

@@ -334,8 +334,7 @@ impl TextRunScanner {
334334
debug!("------------------");
335335
336336
debug!("--- Elem ranges: ---");
337-
let elems: &mut ElementMapping = &mut flow.inline().elems;
338-
for elems.eachi_mut |i: uint, nr: &NodeRange| {
337+
for flow.inline().elems.eachi_mut |i: uint, nr: &NodeRange| {
339338
debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); ()
340339
}
341340
debug!("--------------------");
@@ -386,43 +385,46 @@ impl LineboxScanner {
386385
pub fn scan_for_lines(&mut self, ctx: &LayoutContext) {
387386
self.reset_scanner();
388387
389-
let boxes = &mut self.flow.inline().boxes;
390-
let mut i = 0u;
391-
392-
loop {
393-
// acquire the next box to lay out from work list or box list
394-
let cur_box = if self.work_list.is_empty() {
395-
if i == boxes.len() {
396-
break
388+
{ // FIXME: manually control borrow length
389+
let inline: &InlineFlowData = self.flow.inline();
390+
let mut i = 0u;
391+
392+
loop {
393+
// acquire the next box to lay out from work list or box list
394+
let cur_box = if self.work_list.is_empty() {
395+
if i == inline.boxes.len() {
396+
break
397+
}
398+
let box = inline.boxes[i]; i += 1;
399+
debug!("LineboxScanner: Working with box from box list: b%d", box.id());
400+
box
401+
} else {
402+
let box = self.work_list.pop_front();
403+
debug!("LineboxScanner: Working with box from work list: b%d", box.id());
404+
box
405+
};
406+
407+
let box_was_appended = self.try_append_to_line(ctx, cur_box);
408+
if !box_was_appended {
409+
debug!("LineboxScanner: Box wasn't appended, because line %u was full.",
410+
self.line_spans.len());
411+
self.flush_current_line();
412+
} else {
413+
debug!("LineboxScanner: appended a box to line %u", self.line_spans.len());
397414
}
398-
let box = boxes[i]; i += 1;
399-
debug!("LineboxScanner: Working with box from box list: b%d", box.id());
400-
box
401-
} else {
402-
let box = self.work_list.pop_front();
403-
debug!("LineboxScanner: Working with box from work list: b%d", box.id());
404-
box
405-
};
406-
407-
let box_was_appended = self.try_append_to_line(ctx, cur_box);
408-
if !box_was_appended {
409-
debug!("LineboxScanner: Box wasn't appended, because line %u was full.",
415+
}
416+
417+
if self.pending_line.range.length() > 0 {
418+
debug!("LineboxScanner: Partially full linebox %u left at end of scanning.",
410419
self.line_spans.len());
411420
self.flush_current_line();
412-
} else {
413-
debug!("LineboxScanner: appended a box to line %u", self.line_spans.len());
414421
}
415422
}
416-
417-
if self.pending_line.range.length() > 0 {
418-
debug!("LineboxScanner: Partially full linebox %u left at end of scanning.",
419-
self.line_spans.len());
420-
self.flush_current_line();
423+
424+
{ // FIXME: scope the borrow
425+
let inline: &mut InlineFlowData = self.flow.inline();
426+
inline.elems.repair_for_box_changes(inline.boxes, self.new_boxes);
421427
}
422-
423-
let boxes = &mut self.flow.inline().boxes;
424-
let elems = &mut self.flow.inline().elems;
425-
elems.repair_for_box_changes(*boxes, self.new_boxes);
426428
self.swap_out_results();
427429
}
428430
@@ -431,10 +433,9 @@ impl LineboxScanner {
431433
self.line_spans.len(),
432434
self.flow.id());
433435
434-
let inline_boxes = &mut self.flow.inline().boxes;
435-
util::swap(inline_boxes, &mut self.new_boxes);
436-
let lines = &mut self.flow.inline().lines;
437-
util::swap(lines, &mut self.line_spans);
436+
let inline: &mut InlineFlowData = self.flow.inline();
437+
util::swap(&mut inline.boxes, &mut self.new_boxes);
438+
util::swap(&mut inline.lines, &mut self.line_spans);
438439
}
439440
440441
fn flush_current_line(&mut self) {
@@ -763,7 +764,6 @@ impl InlineFlowData {
763764
// TODO: We can use font metrics directly instead of re-measuring for the
764765
// bounding box.
765766
TextRenderBoxClass(text_box) => {
766-
let text_box = &mut *text_box; // FIXME: borrow check workaround
767767
let range = &text_box.text_data.range;
768768
let run = &text_box.text_data.run;
769769
let text_bounds = run.metrics_for_range(range).bounding_box;
@@ -814,7 +814,7 @@ impl InlineFlowData {
814814
self.common.position.size.height = cur_y;
815815
}
816816
817-
pub fn build_display_list_inline(&mut self,
817+
pub fn build_display_list_inline(&self,
818818
builder: &DisplayListBuilder,
819819
dirty: &Rect<Au>,
820820
offset: &Point2D<Au>,

0 commit comments

Comments
 (0)