Skip to content

Commit 1972c50

Browse files
committed
Auto merge of #31160 - nxnfufunezn:ppwild-31073, r=eddyb
Fixes #31073 r? @eddyb
2 parents acf4aee + 014fc02 commit 1972c50

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

src/librustc_front/print/pprust.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub fn variant_to_string(var: &hir::Variant) -> String {
319319
}
320320

321321
pub fn arg_to_string(arg: &hir::Arg) -> String {
322-
to_string(|s| s.print_arg(arg))
322+
to_string(|s| s.print_arg(arg, false))
323323
}
324324

325325
pub fn visibility_qualified(vis: hir::Visibility, s: &str) -> String {
@@ -1935,7 +1935,8 @@ impl<'a> State<'a> {
19351935

19361936
pub fn print_fn_args(&mut self,
19371937
decl: &hir::FnDecl,
1938-
opt_explicit_self: Option<&hir::ExplicitSelf_>)
1938+
opt_explicit_self: Option<&hir::ExplicitSelf_>,
1939+
is_closure: bool)
19391940
-> io::Result<()> {
19401941
// It is unfortunate to duplicate the commasep logic, but we want the
19411942
// self type and the args all in the same box.
@@ -1965,7 +1966,7 @@ impl<'a> State<'a> {
19651966
} else {
19661967
try!(self.word_space(","));
19671968
}
1968-
try!(self.print_arg(arg));
1969+
try!(self.print_arg(arg, is_closure));
19691970
}
19701971

19711972
self.end()
@@ -1976,7 +1977,7 @@ impl<'a> State<'a> {
19761977
opt_explicit_self: Option<&hir::ExplicitSelf_>)
19771978
-> io::Result<()> {
19781979
try!(self.popen());
1979-
try!(self.print_fn_args(decl, opt_explicit_self));
1980+
try!(self.print_fn_args(decl, opt_explicit_self, false));
19801981
if decl.variadic {
19811982
try!(word(&mut self.s, ", ..."));
19821983
}
@@ -1987,7 +1988,7 @@ impl<'a> State<'a> {
19871988

19881989
pub fn print_fn_block_args(&mut self, decl: &hir::FnDecl) -> io::Result<()> {
19891990
try!(word(&mut self.s, "|"));
1990-
try!(self.print_fn_args(decl, None));
1991+
try!(self.print_fn_args(decl, None, true));
19911992
try!(word(&mut self.s, "|"));
19921993

19931994
if let hir::DefaultReturn(..) = decl.output {
@@ -2204,10 +2205,10 @@ impl<'a> State<'a> {
22042205
self.print_type(&*mt.ty)
22052206
}
22062207

2207-
pub fn print_arg(&mut self, input: &hir::Arg) -> io::Result<()> {
2208+
pub fn print_arg(&mut self, input: &hir::Arg, is_closure: bool) -> io::Result<()> {
22082209
try!(self.ibox(indent_unit));
22092210
match input.ty.node {
2210-
hir::TyInfer => try!(self.print_pat(&*input.pat)),
2211+
hir::TyInfer if is_closure => try!(self.print_pat(&*input.pat)),
22112212
_ => {
22122213
match input.pat.node {
22132214
hir::PatIdent(_, ref path1, _) if

src/libsyntax/print/pprust.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pub fn variant_to_string(var: &ast::Variant) -> String {
425425
}
426426

427427
pub fn arg_to_string(arg: &ast::Arg) -> String {
428-
to_string(|s| s.print_arg(arg))
428+
to_string(|s| s.print_arg(arg, false))
429429
}
430430

431431
pub fn mac_to_string(arg: &ast::Mac) -> String {
@@ -2672,8 +2672,8 @@ impl<'a> State<'a> {
26722672
}
26732673

26742674
pub fn print_fn_args(&mut self, decl: &ast::FnDecl,
2675-
opt_explicit_self: Option<&ast::ExplicitSelf_>)
2676-
-> io::Result<()> {
2675+
opt_explicit_self: Option<&ast::ExplicitSelf_>,
2676+
is_closure: bool) -> io::Result<()> {
26772677
// It is unfortunate to duplicate the commasep logic, but we want the
26782678
// self type and the args all in the same box.
26792679
try!(self.rbox(0, Inconsistent));
@@ -2698,7 +2698,7 @@ impl<'a> State<'a> {
26982698

26992699
for arg in args {
27002700
if first { first = false; } else { try!(self.word_space(",")); }
2701-
try!(self.print_arg(arg));
2701+
try!(self.print_arg(arg, is_closure));
27022702
}
27032703

27042704
self.end()
@@ -2708,7 +2708,7 @@ impl<'a> State<'a> {
27082708
opt_explicit_self: Option<&ast::ExplicitSelf_>)
27092709
-> io::Result<()> {
27102710
try!(self.popen());
2711-
try!(self.print_fn_args(decl, opt_explicit_self));
2711+
try!(self.print_fn_args(decl, opt_explicit_self, false));
27122712
if decl.variadic {
27132713
try!(word(&mut self.s, ", ..."));
27142714
}
@@ -2722,7 +2722,7 @@ impl<'a> State<'a> {
27222722
decl: &ast::FnDecl)
27232723
-> io::Result<()> {
27242724
try!(word(&mut self.s, "|"));
2725-
try!(self.print_fn_args(decl, None));
2725+
try!(self.print_fn_args(decl, None, true));
27262726
try!(word(&mut self.s, "|"));
27272727

27282728
if let ast::DefaultReturn(..) = decl.output {
@@ -2967,10 +2967,10 @@ impl<'a> State<'a> {
29672967
self.print_type(&*mt.ty)
29682968
}
29692969

2970-
pub fn print_arg(&mut self, input: &ast::Arg) -> io::Result<()> {
2970+
pub fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) -> io::Result<()> {
29712971
try!(self.ibox(INDENT_UNIT));
29722972
match input.ty.node {
2973-
ast::TyInfer => try!(self.print_pat(&*input.pat)),
2973+
ast::TyInfer if is_closure => try!(self.print_pat(&*input.pat)),
29742974
_ => {
29752975
match input.pat.node {
29762976
ast::PatIdent(_, ref path1, _) if

src/test/pretty/issue-31073.pp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// pp-exact:issue-31073.pp
12+
13+
fn main() {
14+
fn f1(x: i32, y: i32) -> i32 { y }
15+
let f: fn(_, i32) -> i32 = f1;
16+
f(1, 2);
17+
}

src/test/pretty/issue-31073.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// pp-exact:issue-31073.pp
12+
13+
fn main() {
14+
fn f1(x: i32, y: i32) -> i32 { y }
15+
let f: fn(_, i32) -> i32 = f1;
16+
f(1, 2);
17+
}

0 commit comments

Comments
 (0)