Skip to content

Commit 21aeb0f

Browse files
committed
Fix pretty-printing for bounded closures. Close #7333.
1 parent d0f56db commit 21aeb0f

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,14 @@ pub fn print_type(s: @ps, ty: @ast::Ty) {
410410
let generics = ast::Generics {lifetimes: copy f.lifetimes,
411411
ty_params: opt_vec::Empty};
412412
print_ty_fn(s, Some(f.abis), None, None,
413-
f.purity, ast::Many, &f.decl, None,
413+
f.purity, ast::Many, &f.decl, None, &None,
414414
Some(&generics), None);
415415
}
416416
ast::ty_closure(f) => {
417417
let generics = ast::Generics {lifetimes: copy f.lifetimes,
418418
ty_params: opt_vec::Empty};
419419
print_ty_fn(s, None, Some(f.sigil), f.region,
420-
f.purity, f.onceness, &f.decl, None,
420+
f.purity, f.onceness, &f.decl, None, &f.bounds,
421421
Some(&generics), None);
422422
}
423423
ast::ty_path(path, bounds, _) => print_bounded_path(s, path, bounds),
@@ -806,7 +806,7 @@ pub fn print_ty_method(s: @ps, m: &ast::ty_method) {
806806
maybe_print_comment(s, m.span.lo);
807807
print_outer_attributes(s, m.attrs);
808808
print_ty_fn(s, None, None, None, m.purity, ast::Many,
809-
&m.decl, Some(m.ident), Some(&m.generics),
809+
&m.decl, Some(m.ident), &None, Some(&m.generics),
810810
Some(/*bad*/ copy m.explicit_self.node));
811811
word(s.s, ";");
812812
}
@@ -1497,7 +1497,7 @@ fn print_path_(s: @ps, path: @ast::Path, colons_before_params: bool,
14971497
print_ident(s, *id);
14981498
}
14991499
do opt_bounds.map |bounds| {
1500-
print_bounds(s, bounds);
1500+
print_bounds(s, bounds, true);
15011501
};
15021502
if path.rp.is_some() || !path.types.is_empty() {
15031503
if colons_before_params { word(s.s, "::"); }
@@ -1737,7 +1737,8 @@ pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) {
17371737
maybe_print_comment(s, decl.output.span.lo);
17381738
}
17391739

1740-
pub fn print_bounds(s: @ps, bounds: &OptVec<ast::TyParamBound>) {
1740+
pub fn print_bounds(s: @ps, bounds: &OptVec<ast::TyParamBound>,
1741+
print_colon_anyway: bool) {
17411742
if !bounds.is_empty() {
17421743
word(s.s, ":");
17431744
let mut first = true;
@@ -1754,6 +1755,8 @@ pub fn print_bounds(s: @ps, bounds: &OptVec<ast::TyParamBound>) {
17541755
RegionTyParamBound => word(s.s, "'static"),
17551756
}
17561757
}
1758+
} else if print_colon_anyway {
1759+
word(s.s, ":");
17571760
}
17581761
}
17591762

@@ -1774,7 +1777,7 @@ pub fn print_generics(s: @ps, generics: &ast::Generics) {
17741777
let idx = idx - generics.lifetimes.len();
17751778
let param = generics.ty_params.get(idx);
17761779
print_ident(s, param.ident);
1777-
print_bounds(s, param.bounds);
1780+
print_bounds(s, param.bounds, false);
17781781
}
17791782
}
17801783

@@ -1917,6 +1920,7 @@ pub fn print_ty_fn(s: @ps,
19171920
onceness: ast::Onceness,
19181921
decl: &ast::fn_decl,
19191922
id: Option<ast::ident>,
1923+
opt_bounds: &Option<OptVec<ast::TyParamBound>>,
19201924
generics: Option<&ast::Generics>,
19211925
opt_explicit_self: Option<ast::explicit_self_>) {
19221926
ibox(s, indent_unit);
@@ -1930,6 +1934,7 @@ pub fn print_ty_fn(s: @ps,
19301934
print_onceness(s, onceness);
19311935
word(s.s, "fn");
19321936
match id { Some(id) => { word(s.s, " "); print_ident(s, id); } _ => () }
1937+
do opt_bounds.map |bounds| { print_bounds(s, bounds, true); };
19331938
match generics { Some(g) => print_generics(s, g), _ => () }
19341939
zerobreak(s.s);
19351940

src/test/run-pass/closure-bounds-copyable-squiggle-closure.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-pretty
12-
1311
// Tests correct copying of heap closures' environments.
1412

1513
fn foo(x: ~fn:Copy()) -> (~fn:(), ~fn:()) {

src/test/run-pass/closure-bounds-squiggle-closure-as-copyable-typaram.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-pretty
12-
1311
// Tests correct copying of heap closures' environments.
1412

1513
fn bar<T: Copy>(x: T) -> (T, T) {

0 commit comments

Comments
 (0)