Skip to content

Commit fa45c79

Browse files
U-NOV2010\eugalsEvgeny Sologubov
authored andcommitted
---
yaml --- r: 83245 b: refs/heads/try c: 2927ab1 h: refs/heads/master i: 83243: 74297a8 v: v3
1 parent 8c5e665 commit fa45c79

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: da29a8e6be0af399ef8b350fa4b6d124d2610bf7
5+
refs/heads/try: 2927ab13df9436ae2042866885ea0b9d29cdcedc
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/trans/expr.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,37 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
313313
let target_obj_ty = expr_ty_adjusted(bcx, expr);
314314
debug!("auto_borrow_obj(target=%s)",
315315
target_obj_ty.repr(tcx));
316+
317+
// Extract source store information
318+
let (source_store, source_mutbl) = match ty::get(source_datum.ty).sty {
319+
ty::ty_trait(_, _, s, m, _) => (s, m),
320+
_ => {
321+
bcx.sess().span_bug(
322+
expr.span,
323+
fmt!("auto_borrow_trait_obj expected a trait, found %s",
324+
source_datum.ty.repr(bcx.tcx())));
325+
}
326+
};
327+
328+
// check if any borrowing is really needed or we could reuse the source_datum instead
329+
match ty::get(target_obj_ty).sty {
330+
ty::ty_trait(_, _, ty::RegionTraitStore(target_scope), target_mutbl, _) => {
331+
if target_mutbl == ast::MutImmutable && target_mutbl == source_mutbl {
332+
match source_store {
333+
ty::RegionTraitStore(source_scope) => {
334+
if tcx.region_maps.is_subregion_of(target_scope, source_scope) {
335+
return DatumBlock { bcx: bcx, datum: source_datum };
336+
}
337+
},
338+
_ => {}
339+
340+
};
341+
}
342+
},
343+
_ => {}
344+
}
345+
346+
316347
let scratch = scratch_datum(bcx, target_obj_ty,
317348
"__auto_borrow_obj", false);
318349

@@ -331,15 +362,6 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
331362
// ~T, or &T, depending on source_obj_ty.
332363
let source_data_ptr = GEPi(bcx, source_llval, [0u, abi::trt_field_box]);
333364
let source_data = Load(bcx, source_data_ptr); // always a ptr
334-
let (source_store, source_mutbl) = match ty::get(source_datum.ty).sty {
335-
ty::ty_trait(_, _, s, m, _) => (s, m),
336-
_ => {
337-
bcx.sess().span_bug(
338-
expr.span,
339-
fmt!("auto_borrow_trait_obj expected a trait, found %s",
340-
source_datum.ty.repr(bcx.tcx())));
341-
}
342-
};
343365
let target_data = match source_store {
344366
ty::BoxTraitStore(*) => {
345367
// For deref of @T or @mut T, create a dummy datum and

branches/try/src/libsyntax/ext/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl Context {
7676
self.ecx.span_err(sp, "expected token: `,`");
7777
return (extra, None);
7878
}
79-
if *p.token == token::EOF { break } // accept trailing commas
8079
if named || (token::is_ident(p.token) &&
8180
p.look_ahead(1, |t| *t == token::EQ)) {
8281
named = true;

branches/try/src/test/run-pass/ifmt.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ pub fn main() {
243243
}
244244

245245
test_format_args();
246-
247-
// test that trailing commas are acceptable
248-
format!("{}", "test",);
249-
format!("{foo}", foo="test",);
250246
}
251247

252248
// Basic test to make sure that we can invoke the `write!` macro with an

0 commit comments

Comments
 (0)