Skip to content

Fix pretty_printer to print omitted type _ marker #31160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/librustc_front/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub fn variant_to_string(var: &hir::Variant) -> String {
}

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

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

pub fn print_fn_args(&mut self,
decl: &hir::FnDecl,
opt_explicit_self: Option<&hir::ExplicitSelf_>)
opt_explicit_self: Option<&hir::ExplicitSelf_>,
is_closure: bool)
-> io::Result<()> {
// It is unfortunate to duplicate the commasep logic, but we want the
// self type and the args all in the same box.
Expand Down Expand Up @@ -1965,7 +1966,7 @@ impl<'a> State<'a> {
} else {
try!(self.word_space(","));
}
try!(self.print_arg(arg));
try!(self.print_arg(arg, is_closure));
}

self.end()
Expand All @@ -1976,7 +1977,7 @@ impl<'a> State<'a> {
opt_explicit_self: Option<&hir::ExplicitSelf_>)
-> io::Result<()> {
try!(self.popen());
try!(self.print_fn_args(decl, opt_explicit_self));
try!(self.print_fn_args(decl, opt_explicit_self, false));
if decl.variadic {
try!(word(&mut self.s, ", ..."));
}
Expand All @@ -1987,7 +1988,7 @@ impl<'a> State<'a> {

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

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

pub fn print_arg(&mut self, input: &hir::Arg) -> io::Result<()> {
pub fn print_arg(&mut self, input: &hir::Arg, is_closure: bool) -> io::Result<()> {
try!(self.ibox(indent_unit));
match input.ty.node {
hir::TyInfer => try!(self.print_pat(&*input.pat)),
hir::TyInfer if is_closure => try!(self.print_pat(&*input.pat)),
_ => {
match input.pat.node {
hir::PatIdent(_, ref path1, _) if
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ pub fn variant_to_string(var: &ast::Variant) -> String {
}

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

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

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

for arg in args {
if first { first = false; } else { try!(self.word_space(",")); }
try!(self.print_arg(arg));
try!(self.print_arg(arg, is_closure));
}

self.end()
Expand All @@ -2708,7 +2708,7 @@ impl<'a> State<'a> {
opt_explicit_self: Option<&ast::ExplicitSelf_>)
-> io::Result<()> {
try!(self.popen());
try!(self.print_fn_args(decl, opt_explicit_self));
try!(self.print_fn_args(decl, opt_explicit_self, false));
if decl.variadic {
try!(word(&mut self.s, ", ..."));
}
Expand All @@ -2722,7 +2722,7 @@ impl<'a> State<'a> {
decl: &ast::FnDecl)
-> io::Result<()> {
try!(word(&mut self.s, "|"));
try!(self.print_fn_args(decl, None));
try!(self.print_fn_args(decl, None, true));
try!(word(&mut self.s, "|"));

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

pub fn print_arg(&mut self, input: &ast::Arg) -> io::Result<()> {
pub fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) -> io::Result<()> {
try!(self.ibox(INDENT_UNIT));
match input.ty.node {
ast::TyInfer => try!(self.print_pat(&*input.pat)),
ast::TyInfer if is_closure => try!(self.print_pat(&*input.pat)),
_ => {
match input.pat.node {
ast::PatIdent(_, ref path1, _) if
Expand Down
17 changes: 17 additions & 0 deletions src/test/pretty/issue-31073.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pp-exact:issue-31073.pp

fn main() {
fn f1(x: i32, y: i32) -> i32 { y }
let f: fn(_, i32) -> i32 = f1;
f(1, 2);
}
17 changes: 17 additions & 0 deletions src/test/pretty/issue-31073.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pp-exact:issue-31073.pp

fn main() {
fn f1(x: i32, y: i32) -> i32 { y }
let f: fn(_, i32) -> i32 = f1;
f(1, 2);
}